Skip to content

Commit 0c33b2d

Browse files
authored
Features for tpm spec (#40)
* Fix up mkpdf.sh This change fixes mkpdf.sh to take the dependency on build.sh inside the Docker container instead of doing the fixups itself. It simplifies the script down to: 1. Create and mount a temp directory for simplified file I/O to the Docker container 2. Use docker run but with a customized entrypoint that also copies files to the current directory and back to the working directory 3. Check for errors * Add some quality-of-life changes to the TCG fork of Eisvogel 1. Increase the limit for list nesting depth from 5 to 9 2. Enable more than one line of error output, for debugging * Remove citations, add table_captions This change adds some improved complex TCG doc support to build.sh. The extension `grid_tables` is added, which is the only way to have a table with cells that span multiple columns or rows without writing your tables in raw HTML. The extension `citations` is removed: it gets messed up by TCG documents with "@" symbols, and TCG typically handles its own references section manually (e.g., in a section called Normative References) A trivial typo is fixed: "resouredir" -> "resourcedir" * Add mathtools to the latex plugins * move enumitem settings to just before the document * try moving the enumitem settings to near the header-includes * remove math-mode $'s around labels * add mathtools, add grid table sample * move usepackage mathtools * render all samples
1 parent 1650632 commit 0c33b2d

File tree

6 files changed

+54
-55
lines changed

6 files changed

+54
-55
lines changed

.github/workflows/docker-publish.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,13 @@ jobs:
108108
output-pdf: sample2.pdf
109109
output-tex: sample2.tex
110110

111+
- name: Run the action on sample3
112+
uses: trustedcomputinggroup/markdown@latest
113+
with:
114+
input-md: sample3.md
115+
output-pdf: sample3.pdf
116+
output-tex: sample3.tex
117+
111118
- name: Upload Artifact
112119
uses: actions/upload-artifact@master
113120
with:

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ RUN tlmgr update --self && \
3434
hardwrap \
3535
catchfile \
3636
ragged2e \
37-
enumitem
37+
enumitem \
38+
mathtools
3839

3940
RUN apk upgrade && apk add --no-cache \
4041
bash \

build.sh

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ print_usage() {
2323
echo "$(basename "${0}") [options] [input-file]"
2424
echo
2525
echo "Arguments:"
26-
echo " This script takes a single markdown file input for rendering to docx/pdf/LaTex."
26+
echo " This script takes a single markdown file input for rendering to docx/pdf/LaTeX."
2727
echo
2828
echo "Options:"
2929
echo
@@ -34,14 +34,14 @@ print_usage() {
3434
echo
3535
echo "Miscellaneous"
3636
echo " --puppeteer: enable outputing of .puppeteer.json in current directory. This is needed for running in sandboxes eg docker containers."
37-
echo " --resouredir=dir: Set the resource directory, defaults to root for pandoc containers"
37+
echo " --resourcedir=dir: Set the resource directory, defaults to root for pandoc containers"
3838
echo " --notmp: Do not use a tempory directory for processing steps, instead create a directory called \"build\" in CWD"
3939
echo " --gitversion: Use git describe to generate document version and revision metadata."
4040
echo " --gitstatus: Use git describe to generate document version and revision metadata. Implies --gitversion"
4141
}
4242

4343

44-
if ! options=$(getopt --longoptions=help,puppeteer,notmp,gitversion,gitstatus,pdf:,latex:,docx:,resouredir: --options="" -- "$@"); then
44+
if ! options=$(getopt --longoptions=help,puppeteer,notmp,gitversion,gitstatus,pdf:,latex:,docx:,resourcedir: --options="" -- "$@"); then
4545
echo "Incorrect options provided"
4646
print_usage
4747
exit 1
@@ -79,7 +79,7 @@ while true; do
7979
pdf_output="${2}"
8080
shift 2
8181
;;
82-
--resouredir)
82+
--resourcedir)
8383
resource_dir="${2}"
8484
shift 2
8585
;;
@@ -259,7 +259,7 @@ export MERMAID_FILTER_FORMAT="pdf"
259259
if [ -n "${pdf_output}" ]; then
260260
echo "Generating PDF Output"
261261
pandoc \
262-
--citeproc \
262+
--trace \
263263
--embed-resources \
264264
--standalone \
265265
--template=eisvogel.latex \
@@ -279,7 +279,7 @@ if [ -n "${pdf_output}" ]; then
279279
--metadata=titlepage-rule-height:0 \
280280
--metadata=colorlinks:true \
281281
--metadata=contact:[email protected] \
282-
--from=markdown+implicit_figures+table_captions+citations \
282+
--from=markdown+implicit_figures+grid_tables+table_captions-citations \
283283
${extra_pandoc_options} \
284284
--to=pdf \
285285
"${build_dir}/${input_file}.3" \
@@ -291,7 +291,6 @@ fi
291291
if [ -n "${latex_output}" ]; then
292292
echo "Generating LaTeX Output"
293293
pandoc \
294-
--citeproc \
295294
--embed-resources \
296295
--standalone \
297296
--template=eisvogel.latex \
@@ -311,7 +310,7 @@ if [ -n "${latex_output}" ]; then
311310
--metadata=titlepage-rule-height:0 \
312311
--metadata=colorlinks:true \
313312
--metadata=contact:[email protected] \
314-
--from=markdown+implicit_figures+table_captions+citations \
313+
--from=markdown+implicit_figures+grid_tables+table_captions-citations \
315314
${extra_pandoc_options} \
316315
--to=latex \
317316
"${build_dir}/${input_file}.3" \
@@ -323,15 +322,14 @@ fi
323322
if [ -n "${docx_output}" ]; then
324323
echo "Generating DOCX Output"
325324
pandoc \
326-
--citeproc \
327325
--embed-resources \
328326
--standalone \
329327
--filter=/resources/filters/info.py \
330328
--filter=mermaid-filter \
331329
--filter=pandoc-crossref \
332330
--resource-path=.:/resources \
333331
--data-dir=/resources \
334-
--from=markdown+implicit_figures+table_captions+citations \
332+
--from=markdown+implicit_figures+grid_tables+table_captions-citations \
335333
--reference-doc=/resources/templates/tcg_template.docx \
336334
${extra_pandoc_options} \
337335
--to=docx \

sample3.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,21 @@ Table: List of Mandatory Curves
133133
| TPM_ECC_NIST_P256 | M |
134134
| TPM_ECC_NIST_P384 | M |
135135

136+
### Temperatures
137+
138+
This section contains a Grid Table.
139+
140+
+---------------------+-----------------------+
141+
| Location | Temperature 1961-1990 |
142+
| | in degree Celsius |
143+
| +-------+-------+-------+
144+
| | min | mean | max |
145+
+=====================+=======+=======+=======+
146+
| Antarctica | -89.2 | N/A | 19.8 |
147+
+---------------------+-------+-------+-------+
148+
| Earth | -89.2 | 14 | 56.7 |
149+
+---------------------+-------+-------+-------+
150+
136151
## Code
137152

138153
```c++

scripts/mkpdf.sh

Lines changed: 9 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -13,54 +13,19 @@ if [[ ! -f "$MD" ]]; then
1313
fi
1414

1515
cp $MD $WD/spec.md
16-
MD=$WD/spec.md
1716
DOCKER_MD=$DOCKER_WD/spec.md
1817

19-
# \newpage is rendered as the string "\newpage" in GitHub markdown.
20-
# Transform horizontal rules into \newpages.
21-
# Exception: the YAML front matter of the document, so undo the instance on the first line.
22-
sed -i 's/^---$/\\newpage/g;1s/\\newpage/---/g' $MD
23-
24-
# Transform sections before the table of contents into addsec, which does not number them.
25-
# While we're doing this, transform the case to all-caps.
26-
sed -i '0,/\\tableofcontents/s/^# \(.*\)/\\addsec\{\U\1\}/g' $MD
27-
28-
# Get data
29-
DATE=$(grep "date:" $MD | head -n 1 | cut -d ' ' -f 2)
30-
YEAR=$(date --date=$DATE +%Y)
31-
DATE_ENGLISH=$(date --date=$DATE "+%B %-d, %Y")
32-
33-
OUT="${DOCKER_WD}/tcgspec.pdf"
34-
35-
# Make PDF
36-
PANDOC_OPTS="--embed-resources \
37-
--standalone \
38-
--template=/resources/template/eisvogel.latex \
39-
--filter=mermaid-filter \
40-
--filter=pandoc-crossref \
41-
--resource-path=.:/resources \
42-
--data-dir=/resources \
43-
--top-level-division=section \
44-
--variable=block-headings \
45-
--variable=numbersections \
46-
--variable=table-use-row-colors \
47-
--metadata=date-english:\"${DATE_ENGLISH}\" \
48-
--metadata=year:"${YEAR}" \
49-
--metadata=titlepage:true \
50-
--metadata=titlepage-background:/resources/img/greentop.png \
51-
--metadata=logo:/resources/img/tcg.png \
52-
--metadata=titlepage-rule-height:0 \
53-
--metadata=colorlinks:true \
54-
--metadata=contact:[email protected] \
55-
--from=markdown+implicit_figures+table_captions \
56-
--to=pdf \
57-
--output=${OUT}"
18+
OUT="${DOCKER_WD}/output.pdf"
5819

20+
SCRIPT_OPTS="--pdf=output.pdf spec.md"
5921
DOCKER_OPTS="-v $WD:$DOCKER_WD"
22+
DOCKER_COMMAND="cp $DOCKER_MD .; /usr/bin/build.sh $SCRIPT_OPTS; cp ./output.* $DOCKER_WD"
6023
IMAGE_NAME="ghcr.io/trustedcomputinggroup/pandoc"
6124

62-
# Quotes around DATE_ENGLISH get messed up during expansion. Instead,
63-
# quotes are added menually above and eval is used to execute the command.
64-
eval "docker run $DOCKER_OPTS $IMAGE_NAME $DOCKER_MD $PANDOC_OPTS"
25+
eval "docker run $DOCKER_OPTS --entrypoint /bin/sh $IMAGE_NAME -c '$DOCKER_COMMAND'"
6526

66-
echo "Generated spec at $OUT"
27+
if [ $? -eq 0 ]; then
28+
echo "Generated spec at $OUT"
29+
else
30+
echo "Failed to generate spec"
31+
fi

template/eisvogel.latex

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
% POSSIBILITY OF SUCH DAMAGE.
3434
%%
3535

36+
%% Enable useful error output.
37+
\errorcontextlines 10000
38+
3639
%%
3740
% This is the Eisvogel pandoc LaTeX template.
3841
%
@@ -131,6 +134,7 @@ $if(beamerarticle)$
131134
\usepackage{beamerarticle} % needs to be loaded first
132135
$endif$
133136
\usepackage{amsmath,amssymb}
137+
\usepackage{mathtools}
134138
$if(fontfamily)$
135139
\usepackage[$for(fontfamilyoptions)$$fontfamilyoptions$$sep$,$endfor$]{$fontfamily$}
136140
$else$
@@ -433,6 +437,15 @@ $endif$
433437
$for(header-includes)$
434438
$header-includes$
435439
$endfor$
440+
441+
%% TCG docs tend to have deeply nested lists, too deep for Pandoc/Latex defaults.
442+
\usepackage{enumitem}
443+
\setlistdepth{9}
444+
\setlist[itemize]{label=\textbullet}
445+
\renewlist{itemize}{itemize}{9}
446+
\setlist[enumerate]{label=\arabic*.}
447+
\renewlist{enumerate}{enumerate}{9}
448+
436449
$if(lang)$
437450
\ifxetex
438451
$if(mainfont)$

0 commit comments

Comments
 (0)