Skip to content

Commit 1d706bb

Browse files
committed
Add manual PDF index
Update the options passed to pandoc and run it twice with `makeindex` in between. Add a Lua filter that passes through `\index` within HTML comments so that we can custom add our index entries. It would be nice to be able to use these index entries in the lunr.js search results as well, but that will have to wait.
1 parent 44e90fe commit 1d706bb

File tree

4 files changed

+62
-1
lines changed

4 files changed

+62
-1
lines changed

.github/workflows/build_pdf.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
push:
55
branches:
66
- main
7+
- fix_index
78
workflow_dispatch:
89

910
jobs:

docs/soar_manual/build.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,35 @@ pandoc \
2020
--listings \
2121
--number-sections \
2222
--lua-filter=docs/soar_manual/path_filter.lua \
23+
--lua-filter=docs/soar_manual/index_filter.lua \
2324
-V geometry:"left=3cm, top=2.5cm, right=3cm, bottom=3cm" \
25+
-V has-index \
26+
docs/soar_manual/01_Introduction.md \
27+
docs/soar_manual/02_TheSoarArchitecture.md \
28+
docs/soar_manual/03_SyntaxOfSoarPrograms.md \
29+
docs/soar_manual/04_ProceduralKnowledgeLearning.md \
30+
docs/soar_manual/05_ReinforcementLearning.md \
31+
docs/soar_manual/06_SemanticMemory.md \
32+
docs/soar_manual/07_EpisodicMemory.md \
33+
docs/soar_manual/08_SpatialVisualSystem.md \
34+
docs/soar_manual/09_SoarUserInterface.md \
35+
output/cli.tex \
36+
-o output/SoarManual.pdf
37+
38+
# Run makeindex to generate the index file
39+
cd output && makeindex SoarManual.idx && cd ..
40+
41+
# Run pandoc again to include the index in the final PDF
42+
pandoc \
43+
--pdf-engine=lualatex \
44+
--resource-path=docs/soar_manual/ \
45+
--template=docs/soar_manual/template.tex \
46+
--listings \
47+
--number-sections \
48+
--lua-filter=docs/soar_manual/path_filter.lua \
49+
--lua-filter=docs/soar_manual/index_filter.lua \
50+
-V geometry:"left=3cm, top=2.5cm, right=3cm, bottom=3cm" \
51+
-V has-index \
2452
docs/soar_manual/01_Introduction.md \
2553
docs/soar_manual/02_TheSoarArchitecture.md \
2654
docs/soar_manual/03_SyntaxOfSoarPrograms.md \

docs/soar_manual/index_filter.lua

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
-- Pandoc Lua filter to extract LaTeX index commands from HTML comments
2+
-- This allows index entries to be hidden from MkDocs while being processed for PDF output
3+
4+
function extractIndexFromComments(elem)
5+
if elem.tag == "RawInline" and elem.format == "html" then
6+
local comment = elem.text
7+
-- Match HTML comments containing \index commands
8+
local index_cmd = comment:match("<!%-%-.-\\index{(.-)}.-->")
9+
if index_cmd then
10+
-- Return LaTeX raw inline instead of HTML comment
11+
return pandoc.RawInline("latex", "\\index{" .. index_cmd .. "}")
12+
end
13+
-- Match full \index{...} commands in comments
14+
local full_index = comment:match("<!%-%-.-(\\\index{.-}).--->")
15+
if full_index then
16+
return pandoc.RawInline("latex", full_index)
17+
end
18+
end
19+
return elem
20+
end
21+
22+
return {
23+
{
24+
RawInline = extractIndexFromComments
25+
}
26+
}

docs/soar_manual/template.tex

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
% soar version information
2424
\newcommand{\SoarVersionMajor}{9}
2525
\newcommand{\SoarVersionMinor}{6}
26-
\newcommand{\SoarVersionRevision}{1}
26+
\newcommand{\SoarVersionRevision}{4}
2727

2828
$if(linestretch)$
2929
\usepackage{setspace}
@@ -435,6 +435,9 @@
435435
$endif$
436436
437437
\begin{document}
438+
$if(has-index)$
439+
\makeindex
440+
$endif$
438441
\begin{titlepage}
439442
\vspace{1.5in}
440443
@@ -558,4 +561,7 @@
558561
$include-after$
559562
560563
$endfor$
564+
$if(has-index)$
565+
\printindex
566+
$endif$
561567
\end{document}

0 commit comments

Comments
 (0)