Skip to content

Commit f99a3b9

Browse files
authored
Allow code blocks to customize their font size. (#224)
1 parent ba24599 commit f99a3b9

File tree

3 files changed

+66
-12
lines changed

3 files changed

+66
-12
lines changed

filter/divide-code-blocks.lua

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,32 @@
11
-- draw horizontal rules above and below code blocks to separate them nicely
22

3+
code_classes =
4+
{
5+
["normal"] = {
6+
["font"] = "\\small",
7+
},
8+
["small"] = {
9+
["font"] = "\\scriptsize",
10+
},
11+
["tiny"] = {
12+
["font"] = "\\tiny",
13+
},
14+
}
15+
316
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"]
21+
end
22+
font = class_spec["font"]
423
return {
5-
pandoc.RawInline('latex', [[
6-
\vskip 3pt%
24+
pandoc.RawInline('latex', string.format([[
25+
\vskip 3pt
726
\begin{customcodeblock}
827
\textbf{\textit{\textcolor{codeblock-header}{\small \BeginDemarcated{Code}}}}
9-
]]),
28+
%s
29+
]], font)),
1030
block,
1131
pandoc.RawInline('latex', [[
1232
\textbf{\textit{\textcolor{codeblock-header}{\small \EndDemarcated{Code}}}}

guide.tcg

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,49 @@ The result looks like this:
428428
int i = 42;
429429
```
430430

431+
You can customize the font size, in case code runs off the edge of the page and can't be word-wrapped:
432+
433+
````md
434+
``` {.small}
435+
{
436+
"Foo": {
437+
"Bar": {
438+
"Baz":
439+
"/some/very/long/string/that/can't/be/word/wrapped/e.g./because/it's/encoded/in/json",
440+
}
441+
}
442+
}
443+
```
444+
````
445+
446+
The result looks like this:
447+
448+
``` {.small}
449+
{
450+
"Foo": {
451+
"Bar": {
452+
"Baz":
453+
"/some/very/long/string/that/can't/be/word/wrapped/e.g./because/it's/encoded/in/json",
454+
}
455+
}
456+
}
457+
```
458+
459+
You can use `.normal`, `.small`, or `.tiny` (illustrated below):
460+
461+
``` {.tiny}
462+
{
463+
"Foo": {
464+
"Bar": {
465+
"Baz":
466+
"/some/very/long/string/that/can't/be/word/wrapped/e.g./because/it's/encoded/in/json",
467+
}
468+
}
469+
}
470+
```
471+
472+
The default case is `.normal`.
473+
431474
## Footnotes {#sec:footnotes}
432475

433476
```md

template/tcg.tex

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -164,15 +164,6 @@
164164
% }
165165
% \makeatother
166166

167-
% Make all verbatim environments use \small font.
168-
\usepackage{etoolbox}
169-
\makeatletter
170-
\patchcmd{\@verbatim}
171-
{\verbatim@font}
172-
{\verbatim@font\small}
173-
{}{}
174-
\makeatother
175-
176167
% Left-justify the document.
177168
\usepackage[document]{ragged2e}
178169
\RaggedRight{}

0 commit comments

Comments
 (0)