Skip to content

Commit

Permalink
Features for tpm spec (#40)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
chrisfenner authored Dec 3, 2023
1 parent 1650632 commit 0c33b2d
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 55 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ RUN tlmgr update --self && \
hardwrap \
catchfile \
ragged2e \
enumitem
enumitem \
mathtools

RUN apk upgrade && apk add --no-cache \
bash \
Expand Down
18 changes: 8 additions & 10 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -79,7 +79,7 @@ while true; do
pdf_output="${2}"
shift 2
;;
--resouredir)
--resourcedir)
resource_dir="${2}"
shift 2
;;
Expand Down Expand Up @@ -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 \
Expand All @@ -279,7 +279,7 @@ if [ -n "${pdf_output}" ]; then
--metadata=titlepage-rule-height:0 \
--metadata=colorlinks:true \
--metadata=contact:[email protected] \
--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" \
Expand All @@ -291,7 +291,6 @@ fi
if [ -n "${latex_output}" ]; then
echo "Generating LaTeX Output"
pandoc \
--citeproc \
--embed-resources \
--standalone \
--template=eisvogel.latex \
Expand All @@ -311,7 +310,7 @@ if [ -n "${latex_output}" ]; then
--metadata=titlepage-rule-height:0 \
--metadata=colorlinks:true \
--metadata=contact:[email protected] \
--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" \
Expand All @@ -323,15 +322,14 @@ fi
if [ -n "${docx_output}" ]; then
echo "Generating DOCX Output"
pandoc \
--citeproc \
--embed-resources \
--standalone \
--filter=/resources/filters/info.py \
--filter=mermaid-filter \
--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 \
Expand Down
15 changes: 15 additions & 0 deletions sample3.md
Original file line number Diff line number Diff line change
Expand Up @@ -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++
Expand Down
53 changes: 9 additions & 44 deletions scripts/mkpdf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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:[email protected] \
--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
13 changes: 13 additions & 0 deletions template/eisvogel.latex
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
% POSSIBILITY OF SUCH DAMAGE.
%%

%% Enable useful error output.
\errorcontextlines 10000

%%
% This is the Eisvogel pandoc LaTeX template.
%
Expand Down Expand Up @@ -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$
Expand Down Expand Up @@ -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)$
Expand Down

0 comments on commit 0c33b2d

Please sign in to comment.