@@ -9,6 +9,7 @@ DIFFTEX_OUTPUT=""
9
9
DOCX_OUTPUT=" "
10
10
HTML_OUTPUT=" "
11
11
LATEX_OUTPUT=" "
12
+ TYPST_OUTPUT=" "
12
13
PDFLOG_OUTPUT=" "
13
14
VERSIONED_FILENAMES=" no"
14
15
PR_NUMBER=" "
@@ -54,6 +55,7 @@ print_usage() {
54
55
echo " --crossref=(iso|tcg): set cross-reference style."
55
56
echo " --pdf=output: enable output of pdf and specify the output file name."
56
57
echo " --latex=output: enable output of latex and specify the output file name."
58
+ echo " --typst=output: enable output of typst and specify the output file name."
57
59
echo " --html=output: enable output of html and specify the output file name."
58
60
echo " --pdflog=output: enable logging of pdf engine and specify the output file name."
59
61
echo " --diffpdf=output: enable output of pdf diff and specify the output file name (requires --diffbase)"
@@ -72,13 +74,13 @@ print_usage() {
72
74
echo " --versioned_filenames: insert version information before the file extension for outputs"
73
75
echo " --pr_number=number: mark the document as a pull-request draft if using Git versioning."
74
76
echo " --pr_repo=url: provide the URL for the repository for pull-request drafts (has no effect if --PR_NUMBER is not passed)."
75
- echo " --pdf_engine=(xelatex|lualatex): use the given latex engine (default xelatex)"
77
+ echo " --pdf_engine=(xelatex|lualatex|typst ): use the given PDF engine (default xelatex)"
76
78
echo " --noautobackmatter: don't automatically insert back matter at the end of the document."
77
79
echo " --csl: provide a csl file via the command line (instead of in YAML metadata)."
78
80
}
79
81
80
82
81
- 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:,template:,template_html:,html_stylesheet:,reference_doc:,docx:,crossref:,html:,resourcedir:,noautobackmatter,csl: --options=" " -- " $@ " ) ; then
83
+ 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:,typst:, pdflog:,pdf_engine:,template:,template_html:,html_stylesheet:,reference_doc:,docx:,crossref:,html:,resourcedir:,noautobackmatter,csl: --options=" " -- " $@ " ) ; then
82
84
echo " Incorrect options provided"
83
85
print_usage
84
86
exit 1
@@ -128,6 +130,10 @@ while true; do
128
130
LATEX_OUTPUT=" ${2} "
129
131
shift 2
130
132
;;
133
+ --typst)
134
+ TYPST_OUTPUT=" ${2} "
135
+ shift 2
136
+ ;;
131
137
--pdflog)
132
138
PDFLOG_OUTPUT=" ${2} "
133
139
shift 2
@@ -243,7 +249,7 @@ if [ -z "${PDF_OUTPUT}${LATEX_OUTPUT}${DOCX_OUTPUT}${HTML_OUTPUT}" ]; then
243
249
fi
244
250
245
251
# the pdf engine must be supported
246
- if [ " ${PDF_ENGINE} " != " xelatex" -a " ${PDF_ENGINE} " != " lualatex" ]; then
252
+ if [ " ${PDF_ENGINE} " != " xelatex" -a " ${PDF_ENGINE} " != " lualatex" -a " ${PDF_ENGINE} " != " typst " ]; then
247
253
>&2 echo " Unsupported PDF engine '${PDF_ENGINE} ', expected one of: xelatex, lualatex"
248
254
print_usage
249
255
exit 1
@@ -504,6 +510,7 @@ echo "pdf: ${PDF_OUTPUT:-none} (engine: ${PDF_ENGINE})"
504
510
echo " diff pdf: ${DIFFPDF_OUTPUT:- none} (engine: ${PDF_ENGINE} )"
505
511
echo " latex: ${latex_ouput:- none} "
506
512
echo " diff latex: ${DIFFTEX_OUTPUT:- none} "
513
+ echo " typst: ${TYPST_OUTPUT:- none} "
507
514
echo " html: ${html_ouput:- none} "
508
515
echo " resource dir: ${RESOURCE_DIR} "
509
516
echo " build dir: ${BUILD_DIR} "
@@ -718,7 +725,7 @@ retry () {
718
725
}
719
726
720
727
# Greps the latex logs to surface relevant errors and warnings.
721
- analyze_latex_logs () {
728
+ analyze_pdf_logs () {
722
729
local logfile=$1
723
730
724
731
local runcount=$( grep " Run number " " ${logfile} " | tail -n 1 | cut -d ' ' -f 3)
@@ -819,8 +826,61 @@ do_latex() {
819
826
cache_generated_files
820
827
}
821
828
829
+ # Takes Markdown input and writes Typst output using pandoc.
830
+ do_typst () {
831
+ local input=$1
832
+ local output=$2
833
+ local crossref=$3
834
+ local extra_pandoc_options=$4
835
+ mkdir -p " $( dirname ${output} ) "
836
+
837
+ # TODO: https://github.com/TrustedComputingGroup/pandoc/issues/164
838
+ # highlighting breaks diffing due to the \xxxxTok commands generated during highlighting being fragile.
839
+ # Citations: https://pandoc.org/MANUAL.html#other-relevant-metadata-fields
840
+ echo " Generating Typst Output"
841
+ local start=$( date +%s)
842
+ local cmd=(pandoc
843
+ --standalone
844
+ --highlight-style=${SYNTAX_HIGHLIGHT_STYLE}
845
+ --lua-filter=convert-diagrams.lua
846
+ --lua-filter=convert-images.lua
847
+ --lua-filter=parse-html.lua
848
+ --filter=pandoc-crossref
849
+ --citeproc
850
+ --resource-path=.:/resources:${RESOURCE_DIR}
851
+ --data-dir=/resources
852
+ --top-level-division=section
853
+ --variable=block-headings
854
+ --variable=numbersections
855
+ --metadata=date:" '${DATE} '"
856
+ --metadata=date-english:" '${DATE_ENGLISH} '"
857
+ --metadata=year:" '${YEAR} '"
858
+ --metadata=titlepage:true
859
+ --metadata=link-citations
860
+ --metadata=link-bibliography
861
+ --metadata=crossrefYaml:/resources/filters/pandoc-crossref-${crossref} .yaml
862
+ --metadata=colorlinks:true
863
+ --metadata=contact:
[email protected]
864
+ --from=${FROM}
865
+ ${extra_pandoc_options}
866
+ --to=typst
867
+ --output=" '${output} '"
868
+ " '${input} '" )
869
+ retry 5 " ${cmd[@]} "
870
+ if [ $? -ne 0 ]; then
871
+ FAILED=true
872
+ echo " Typst output failed"
873
+ fi
874
+ local end=$( date +%s)
875
+ echo " Elapsed time: $(( $end - $start )) seconds"
876
+
877
+ # Cache generated files now so they don't need to be
878
+ # re-rendered if the build later fails.
879
+ cache_generated_files
880
+ }
881
+
822
882
# Takes LaTeX input and writes PDF output and logs using the PDF engine of choice.
823
- do_pdf () {
883
+ do_pdf_from_latex () {
824
884
local input=$1
825
885
local output=$2
826
886
mkdir -p " $( dirname ${output} ) "
@@ -854,10 +914,37 @@ do_pdf() {
854
914
cp_chown " .cache/${temp_pdf_file} " " ${output} " && rm " .cache/${temp_pdf_file} "
855
915
fi
856
916
if [[ ! " ${FAILED} " = " true" ]]; then
857
- analyze_latex_logs " ${logfile} "
917
+ analyze_pdf_logs " ${logfile} "
858
918
fi
859
919
}
860
920
921
+
922
+ # Takes Typst input and writes PDF output and logs.
923
+ do_pdf_from_typst () {
924
+ local input=$1
925
+ local output=$2
926
+ mkdir -p " $( dirname ${output} ) "
927
+
928
+ local logfile=$3
929
+ local temp_pdf_file=" $( basename ${input% .* } ) .pdf"
930
+ rm -f ${temp_pdf_file}
931
+ local start=$( date +%s)
932
+ typst compile ${input} ${temp_pdf_file}
933
+ if [ $? -ne 0 ]; then
934
+ FAILED=true
935
+ echo " PDF output failed"
936
+ fi
937
+ if [[ ! " ${FAILED} " = " true" || " ${ignore_errors} " = " true" ]]; then
938
+ cp_chown " ${temp_pdf_file} " " ${output} "
939
+ fi
940
+ if [ $? -ne 0 ]; then
941
+ FAILED=true
942
+ echo " PDF output failed"
943
+ fi
944
+ local end=$( date +%s)
945
+ echo " Elapsed time: $(( $end - $start )) seconds"
946
+ }
947
+
861
948
# Takes Markdown input and writes Docx output using pandoc.
862
949
do_docx () {
863
950
local input=$1
@@ -964,31 +1051,43 @@ do_html() {
964
1051
fi
965
1052
}
966
1053
967
- # Generate .tex output if either latex or pdf formats were requested, because
968
- # the .tex is an intermediate requirement to the pdf.
1054
+ do_md_fixups " ${BUILD_DIR} /${INPUT_FILE} "
1055
+
1056
+ # Generate .typ output if either typst or pdf format (using the Typst engine) were requested.
1057
+ readonly TEMP_TYP_FILE=" ${BUILD_DIR} /${INPUT_FILE} .typ"
1058
+ if { [ -n " ${TYPST_OUTPUT} " ] || { [ " ${PDF_ENGINE} " == " typst" ] && [ -n " ${PDF_OUTPUT} " ]; }; }; then
1059
+ do_typst " ${BUILD_DIR} /${INPUT_FILE} " " ${TEMP_TYP_FILE} " " ${CROSSREF_TYPE} " " ${EXTRA_PANDOC_OPTIONS} "
1060
+ fi
1061
+ if [ -n " ${TYPST_OUTPUT} " ]; then
1062
+ cp_chown " ${TEMP_TYP_FILE} " " ${SOURCE_DIR} /${TYPST_OUTPUT} "
1063
+ fi
1064
+
1065
+ # Generate .tex output if either latex or pdf formats (using a non-Typst engine) were requested.
969
1066
readonly TEMP_TEX_FILE=" ${BUILD_DIR} /${INPUT_FILE} .tex"
970
- if [ -n " ${PDF_OUTPUT} " -o -n " ${LATEX_OUTPUT} " -o -n " ${DIFFPDF_OUTPUT} " -o -n " ${DIFFTEX_OUTPUT} " ]; then
971
- do_md_fixups " ${BUILD_DIR} /${INPUT_FILE} "
1067
+ if { [ -n " ${LATEX_OUTPUT} " ] || [ -n " ${DIFFTEX_OUTPUT} " ] || { [ " ${PDF_ENGINE} " != " typst" ] && { [ -n " ${PDF_OUTPUT} " ] || [ -n " ${DIFFPDF_OUTPUT} " ]; }; }; }; then
972
1068
do_latex " ${BUILD_DIR} /${INPUT_FILE} " " ${TEMP_TEX_FILE} " " ${CROSSREF_TYPE} " " ${EXTRA_PANDOC_OPTIONS} "
973
1069
fi
974
1070
if [ -n " ${LATEX_OUTPUT} " ]; then
975
1071
cp_chown " ${TEMP_TEX_FILE} " " ${SOURCE_DIR} /${LATEX_OUTPUT} "
976
1072
fi
977
1073
978
1074
# Generate the PDF output
979
- readonly LATEX_LOG =" ${BUILD_DIR} /latex .log"
1075
+ readonly PDF_LOG =" ${BUILD_DIR} /pdf .log"
980
1076
if [ -n " ${PDF_OUTPUT} " ]; then
981
- do_pdf " ${TEMP_TEX_FILE} " " ${SOURCE_DIR} /${PDF_OUTPUT} " " ${LATEX_LOG} " false
1077
+ if [ " ${PDF_ENGINE} " == " typst" ]; then
1078
+ do_pdf_from_typst " ${TEMP_TYP_FILE} " " ${SOURCE_DIR} /${PDF_OUTPUT} " " ${PDF_LOG} " false
1079
+ else
1080
+ do_pdf_from_latex " ${TEMP_TEX_FILE} " " ${SOURCE_DIR} /${PDF_OUTPUT} " " ${PDF_LOG} " false
1081
+ fi
982
1082
983
1083
# Copy the logs, if requested.
984
1084
if [ -n " ${PDFLOG_OUTPUT} " ]; then
985
- cp_chown " ${LATEX_LOG } " " ${SOURCE_DIR} /${PDFLOG_OUTPUT} "
1085
+ cp_chown " ${PDF_LOG } " " ${SOURCE_DIR} /${PDFLOG_OUTPUT} "
986
1086
fi
987
1087
fi
988
1088
989
1089
# Generate the html output
990
1090
if [ -n " ${HTML_OUTPUT} " ]; then
991
- do_md_fixups " ${BUILD_DIR} /${INPUT_FILE} " " html"
992
1091
do_html " ${BUILD_DIR} /${INPUT_FILE} " " ${SOURCE_DIR} /${HTML_OUTPUT} " " ${CROSSREF_TYPE} "
993
1092
fi
994
1093
@@ -1036,7 +1135,7 @@ if [ "${FAILED}" != "true" -a -n "${DIFFPDF_OUTPUT}" ]; then
1036
1135
# We do our best to fix up the latexdiff result so that it compiles without errors.
1037
1136
# In some cases, there are still errors. It is better to produce an ugly diff-document than to
1038
1137
# produce no diff-document at all.
1039
- do_pdf " ${TEMP_DIFF_TEX_FILE} " " ${SOURCE_DIR} /${DIFFPDF_OUTPUT} " " ${LATEX_LOG } " true
1138
+ do_pdf_from_latex " ${TEMP_DIFF_TEX_FILE} " " ${SOURCE_DIR} /${DIFFPDF_OUTPUT} " " ${PDF_LOG } " true
1040
1139
1041
1140
# Copy the logs, if requested. Note that this file gets the latexdiff and PDF driver output.
1042
1141
if [ -n " ${DIFFPDFLOG_OUTPUT} " ]; then
@@ -1045,7 +1144,7 @@ if [ "${FAILED}" != "true" -a -n "${DIFFPDF_OUTPUT}" ]; then
1045
1144
cat " ${TEMP_LATEXDIFF_LOG} " >> " ${SOURCE_DIR} /${DIFFPDFLOG_OUTPUT} "
1046
1145
echo " " >> " ${SOURCE_DIR} /${DIFFPDFLOG_OUTPUT} "
1047
1146
echo " ${PDF_ENGINE} output:" >> " ${SOURCE_DIR} /${DIFFPDFLOG_OUTPUT} "
1048
- cat " ${LATEX_LOG } " >> " ${SOURCE_DIR} /${DIFFPDFLOG_OUTPUT} "
1147
+ cat " ${PDF_LOG } " >> " ${SOURCE_DIR} /${DIFFPDFLOG_OUTPUT} "
1049
1148
fi
1050
1149
fi
1051
1150
0 commit comments