Skip to content

Commit 693cc21

Browse files
authored
build.sh: add support for TCG cross-references (Section vs. Clause) (#213)
Added --crossref=(iso|tcg) option support, which can be extended further if more variants are needed. TEST=DOCKER_IMAGE=working:latest ./docker_run --pdf=guide.pdf\ --crossref=tcg guide.tcg
1 parent 9fe640d commit 693cc21

File tree

5 files changed

+28
-13
lines changed

5 files changed

+28
-13
lines changed

Dockerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ RUN wget https://github.com/alerque/libertinus/releases/download/v7.040/Libertin
113113
FROM ${BASE} as build-latexdiff
114114

115115
RUN apt update && apt install -y \
116-
build-essential \
116+
build-essential \
117117
wget \
118118
xz-utils
119119

@@ -269,7 +269,8 @@ RUN mkdir -m 0777 /home/user
269269
ENV HOME="/home/user"
270270
ENV DBUS_SESSION_BUS_ADDRESS="unix:path=/var/run/dbus/system_bus_socket"
271271

272-
COPY ./filter/pandoc-crossref.yaml /home/user/.pandoc-crossref/config.yaml
272+
COPY ./filter/pandoc-crossref-iso.yaml /home/user/.pandoc-crossref/config.yaml
273+
COPY ./filter/pandoc-crossref-tcg.yaml /home/user/.pandoc-crossref/config-tcg.yaml
273274

274275
COPY build.sh /usr/bin/build.sh
275276

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ https://github.com/trustedcomputinggroup/pandoc/pkgs/container/pandoc from this
3333
```sh
3434
docker pull ghcr.io/trustedcomputinggroup/pandoc:latest
3535

36-
./docker_run --pdf=guide.pdf guide.md
36+
./docker_run --pdf=guide.pdf guide.tcg
3737
```
3838

3939
## How to Build Locally
@@ -55,7 +55,7 @@ docker buildx install
5555
To build the container:
5656

5757
```sh
58-
docker build --tag WORKING .
58+
docker build --tag working .
5959

60-
DOCKER_IMAGE=working:latest ./docker_run --pdf=guide.pdf guide.md
60+
DOCKER_IMAGE=working:latest ./docker_run --pdf=guide.pdf guide.tcg
6161
```

build.sh

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ PR_NUMBER=""
1515
PR_REPO=""
1616
DIFFBASE=""
1717
PDF_ENGINE=xelatex
18+
CROSSREF_TYPE="iso"
1819
DO_AUTO_BACKMATTER="yes"
1920

21+
2022
# Start up the dbus daemon (drawio will use it later)
2123
dbus-daemon --system || echo "Failed to start dbus daemon"
2224

@@ -40,6 +42,7 @@ print_usage() {
4042
echo
4143
echo "Output Control (note that output file names are always relative to the current directory)"
4244
echo " --docx=output: enable output of docx and specify the output file name."
45+
echo " --crossref=(iso|tcg): set cross-reference style."
4346
echo " --pdf=output: enable output of pdf and specify the output file name."
4447
echo " --latex=output: enable output of latex and specify the output file name."
4548
echo " --html=output: enable output of html and specify the output file name."
@@ -64,7 +67,7 @@ print_usage() {
6467
}
6568

6669

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
70+
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:,crossref:,html:,resourcedir:,noautobackmatter --options="" -- "$@"); then
6871
echo "Incorrect options provided"
6972
print_usage
7073
exit 1
@@ -106,6 +109,10 @@ while true; do
106109
DOCX_OUTPUT="${2}"
107110
shift 2
108111
;;
112+
--crossref)
113+
CROSSREF_TYPE="${2}"
114+
shift 2
115+
;;
109116
--latex)
110117
LATEX_OUTPUT="${2}"
111118
shift 2
@@ -179,6 +186,7 @@ readonly PR_NUMBER
179186
readonly PR_REPO
180187
readonly DIFFBASE
181188
readonly PDF_ENGINE
189+
readonly CROSSREF_TYPE
182190

183191
shift "$(( OPTIND - 1 ))"
184192

@@ -559,7 +567,7 @@ do_diff_tex_fixups() {
559567
# The \multicolumn needs to be the first thing in the cell.
560568
# Swap the order of any \DIF stuff and \multicolumn invocation inside a cell.
561569
sed -i.bak 's/\(\\DIF[^&]*\)\(\\multicolumn{[^{}]*}\({[^{}]*}\|{[^{}]*{[^{}]*}}\)\)/\2\1/g' "${input}"
562-
570+
563571
# latexdiff inserts its markers before \hline sometimes.
564572
# After the transformations above, \hline needs to be the first thing in a line of text.
565573
sed -i.bak 's/\(\s*\)\(.*\)\(\\hline \|\\hlineifmdframed \)\(.*\)/\1\3\2\4/g' "${input}"
@@ -648,7 +656,8 @@ analyze_latex_logs() {
648656
do_latex() {
649657
local input=$1
650658
local output=$2
651-
local extra_pandoc_options=$3
659+
local crossref=$3
660+
local extra_pandoc_options=$4
652661
mkdir -p "$(dirname ${output})"
653662

654663
# TODO: https://github.com/TrustedComputingGroup/pandoc/issues/164
@@ -684,7 +693,7 @@ do_latex() {
684693
--metadata=link-citations
685694
--metadata=link-bibliography
686695
--metadata=titlepage-background:/resources/img/cover.png
687-
--metadata=crossrefYaml:/resources/filters/pandoc-crossref.yaml
696+
--metadata=crossrefYaml:/resources/filters/pandoc-crossref-${crossref}.yaml
688697
--metadata=logo:/resources/img/tcg.png
689698
--metadata=titlepage-rule-height:0
690699
--metadata=colorlinks:true
@@ -798,6 +807,7 @@ do_docx() {
798807
do_html() {
799808
local input=$1
800809
local output=$2
810+
local crossref=$3
801811
mkdir -p "$(dirname ${output})"
802812
echo "Generating HTML Output"
803813
local cmd=(pandoc
@@ -822,7 +832,7 @@ do_html() {
822832
--variable=numbersections
823833
--metadata=titlepage:true
824834
--metadata=titlepage-background:/resources/img/cover.png
825-
--metadata=crossrefYaml:/resources/filters/pandoc-crossref.yaml
835+
--metadata=crossrefYaml:/resources/filters/pandoc-crossref-${crossref}.yaml
826836
--metadata=logo:/resources/img/tcg.png
827837
--metadata=titlepage-rule-height:0
828838
--metadata=colorlinks:true
@@ -846,7 +856,7 @@ do_html() {
846856
readonly TEMP_TEX_FILE="${BUILD_DIR}/${INPUT_FILE}.tex"
847857
if [ -n "${PDF_OUTPUT}" -o -n "${LATEX_OUTPUT}" -o -n "${DIFFPDF_OUTPUT}" -o -n "${DIFFTEX_OUTPUT}" ]; then
848858
do_md_fixups "${BUILD_DIR}/${INPUT_FILE}"
849-
do_latex "${BUILD_DIR}/${INPUT_FILE}" "${TEMP_TEX_FILE}" "${EXTRA_PANDOC_OPTIONS}"
859+
do_latex "${BUILD_DIR}/${INPUT_FILE}" "${TEMP_TEX_FILE}" "${CROSSREF_TYPE}" "${EXTRA_PANDOC_OPTIONS}"
850860
fi
851861
if [ -n "${LATEX_OUTPUT}" ]; then
852862
cp "${TEMP_TEX_FILE}" "${SOURCE_DIR}/${LATEX_OUTPUT}"
@@ -862,7 +872,7 @@ if [ -n "${PDF_OUTPUT}" ]; then
862872
mkdir -p "$(dirname ${SOURCE_DIR}/${PDFLOG_OUTPUT})"
863873
cp "${LATEX_LOG}" "${SOURCE_DIR}/${PDFLOG_OUTPUT}"
864874
fi
865-
fi
875+
fi
866876

867877
# Generate the docx output
868878
if [ -n "${DOCX_OUTPUT}" ]; then
@@ -885,7 +895,7 @@ if [ -n "${DIFFPDF_OUTPUT}" -o -n "${DIFFTEX_OUTPUT}" ]; then
885895
echo "diff output failed"
886896
else
887897
do_md_fixups "${BUILD_DIR}/${INPUT_FILE}"
888-
do_latex "${BUILD_DIR}/${INPUT_FILE}" "${TEMP_DIFFBASE_TEX_FILE}" "${EXTRA_PANDOC_OPTIONS} -V keepstaleimages=true"
898+
do_latex "${BUILD_DIR}/${INPUT_FILE}" "${TEMP_DIFFBASE_TEX_FILE}" "${CROSSREF_TYPE}" "${EXTRA_PANDOC_OPTIONS} -V keepstaleimages=true"
889899
echo "Running latexdiff... (this may take a while for complex changes)"
890900
start=$(date +%s)
891901
latexdiff-fast --math-markup=whole --preamble /resources/templates/latexdiff.tex --config /resources/templates/latexdiff.cfg --append-safecmd /resources/templates/latexdiff.safe --exclude-safecmd /resources/templates/latexdiff.unsafe "${TEMP_DIFFBASE_TEX_FILE}" "${TEMP_TEX_FILE}" > "${TEMP_DIFF_TEX_FILE}" 2>"${TEMP_LATEXDIFF_LOG}"
File renamed without changes.

filter/pandoc-crossref-tcg.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
figPrefix: "Figure"
2+
eqnPrefix: "Equation"
3+
tblPrefix: "Table"
4+
secPrefix: "Section"

0 commit comments

Comments
 (0)