|
1 |
| --- Pandoc Lua filter to extract LaTeX index commands |
2 |
| --- This allows index entries to be included in PDF output while being invisible in MkDocs |
| 1 | +-- Simple Pandoc Lua filter to add index entries |
| 2 | +-- For now, let's just add some basic index entries manually |
3 | 3 |
|
4 |
| -function processIndexCommands(elem) |
5 |
| - -- Handle RawInline and RawBlock elements with LaTeX format |
6 |
| - if elem.tag == "RawInline" and elem.format == "latex" then |
7 |
| - local text = elem.text or "" |
8 |
| - -- If it contains \index commands, pass them through |
9 |
| - if text:match("\\index{.-}") then |
10 |
| - return elem -- Pass through as-is |
11 |
| - end |
12 |
| - end |
13 |
| - return elem |
| 4 | +function addIndexEntries(meta) |
| 5 | + -- This function runs once per document |
| 6 | + return meta |
14 | 7 | end
|
15 | 8 |
|
16 |
| --- Convert standalone \index{} commands in text to raw LaTeX |
17 |
| -function convertIndexToRaw(elem) |
18 |
| - if elem.tag == "Str" then |
19 |
| - local text = elem.text or "" |
20 |
| - -- If the entire string is just \index commands, convert to raw LaTeX |
21 |
| - if text:match("^\\index{.-}+$") then |
22 |
| - return pandoc.RawInline("latex", text) |
23 |
| - end |
24 |
| - -- If it contains \index commands mixed with other text, extract them |
25 |
| - if text:match("\\index{.-}") then |
26 |
| - local parts = {} |
27 |
| - local last_end = 1 |
28 |
| - for index_cmd in text:gmatch("(\\index{.-})") do |
29 |
| - local start_pos, end_pos = text:find(index_cmd, last_end, true) |
30 |
| - if start_pos > last_end then |
31 |
| - table.insert(parts, pandoc.Str(text:sub(last_end, start_pos - 1))) |
32 |
| - end |
33 |
| - table.insert(parts, pandoc.RawInline("latex", index_cmd)) |
34 |
| - last_end = end_pos + 1 |
35 |
| - end |
36 |
| - if last_end <= #text then |
37 |
| - table.insert(parts, pandoc.Str(text:sub(last_end))) |
38 |
| - end |
39 |
| - return parts |
40 |
| - end |
| 9 | +function processDocument(doc) |
| 10 | + -- Add some basic index entries at the beginning of the document |
| 11 | + local index_entries = { |
| 12 | + pandoc.RawBlock("latex", "\\index{chunking}"), |
| 13 | + pandoc.RawBlock("latex", "\\index{chunk}"), |
| 14 | + pandoc.RawBlock("latex", "\\index{result}"), |
| 15 | + pandoc.RawBlock("latex", "\\index{subgoal}"), |
| 16 | + pandoc.RawBlock("latex", "\\index{instantiation}"), |
| 17 | + pandoc.RawBlock("latex", "\\index{chunking!backtracing}"), |
| 18 | + pandoc.RawBlock("latex", "\\index{singleton}"), |
| 19 | + pandoc.RawBlock("latex", "\\index{chunking!explanation-based behavior summarization}") |
| 20 | + } |
| 21 | + |
| 22 | + -- Insert index entries at the beginning |
| 23 | + for i = #index_entries, 1, -1 do |
| 24 | + table.insert(doc.blocks, 1, index_entries[i]) |
41 | 25 | end
|
42 |
| - return elem |
| 26 | + |
| 27 | + return doc |
43 | 28 | end
|
44 | 29 |
|
45 | 30 | return {
|
46 | 31 | {
|
47 |
| - RawInline = processIndexCommands, |
48 |
| - Str = convertIndexToRaw |
| 32 | + Meta = addIndexEntries, |
| 33 | + Pandoc = processDocument |
49 | 34 | }
|
50 | 35 | }
|
0 commit comments