summaryrefslogtreecommitdiff
path: root/macros/luatex/optex/base/lists.opm
diff options
context:
space:
mode:
Diffstat (limited to 'macros/luatex/optex/base/lists.opm')
-rw-r--r--macros/luatex/optex/base/lists.opm110
1 files changed, 110 insertions, 0 deletions
diff --git a/macros/luatex/optex/base/lists.opm b/macros/luatex/optex/base/lists.opm
new file mode 100644
index 0000000000..0b30ed43bb
--- /dev/null
+++ b/macros/luatex/optex/base/lists.opm
@@ -0,0 +1,110 @@
+%% This is part of OpTeX project, see http://petr.olsak.net/optex
+
+\_codedecl \begitems {Lists: begitems, enditems <2020-04-21>} % preloaded in format
+
+ \_doc -----------------------------
+ \`\_aboveliskip` is used above the list of items,\nl
+ \`\_belowliskip` is used below the list of items and\nl
+ \`\_interliskip` is used between items.\nl
+ \`\_listskipA` is used as `\listskipamount` at level 1 of items.\nl
+ \`\_listskipB` is used as `\listskipamount` at other levels.\nl
+ \`\_setlistskip` sets the skip dependent on the current level of items
+ \_cod -----------------------------
+
+\_def\_aboveliskip {\_removelastskip \_penalty-100 \_vskip\_listskipamount}
+\_def\_belowliskip {\_penalty-200 \_vskip\_listskipamount}
+\_def\_interliskip {}
+\_def\_listskipA {\_medskipamount}
+\_def\_listskipB {0pt plus.5\_smallskipamount}
+
+\_def\_setlistskip {%
+ \_ifnum \_ilevel = 1 \_listskipamount = \_listskipA \_relax
+ \_else \_listskipamount = \_listskipB \_relax
+ \_fi}
+
+ \_doc -----------------------------
+ The \`\itemnum` is locally reset to zero in each group declared by
+ `\begitems`. So nested lists are numbered independently. User can set
+ initial value of `\itemnum` to another value after `\beitems` if he/she want.
+ \nl
+ Each level of nested lists is indented by new `\iindent` from left.
+ Default item mark is `\_printitem`.
+ \nl
+ The \`\begitems` runs `\_aboveliskip` only if we are not near below a title,
+ where a vertical skip is placed already and where the `\penalty` 11333 is.
+ It activates `*` and defines it as \`\_startitem`.
+ \nl
+ The \`\enditems` runs `\_isnextchar\_par{}{\_noindent}` thus the next
+ paragraph is without indentation if there is no empty line between
+ the list and this paragraph (it is similar behavior as after display math).
+ \_cod -----------------------------
+
+\_newcount\_itemnum \_itemnum=0
+\_newtoks\_printitem
+
+\_def\_begitems{\_par
+ \_bgroup
+ \_advance \_ilevel by1
+ \_setlistskip
+ \_ifnum\_lastpenalty<10000 \_aboveliskip \_fi
+ \_itemnum=0 \_adef*{\_startitem}
+ \_advance\_leftskip by\_iindent
+ \_printitem=\_defaultitem
+ \_the\_everylist \_relax
+}
+\_def\_enditems{\_par\_belowliskip\_egroup \_isnextchar\_par{}{\_noindent}}
+
+\_def\_startitem{\_par \_ifnum\_itemnum>0 \_interliskip \_fi
+ \_advance\_itemnum by1
+ \_the\_everyitem \_noindent\_llap{\_the\_printitem}\_ignorespaces
+}
+\_public \begitems \enditems \itemnum ;
+
+ \_doc ----------------------------
+ \`\novspaces` sets \`\listskipamount` to 0pt.
+ \_cod ----------------------------
+
+\_def\_novspaces {\_removelastskip \_listskipamount=0pt \_relax}
+\_public \novspaces ;
+
+ \_doc -----------------------------
+ Various item marks are saved in `\_item:<letter>` macros.
+ You can re-define then or define more such macros.
+ The \`\style` `<letter>` does \`\_printitem``={\_item:<letter>}`.
+ More exactly: \^`\begitems` does `\_printitem=`\^`\defaultitem` first,
+ then \`\style` `<letter>` does \`\_printitem``={\_item:<letter>}`
+ when it is used and finally, `\_startitem` alias `*` uses `\_printitem`.
+ \_cod -----------------------------
+
+\_def\_style#1{%
+ \_ifcsname _item:#1\_endcsname \_printitem=\ea{\_csname _item:#1\_endcsname}%
+ \_else \_printitem=\_defaultitem \_fi
+}
+\_sdef{_item:o}{\_raise.4ex\_hbox{$\_scriptscriptstyle\_bullet$} }
+\_sdef{_item:-}{- }
+\_sdef{_item:n}{\_the\_itemnum. }
+\_sdef{_item:N}{\_the\_itemnum) }
+\_sdef{_item:i}{(\_romannumeral\_itemnum) }
+\_sdef{_item:I}{\_uppercase\_ea{\_romannumeral\_itemnum}\_kern.5em}
+\_sdef{_item:a}{\_athe\_itemnum) }
+\_sdef{_item:A}{\_uppercase\_ea{\_athe\_itemnum}) }
+\_sdef{_item:x}{\_raise.3ex\_fullrectangle{.6ex}\_kern.4em}
+\_sdef{_item:X}{\_raise.2ex\_fullrectangle{1ex}\_kern.5em}
+
+ \_doc -----------------------------
+ \`\_athe``{<num>}` returns the `<num>`s lowercase letter from the alphabet.\nl
+ \`\_fullrectangle``{<dimen>}` prints full rectangle with given `<dimen>`.
+ \_cod -----------------------------
+
+\_def\_fullrectangle#1{\_hbox{\_vrule height#1 width#1}}
+
+\_def\_athe#1{\_ifcase#1?\_or a\_or b\_or c\_or d\_or e\_or f\_or g\_or h\_or
+ i\_or j\_or k\_or l\_or m\_or n\_or o\_or p\_or q\_or r\_or s\_or t\_or
+ u\_or v\_or w\_or x\_or y\_or z\_else ?\_fi
+}
+\_public \style ;
+
+\_endcode % -------------------------------------
+
+2020-04-21 \isnextchar\par added to \enditems
+2020-03-18 introduced