From 0c33b2d6feb26e90c428ccd62479262496129b5a Mon Sep 17 00:00:00 2001 From: Chris Fenner Date: Sun, 3 Dec 2023 11:53:32 -0800 Subject: [PATCH] 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 --- .github/workflows/docker-publish.yml | 7 ++++ Dockerfile | 3 +- build.sh | 18 +++++----- sample3.md | 15 ++++++++ scripts/mkpdf.sh | 53 +++++----------------------- template/eisvogel.latex | 13 +++++++ 6 files changed, 54 insertions(+), 55 deletions(-) diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index e9e73a3..9d5f337 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -108,6 +108,13 @@ jobs: output-pdf: sample2.pdf output-tex: sample2.tex + - name: Run the action on sample3 + uses: trustedcomputinggroup/markdown@latest + with: + input-md: sample3.md + output-pdf: sample3.pdf + output-tex: sample3.tex + - name: Upload Artifact uses: actions/upload-artifact@master with: diff --git a/Dockerfile b/Dockerfile index 5335ff9..9d38f70 100644 --- a/Dockerfile +++ b/Dockerfile @@ -34,7 +34,8 @@ RUN tlmgr update --self && \ hardwrap \ catchfile \ ragged2e \ - enumitem + enumitem \ + mathtools RUN apk upgrade && apk add --no-cache \ bash \ diff --git a/build.sh b/build.sh index 7362050..ac2e207 100755 --- a/build.sh +++ b/build.sh @@ -23,7 +23,7 @@ print_usage() { echo "$(basename "${0}") [options] [input-file]" echo echo "Arguments:" - echo " This script takes a single markdown file input for rendering to docx/pdf/LaTex." + echo " This script takes a single markdown file input for rendering to docx/pdf/LaTeX." echo echo "Options:" echo @@ -34,14 +34,14 @@ print_usage() { echo echo "Miscellaneous" echo " --puppeteer: enable outputing of .puppeteer.json in current directory. This is needed for running in sandboxes eg docker containers." - echo " --resouredir=dir: Set the resource directory, defaults to root for pandoc containers" + echo " --resourcedir=dir: Set the resource directory, defaults to root for pandoc containers" echo " --notmp: Do not use a tempory directory for processing steps, instead create a directory called \"build\" in CWD" echo " --gitversion: Use git describe to generate document version and revision metadata." echo " --gitstatus: Use git describe to generate document version and revision metadata. Implies --gitversion" } -if ! options=$(getopt --longoptions=help,puppeteer,notmp,gitversion,gitstatus,pdf:,latex:,docx:,resouredir: --options="" -- "$@"); then +if ! options=$(getopt --longoptions=help,puppeteer,notmp,gitversion,gitstatus,pdf:,latex:,docx:,resourcedir: --options="" -- "$@"); then echo "Incorrect options provided" print_usage exit 1 @@ -79,7 +79,7 @@ while true; do pdf_output="${2}" shift 2 ;; - --resouredir) + --resourcedir) resource_dir="${2}" shift 2 ;; @@ -259,7 +259,7 @@ export MERMAID_FILTER_FORMAT="pdf" if [ -n "${pdf_output}" ]; then echo "Generating PDF Output" pandoc \ - --citeproc \ + --trace \ --embed-resources \ --standalone \ --template=eisvogel.latex \ @@ -279,7 +279,7 @@ if [ -n "${pdf_output}" ]; then --metadata=titlepage-rule-height:0 \ --metadata=colorlinks:true \ --metadata=contact:admin@trustedcomputinggroup.org \ - --from=markdown+implicit_figures+table_captions+citations \ + --from=markdown+implicit_figures+grid_tables+table_captions-citations \ ${extra_pandoc_options} \ --to=pdf \ "${build_dir}/${input_file}.3" \ @@ -291,7 +291,6 @@ fi if [ -n "${latex_output}" ]; then echo "Generating LaTeX Output" pandoc \ - --citeproc \ --embed-resources \ --standalone \ --template=eisvogel.latex \ @@ -311,7 +310,7 @@ if [ -n "${latex_output}" ]; then --metadata=titlepage-rule-height:0 \ --metadata=colorlinks:true \ --metadata=contact:admin@trustedcomputinggroup.org \ - --from=markdown+implicit_figures+table_captions+citations \ + --from=markdown+implicit_figures+grid_tables+table_captions-citations \ ${extra_pandoc_options} \ --to=latex \ "${build_dir}/${input_file}.3" \ @@ -323,7 +322,6 @@ fi if [ -n "${docx_output}" ]; then echo "Generating DOCX Output" pandoc \ - --citeproc \ --embed-resources \ --standalone \ --filter=/resources/filters/info.py \ @@ -331,7 +329,7 @@ if [ -n "${docx_output}" ]; then --filter=pandoc-crossref \ --resource-path=.:/resources \ --data-dir=/resources \ - --from=markdown+implicit_figures+table_captions+citations \ + --from=markdown+implicit_figures+grid_tables+table_captions-citations \ --reference-doc=/resources/templates/tcg_template.docx \ ${extra_pandoc_options} \ --to=docx \ diff --git a/sample3.md b/sample3.md index 1a517e4..962a28d 100644 --- a/sample3.md +++ b/sample3.md @@ -133,6 +133,21 @@ Table: List of Mandatory Curves | TPM_ECC_NIST_P256 | M | | TPM_ECC_NIST_P384 | M | +### Temperatures + +This section contains a Grid Table. + ++---------------------+-----------------------+ +| Location | Temperature 1961-1990 | +| | in degree Celsius | +| +-------+-------+-------+ +| | min | mean | max | ++=====================+=======+=======+=======+ +| Antarctica | -89.2 | N/A | 19.8 | ++---------------------+-------+-------+-------+ +| Earth | -89.2 | 14 | 56.7 | ++---------------------+-------+-------+-------+ + ## Code ```c++ diff --git a/scripts/mkpdf.sh b/scripts/mkpdf.sh index 3bc3f95..4f0d5ba 100755 --- a/scripts/mkpdf.sh +++ b/scripts/mkpdf.sh @@ -13,54 +13,19 @@ if [[ ! -f "$MD" ]]; then fi cp $MD $WD/spec.md -MD=$WD/spec.md DOCKER_MD=$DOCKER_WD/spec.md -# \newpage is rendered as the string "\newpage" in GitHub markdown. -# Transform horizontal rules into \newpages. -# Exception: the YAML front matter of the document, so undo the instance on the first line. -sed -i 's/^---$/\\newpage/g;1s/\\newpage/---/g' $MD - -# Transform sections before the table of contents into addsec, which does not number them. -# While we're doing this, transform the case to all-caps. -sed -i '0,/\\tableofcontents/s/^# \(.*\)/\\addsec\{\U\1\}/g' $MD - -# Get data -DATE=$(grep "date:" $MD | head -n 1 | cut -d ' ' -f 2) -YEAR=$(date --date=$DATE +%Y) -DATE_ENGLISH=$(date --date=$DATE "+%B %-d, %Y") - -OUT="${DOCKER_WD}/tcgspec.pdf" - -# Make PDF -PANDOC_OPTS="--embed-resources \ - --standalone \ - --template=/resources/template/eisvogel.latex \ - --filter=mermaid-filter \ - --filter=pandoc-crossref \ - --resource-path=.:/resources \ - --data-dir=/resources \ - --top-level-division=section \ - --variable=block-headings \ - --variable=numbersections \ - --variable=table-use-row-colors \ - --metadata=date-english:\"${DATE_ENGLISH}\" \ - --metadata=year:"${YEAR}" \ - --metadata=titlepage:true \ - --metadata=titlepage-background:/resources/img/greentop.png \ - --metadata=logo:/resources/img/tcg.png \ - --metadata=titlepage-rule-height:0 \ - --metadata=colorlinks:true \ - --metadata=contact:admin@trustedcomputinggroup.org \ - --from=markdown+implicit_figures+table_captions \ - --to=pdf \ - --output=${OUT}" +OUT="${DOCKER_WD}/output.pdf" +SCRIPT_OPTS="--pdf=output.pdf spec.md" DOCKER_OPTS="-v $WD:$DOCKER_WD" +DOCKER_COMMAND="cp $DOCKER_MD .; /usr/bin/build.sh $SCRIPT_OPTS; cp ./output.* $DOCKER_WD" IMAGE_NAME="ghcr.io/trustedcomputinggroup/pandoc" -# Quotes around DATE_ENGLISH get messed up during expansion. Instead, -# quotes are added menually above and eval is used to execute the command. -eval "docker run $DOCKER_OPTS $IMAGE_NAME $DOCKER_MD $PANDOC_OPTS" +eval "docker run $DOCKER_OPTS --entrypoint /bin/sh $IMAGE_NAME -c '$DOCKER_COMMAND'" -echo "Generated spec at $OUT" +if [ $? -eq 0 ]; then + echo "Generated spec at $OUT" +else + echo "Failed to generate spec" +fi diff --git a/template/eisvogel.latex b/template/eisvogel.latex index 4d03c14..f3290c3 100644 --- a/template/eisvogel.latex +++ b/template/eisvogel.latex @@ -33,6 +33,9 @@ % POSSIBILITY OF SUCH DAMAGE. %% +%% Enable useful error output. +\errorcontextlines 10000 + %% % This is the Eisvogel pandoc LaTeX template. % @@ -131,6 +134,7 @@ $if(beamerarticle)$ \usepackage{beamerarticle} % needs to be loaded first $endif$ \usepackage{amsmath,amssymb} +\usepackage{mathtools} $if(fontfamily)$ \usepackage[$for(fontfamilyoptions)$$fontfamilyoptions$$sep$,$endfor$]{$fontfamily$} $else$ @@ -433,6 +437,15 @@ $endif$ $for(header-includes)$ $header-includes$ $endfor$ + +%% TCG docs tend to have deeply nested lists, too deep for Pandoc/Latex defaults. +\usepackage{enumitem} +\setlistdepth{9} +\setlist[itemize]{label=\textbullet} +\renewlist{itemize}{itemize}{9} +\setlist[enumerate]{label=\arabic*.} +\renewlist{enumerate}{enumerate}{9} + $if(lang)$ \ifxetex $if(mainfont)$