Skip to content

Commit a2528ae

Browse files
authored
Fix builds that don't include code blocks. (#271)
If there's no code blocks, Pandoc does not inject any definition for the Shaded or Highlighting environments, and `\renewenvironment{Shaded}` fails to compile. This change gates all code-block-related definitions behind `$if(highlighting-macros)$`.
1 parent 915d49a commit a2528ae

File tree

1 file changed

+61
-51
lines changed

1 file changed

+61
-51
lines changed

template/tcg.tex

Lines changed: 61 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -82,27 +82,6 @@
8282
\EndAccSupp{}%
8383
}
8484

85-
\newcommand{\BeginCodeBlock}[1]{
86-
\vskip 3pt
87-
\begingroup
88-
89-
% The `\usepackage[none]{hyphenat}` invocation above disables hyphenation everywhere,
90-
% and breaks word-wrapping on non-space characters within code blocks. This means that
91-
% long symbol names without spaces will bleed off the edge of the page. Here we are
92-
% re-enabling hyphenation behavior for code blocks to get non-space word-wrapping to
93-
% function.
94-
\hyphenpenalty=50
95-
\exhyphenpenalty=50
96-
97-
\textbf{\textit{\textcolor{codeblock-header}{\small \BeginDemarcated{Code}}}}
98-
#1
99-
}
100-
101-
\newcommand{\EndCodeBlock}{
102-
\textbf{\textit{\textcolor{codeblock-header}{\small \EndDemarcated{Code}}}}
103-
\endgroup
104-
}
105-
10685
% Use upquote if available, for straight quotes in verbatim environments
10786
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
10887
\IfFileExists{microtype.sty}{% use microtype if available
@@ -174,6 +153,67 @@
174153
%
175154
$if(highlighting-macros)$
176155
$highlighting-macros$
156+
157+
% The following directives only apply to specs that use code blocks
158+
% and so are gated behind `if(highlighting-macros)`. In particular,
159+
% `\renewenvironment{Shaded}` fails to compile if the spec does not
160+
% include a code block, because in such cases Pandoc does not inject
161+
% the relevant definitions via `highlighting-macros`.
162+
163+
%
164+
% code block style
165+
%
166+
\definecolor{codeblock-line}{RGB}{0,0,0}
167+
\definecolor{codeblock-background}{RGB}{255,255,255}
168+
\definecolor{codeblock-header}{RGB}{35,61,130}
169+
170+
\usepackage{tcolorbox}
171+
\tcbuselibrary{breakable, skins}
172+
\tcbset{enhanced}
173+
174+
% Draws a page-breakable black box around the code block.
175+
\renewenvironment{Shaded}{
176+
\begin{tcolorbox}[
177+
breakable,
178+
arc=0pt,
179+
boxrule=1pt,
180+
colback=codeblock-background,
181+
colframe=codeblock-line,
182+
]
183+
}{
184+
\end{tcolorbox}
185+
}
186+
187+
% Allows text in the code block to break on spaces, periods, slashes, and colons.
188+
\usepackage{fvextra}
189+
\DefineVerbatimEnvironment{Highlighting}{Verbatim}{
190+
commandchars=\\\{\},
191+
breaklines,
192+
breaknonspaceingroup,
193+
breakafter=./:
194+
}
195+
196+
\newcommand{\BeginCodeBlock}[1]{
197+
\vskip 3pt
198+
\begingroup
199+
200+
% The `\usepackage[none]{hyphenat}` invocation above disables hyphenation everywhere,
201+
% and breaks word-wrapping on non-space characters within code blocks. This means that
202+
% long symbol names without spaces will bleed off the edge of the page. Here we are
203+
% re-enabling hyphenation behavior for code blocks to get non-space word-wrapping to
204+
% function.
205+
\hyphenpenalty=50
206+
\exhyphenpenalty=50
207+
208+
\textbf{\textit{\textcolor{codeblock-header}{\small \BeginDemarcated{Code}}}}
209+
#1
210+
}
211+
212+
\newcommand{\EndCodeBlock}{
213+
\textbf{\textit{\textcolor{codeblock-header}{\small \EndDemarcated{Code}}}}
214+
\endgroup
215+
}
216+
177217
$endif$
178218

179219
% https://github.com/Wandmalfarbe/pandoc-latex-template/issues/391
@@ -370,43 +410,13 @@
370410
\definecolor{table-section-background}{RGB}{224, 224, 224}
371411
\definecolor{table-section-foreground}{RGB}{10, 10, 10}
372412

373-
%
374-
% code block style
375-
%
376-
\definecolor{codeblock-line}{RGB}{0,0,0}
377-
\definecolor{codeblock-background}{RGB}{255,255,255}
378-
\definecolor{codeblock-header}{RGB}{35,61,130}
379413
\usepackage{mdframed}
380414
\newmdenv[
381415
linewidth=0pt,
382416
backgroundcolor=informative-background,
383417
skipabove=5pt,
384418
nobreak=true]{informative}
385419

386-
\usepackage{tcolorbox}
387-
\tcbuselibrary{breakable, skins}
388-
\tcbset{enhanced}
389-
390-
\renewenvironment{Shaded}{
391-
\begin{tcolorbox}[
392-
breakable,
393-
arc=0pt,
394-
boxrule=1pt,
395-
colback=codeblock-background,
396-
colframe=codeblock-line,
397-
]
398-
}{
399-
\end{tcolorbox}
400-
}
401-
402-
\usepackage{fvextra}
403-
\DefineVerbatimEnvironment{Highlighting}{Verbatim}{
404-
commandchars=\\\{\},
405-
breaklines,
406-
breaknonspaceingroup,
407-
breakafter=./:
408-
}
409-
410420
\newcommand{\hlineifmdframed}{}
411421
\newcommand{\BeginInformative}[1]{
412422
% HACK: We need to add an extra hline to the ends of tables inside of notes, because

0 commit comments

Comments
 (0)