summaryrefslogtreecommitdiff
path: root/macros/luatex/optex/maketoc.opm
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2020-02-27 03:01:13 +0000
committerNorbert Preining <norbert@preining.info>2020-02-27 03:01:13 +0000
commitcfcab0823d16bb9acd6d6a7d3f80a7b2176a6260 (patch)
tree4db3d6f79edb6570d6c812c4962a4322c0605534 /macros/luatex/optex/maketoc.opm
parent2dfd6df5d1db270dc874c6c319d51eed43defb91 (diff)
CTAN sync 202002270301
Diffstat (limited to 'macros/luatex/optex/maketoc.opm')
-rw-r--r--macros/luatex/optex/maketoc.opm92
1 files changed, 92 insertions, 0 deletions
diff --git a/macros/luatex/optex/maketoc.opm b/macros/luatex/optex/maketoc.opm
new file mode 100644
index 0000000000..05df7d0d64
--- /dev/null
+++ b/macros/luatex/optex/maketoc.opm
@@ -0,0 +1,92 @@
+%% This is part of OpTeX project, see http://petr.olsak.net/optex
+
+\_codedecl \maketoc {maketoc <2020-02-14>}
+
+\_def\_toclist{}
+\_newifi \_ifischap \_ischapfalse
+
+\def\_Xtoc#1#2#3#4{\_ifnum#1=0 \_ischaptrue\_fi
+ \_addto\_toclist{\_tocline{#1}{#2}{#3}{#4}}
+ \_ea\_addto\_ea\_toclist\_ea{\_currpage}%
+}
+\def\_tocline#1#2#3#4#5#6{\_bgroup
+ \_leftskip=\_iindent \_rightskip=2\_iindent
+ \_ifischap \_advance\_leftskip by \_iindent \_fi
+ \_def\_pg{\_ilink[pg:#5]}%
+ \_pretocline \_the\_tochook
+ \_ifcsname _tocl:#1\_endcsname
+ \_cs{_tocl:#1}{#3}{#4}{#6}\_nobreak \_hskip-2\_iindent\_null \_par
+ \_fi
+ \_egroup
+ \_advance\_tocrefnum by1
+}
+\_sdef{_tocl:1}#1#2#3{\_nofirst\_bigskip \_bf\_llaptoclink{#1}{#2}\_hfill \_pg{#3}}
+\_sdef{_tocl:2}#1#2#3{\_llaptoclink{#1}{#2}\_tocdotfill \_pg{#3}}
+\_sdef{_tocl:3}#1#2#3{\_advance\_leftskip by\_iindent \_cs{_tocl:2}{#1}{#2}{#3}}
+
+\_def\_llaptoclink#1{\_noindent \_llap{\_ilink[toc:\_the\_tocrefnum]{#1\enspace}}}
+\_def\_tocdotfill{\_leaders\_hbox to.8em{\_hss.\_hss}\_hskip 1em plus1fill\_relax}
+\_def\_nofirst #1{\_ifnum \_lastpenalty=11333 \_else #1\_fi}
+
+\_def\_pretocline{}
+
+\_def\_maketoc{\_par \_ifx\_toclist\_empty
+ \_opwarning{\_noexpand\maketoc -- data unavailable, TeX me again}\_openref
+ \_else \_begingroup \_tocrefnum=0 \_penalty11333 \_toclist \_endgroup \_fi}
+
+\_newtoks \_tochook
+
+\_public \maketoc \tochook ;
+
+\_endcode % -------------------------------------
+
+`\_Xtoc{<level>}{<type>}{<number>}{<text>}` reads the specified
+data from REF file and saves it to `\_toclist` as
+
+\begtt
+\_tocline{<level>}{<type>}{<number>}{<text>}{<gpageno>}{<pageno>}
+where:
+<level>: 0 reserved, 1: chapter, 2: section, 3: subsection
+<type>: the type of the level, i.e. chap, sec, secc (unused)
+<number>: the number of the chapret/section/subsection in the format 1.2.3
+<text>: the title text
+<gpageno>: the page number numbered from 1 independently of pagination
+<pageno>: the page number used in the pagination
+\endtt
+
+The last two parameters are restored from previous
+`\_Xpage{<pageno>}{<gpageno>}`, data are saved in the `\_currpage` macro.
+
+`\_tocline{<level>}{<type>}{<number>}{<text>}{<gpageno>}{<pageno>}` prints
+the record to the table of contents. It opens group, reduces `\_leftskip`,
+`\_rightskip`, runs the `\tochook` (user can customise the design o TOC
+here) and runs `\_tocl:<level> {<number>}{<text>}{<page>}` macro.
+This macro starts with vertical mode,
+inserts one record with given <level> and ends in horizontal mode. Then
+`\_tocline` appends `\_nobreak \_hskip-2\_iindent\_null \_par`. This causes
+that the last line of the record is shifted outside the margin given by
+`\_rightskip`. A typical record (with long <text>) looks like:
+
+\begtt
+ | |
+\llap{<number>} text text text text text
+ text text text text text
+ text text .................... <pageno>
+\endtt
+
+Margins given by `\leftskip` and `\rightskip` are denoted by `|` in the
+examle above.
+
+You can re-define default macros for each level if you want.
+
+`\_llaptoclink<text>` does `\_noindent\_llap{<linked text>}`.
+
+`\_tocdotfill` creates dots in the TOC.
+
+`\_nofirst\macro` applies the `\macro` only if we don't print the first
+record of the TOC.
+
+`\_pg{<pageno>}` creates <pageno> as link to real <gpage> saved in `#6`.
+
+`\maketoc` prints warning if TOC data is empty, lse it creates TOC by
+running `\_toclist`