Skip to content

Commit 9fe640d

Browse files
authored
introduce --autobackmatter (#214)
This change introduces a new flag --noautobackmatter, that controls the automatic insertion of the back matter into a spec so that spec writers don't have to include the following at the end of their specs: \beginbackmatter \# References ::: {#refs} ::: Auto backmatter is enabled by default, but it can be disabled with --noautobackmatter. The references section is only included if there is a bibliography: tag in the YAML front matter of the markdown file.
1 parent 70f16a7 commit 9fe640d

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

build.sh

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ PR_NUMBER=""
1515
PR_REPO=""
1616
DIFFBASE=""
1717
PDF_ENGINE=xelatex
18+
DO_AUTO_BACKMATTER="yes"
1819

1920
# Start up the dbus daemon (drawio will use it later)
2021
dbus-daemon --system || echo "Failed to start dbus daemon"
@@ -59,10 +60,11 @@ print_usage() {
5960
echo " --pr_number=number: mark the document as a pull-request draft if using Git versioning."
6061
echo " --pr_repo=url: provide the URL for the repository for pull-request drafts (has no effect if --PR_NUMBER is not passed)."
6162
echo " --pdf_engine=(xelatex|lualatex): use the given latex engine (default xelatex)"
63+
echo " --noautobackmatter: don't automatically insert back matter at the end of the document."
6264
}
6365

6466

65-
if ! options=$(getopt --longoptions=help,puppeteer,gitversion,gitstatus,nogitversion,table_rules,plain_quotes,versioned_filenames,pr_number:,pr_repo:,diffbase:,pdf:,diffpdf:,difftex:,diffpdflog:,latex:,pdflog:,pdf_engine:,docx:,html:,resourcedir: --options="" -- "$@"); then
67+
if ! options=$(getopt --longoptions=help,puppeteer,gitversion,gitstatus,nogitversion,table_rules,plain_quotes,versioned_filenames,pr_number:,pr_repo:,diffbase:,pdf:,diffpdf:,difftex:,diffpdflog:,latex:,pdflog:,pdf_engine:,docx:,html:,resourcedir:,noautobackmatter --options="" -- "$@"); then
6668
echo "Incorrect options provided"
6769
print_usage
6870
exit 1
@@ -152,6 +154,10 @@ while true; do
152154
PR_REPO="${2}"
153155
shift 2
154156
;;
157+
--noautobackmatter)
158+
DO_AUTO_BACKMATTER="no"
159+
shift
160+
;;
155161
--help)
156162
print_usage
157163
shift
@@ -489,6 +495,25 @@ do_md_fixups() {
489495
# While we're doing this, transform the case to all-caps.
490496
# TODO: Turn this into a Pandoc filter.
491497
sed -i.bak '0,/\\tableofcontents/s/^# \(.*\)/\\section*\{\U\1\}/g' "${input}"
498+
499+
# Insert the back matter (if it's not already there)
500+
if test "${DO_AUTO_BACKMATTER}" == "yes" && ! grep -q "<!--AUTO BACK MATTER-->" ${input}; then
501+
cat <<- 'EOF' >> ${input}
502+
503+
<!--AUTO BACK MATTER-->
504+
EOF
505+
506+
# Insert the "References" section if there's a bibliography in the front matter
507+
if grep -q "^bibliography:" ${input}; then
508+
cat <<- 'EOF' >> ${input}
509+
\beginbackmatter
510+
# References
511+
<!--https://pandoc.org/MANUAL.html#placement-of-the-bibliography-->
512+
::: {$refs}
513+
:::
514+
EOF
515+
fi
516+
fi
492517
}
493518

494519
# latexdiff is pretty great, but it has some incompatibilities with our template, so we

template/tcg.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,7 @@
773773
\addappheadtotoc
774774
}
775775

776-
% Allow TCG documents to use '\beginbackmatter' to easily mark the transition to the back matter (after the appecndices).
776+
% Allow TCG documents to use '\beginbackmatter' to easily mark the transition to the back matter (after the appendices).
777777
\newcommand{\beginbackmatter}{
778778
\newpage
779779
\let\oldsection\section

0 commit comments

Comments
 (0)