Skip to content

Commit e8d41fe

Browse files
authored
Enable (and fix) Pandoc syntax highlighting (#243)
This change removes the --no-highlight flag from the pandoc invocation. It fixes the issue with the template that that revealed (which is that the $highlighting-styles$ magic was missing). If you are using this project with a custom LaTeX template and this change breaks with an error like "Environment Shaded undefied", then it's because your template needs this magic as well. See jgm/pandoc#7923 for more information on that. This change re-styles code blocks to use a white background instead of the light blue one, so that the kate-styled syntax highlighting looks good. Since the background is white, but the code block still needs to be a block, this change adds a 1pt black line around the code.
1 parent ed2e4a1 commit e8d41fe

File tree

5 files changed

+38
-18
lines changed

5 files changed

+38
-18
lines changed

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ RUN wget -O /usr/share/plantuml.jar https://github.com/plantuml/plantuml/release
130130
ENV PATH="/usr/local/texlive/bin/aarch64-linux:/usr/local/texlive/bin/x86_64-linux:${PATH}"
131131

132132
# Packages that are needed despite not being used explicitly by the template:
133-
# bigfoot, catchfile, fancyvrb, footmisc, hardwrap, lineno, ltablex, latexmk, needspace, pgf, zref
133+
# bigfoot, catchfile, fancyvrb, footmisc, framed, hardwrap, lineno, ltablex, latexmk, needspace, pgf, zref
134134
# Package dependencies introduced by latexdiff:
135135
# changebar, datetime2, latexdiff, listings, marginnote, pdfcomment, soulpos
136136
RUN tlmgr update --self && tlmgr install \
@@ -159,6 +159,7 @@ RUN tlmgr update --self && tlmgr install \
159159
footmisc \
160160
footnotebackref \
161161
footnotehyper \
162+
framed \
162163
fvextra \
163164
geometry \
164165
hardwrap \

build.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,11 @@ cache_generated_files() {
749749
cp_chown .cache "${SOURCE_DIR}"
750750
}
751751

752+
# This theme was chosen because it is light (like the rest of the document) and
753+
# looks reasonably nice for both programming languages (e.g., C) as well as
754+
# diff markups.
755+
SYNTAX_HIGHLIGHT_STYLE=kate
756+
752757
# Takes Markdown input and writes LaTeX output using pandoc.
753758
do_latex() {
754759
local input=$1
@@ -764,7 +769,7 @@ do_latex() {
764769
local start=$(date +%s)
765770
local cmd=(pandoc
766771
--standalone
767-
--no-highlight
772+
--highlight-style=${SYNTAX_HIGHLIGHT_STYLE}
768773
--template=${TEMPLATE_PDF}
769774
--lua-filter=convert-diagrams.lua
770775
--lua-filter=convert-aasvg.lua

filter/divide-code-blocks.lua

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,15 @@ code_classes =
1414
}
1515

1616
function CodeBlock(block)
17-
local class = block.classes[1]
18-
local class_spec = code_classes[string.lower(class or "")]
19-
if not class_spec then
20-
class_spec = code_classes["normal"]
17+
local class_spec = code_classes["normal"]
18+
for _, class in ipairs(block.classes) do
19+
local maybe_spec = code_classes[string.lower(class)]
20+
if maybe_spec then
21+
class_spec = maybe_spec
22+
break
23+
end
2124
end
25+
2226
font = class_spec["font"]
2327
return {
2428
pandoc.RawInline('latex', string.format([[

guide.tcg

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ Usage:
174174
You can specify a particular version of the docker container using the
175175
`DOCKER_IMAGE` environment variable:
176176

177-
```sh
177+
```sh {.small}
178178
DOCKER_IMAGE=ghcr.io/trustedcomputinggroup/pandoc:0.6.5 ./docker_run --pdf=output.pdf ./input.md
179179
```
180180

@@ -782,7 +782,7 @@ reimplementation, the code uses the original
782782

783783
Here is an example aasvg diagram:
784784

785-
````md
785+
````md {.small}
786786
```aasvg {caption="(v)TPM Key Management" #fig:tpm-key-management}
787787
.---------------------. .----.
788788
| Virtual Environment | | vTPM +--------------.-----------------.----------------.
@@ -1216,25 +1216,25 @@ To typeset complex equations with multi-character identifiers (such as the funct
12161216
we recommend using the functions `\mathbf` (for functions) and `\mathit` (for variables). For constants, we recommend `\mathrm`.
12171217
This avoids strange kerning issues where a string is treated as a product of single-character symbols, like in @eq:hmac-iso-bad-kerning:
12181218

1219-
```md
1220-
$$ \mathbf{HMAC}(K, \mathit{someTEXT}) \coloneq \mathbf{H}((\bar{K} \oplus \mathrm{OPAD}) \parallel \mathbf{H}((\bar{K} \oplus \mathrm{IPAD}) \parallel \mathit{someTEXT})) $$ {#eq:hmac-iso}
1219+
```md {.tiny}
1220+
$$ \mathbf{HMAC}(K, \mathit{someTEXT}) \coloneq \mathbf{H}((\bar{K} \oplus \mathrm{OPAD}) \parallel ... \parallel \mathit{someTEXT})) $$ {#eq:hmac-iso}
12211221
```
12221222

1223-
$$ \mathbf{HMAC}(K, \mathit{someTEXT}) \coloneq \mathbf{H}((\bar{K} \oplus \mathrm{OPAD}) \parallel \mathbf{H}((\bar{K} \oplus \mathrm{IPAD}) \parallel \mathit{someTEXT})) $$ {#eq:hmac-iso}
1223+
$$ \mathbf{HMAC}(K, \mathit{someTEXT}) \coloneq \mathbf{H}((\bar{K} \oplus \mathrm{OPAD}) \parallel ... \parallel \mathit{someTEXT})) $$ {#eq:hmac-iso}
12241224

1225-
```md
1225+
```md {.tiny}
12261226
$$ HMAC(K, someTEXT) \coloneq H((\bar{K} \oplus OPAD) \parallel H((\bar{K} \oplus IPAD) \parallel someTEXT)) $$ {#eq:hmac-iso-bad-kerning}
12271227
```
12281228

12291229
$$ HMAC(K, someTEXT) \coloneq H((\bar{K} \oplus OPAD) \parallel H((\bar{K} \oplus IPAD) \parallel someTEXT)) $$ {#eq:hmac-iso-bad-kerning}
12301230

12311231
You can use Unicode characters to make equations a little more readable in plain-text:
12321232

1233-
```md
1234-
$$ \mathbf{HMAC}(K, \mathit{someTEXT}) := H((\bar{K} ⊕ \mathrm{OPAD}) \parallel H((\bar{K} ⊕ \mathrm{IPAD}) \parallel \mathit{someTEXT})) $$ {#eq:hmac-unicode}
1233+
```md {.tiny}
1234+
$$ \mathbf{HMAC}(K, \mathit{someTEXT}) := H((\bar{K} ⊕ \mathrm{OPAD}) \parallel ... \parallel \mathit{someTEXT})) $$ {#eq:hmac-unicode}
12351235
```
12361236

1237-
$$ \mathbf{HMAC}(K, \mathit{someTEXT}) := \mathbf{H}((\bar{K} ⊕ \mathrm{OPAD}) \parallel \mathbf{H}((\bar{K} ⊕ \mathrm{IPAD}) \parallel \mathit{someTEXT})) $$ {#eq:hmac-unicode}
1237+
$$ \mathbf{HMAC}(K, \mathit{someTEXT}) := \mathbf{H}((\bar{K} ⊕ \mathrm{OPAD}) \parallel ... \parallel \mathit{someTEXT})) $$ {#eq:hmac-unicode}
12381238

12391239
# Advanced Features
12401240

@@ -1423,7 +1423,7 @@ Figures can be placed on landscape pages as in @fig:pdf-diagram or
14231423
![Wide Diagram](bigdiagram.pdf){#fig:pdf-diagram .landscape}
14241424
```
14251425

1426-
````md
1426+
````md {.small}
14271427
```mermaid {caption="Complicated Swimlane" #fig:landscape-swimlane width=3000 .landscape}
14281428
sequenceDiagram
14291429
Alice->>Bob: Hello

template/tcg.tex

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,14 @@
147147
\usepackage{rotating}
148148
$endif$
149149

150+
%
151+
% This is where the Haskell library skylighting will inject its definitions for the Shaded and Highlighting environments.
152+
% See also: https://github.com/jgm/pandoc/issues/7923
153+
%
154+
$if(highlighting-macros)$
155+
$highlighting-macros$
156+
$endif$
157+
150158
% https://github.com/Wandmalfarbe/pandoc-latex-template/issues/391
151159
% We don't care to scale images.
152160
\newcommand*\pandocbounded[1]{#1}
@@ -344,11 +352,13 @@
344352
%
345353
% code block style
346354
%
347-
\definecolor{codeblock-background}{RGB}{240,244,255}
355+
\definecolor{codeblock-line}{RGB}{0,0,0}
356+
\definecolor{codeblock-background}{RGB}{255,255,255}
348357
\definecolor{codeblock-header}{RGB}{35,61,130}
349358
\usepackage{mdframed}
350359
\newmdenv[
351-
linewidth=0pt,
360+
linewidth=1pt,
361+
linecolor=codeblock-line,
352362
backgroundcolor=codeblock-background,
353363
skipabove=5pt,
354364
nobreak=true]{customcodeblock}

0 commit comments

Comments
 (0)