| 1 |
%% This is part of the OpTeX project, see http://petr.olsak.net/optex |
| 2 |
|
| 3 |
\_codedecl \begitems {Lists: begitems, enditems <2023-10-20>} % preloaded in format |
| 4 |
|
| 5 |
\_doc ----------------------------- |
| 6 |
\`\_aboveliskip` is used above the list of items,\nl |
| 7 |
\`\_belowliskip` is used below the list of items,\nl |
| 8 |
\`\_setlistskip` sets the skip dependent on the current level of items,\nl |
| 9 |
\`\_listskipab` is \^`\ilistskipamount` or \^`\olistskipamount`. |
| 10 |
\_cod ----------------------------- |
| 11 |
|
| 12 |
\_def\_aboveliskip {\_removelastskip \_penalty-100 \_vskip\_listskipab} |
| 13 |
\_def\_belowliskip {\_penalty-200 \_vskip\_listskipab} |
| 14 |
\_newskip\_listskipab |
| 15 |
|
| 16 |
\_def\_setlistskip {% |
| 17 |
\_ifnum \_ilevel = 1 \_listskipab = \_olistskipamount \_relax |
| 18 |
\_else \_listskipab = \_ilistskipamount \_relax |
| 19 |
\_fi} |
| 20 |
|
| 21 |
\_doc ----------------------------- |
| 22 |
The \`\itemnum` is locally reset to zero in each group declared by |
| 23 |
`\begitems`. So nested lists are numbered independently. Users can set |
| 24 |
initial value of `\itemnum` to another value after `\beitems` if they want. |
| 25 |
\nl |
| 26 |
Each level of nested lists is indented by the new `\iindent` from left. |
| 27 |
The default item mark is `\_printitem`. |
| 28 |
\nl |
| 29 |
The \`\begitems` runs `\_aboveliskip` only if we are not near below a title, |
| 30 |
where a vertical skip is placed already and where the `\penalty` 11333 is. |
| 31 |
It activates `*` and defines it as \`\_startitem`. |
| 32 |
\nl |
| 33 |
The \`\enditems` runs `\_isnextchar\_par{}{\_noindent}` thus the next |
| 34 |
paragraph is without indentation if there is no empty line between |
| 35 |
the list and this paragraph (it is similar behavior as after display math). |
| 36 |
\_cod ----------------------------- |
| 37 |
|
| 38 |
\_newcount\_itemnum \_itemnum=0 |
| 39 |
\_newtoks\_printitem |
| 40 |
|
| 41 |
\_def\_begitems{\_par |
| 42 |
\_bgroup |
| 43 |
\_advance \_ilevel by1 |
| 44 |
\_setlistskip |
| 45 |
\_ifnum\_lastpenalty<10000 \_aboveliskip \_fi |
| 46 |
\_itemnum=0 \_adef*{\_relax\_ifmmode*\_else\_ea\_startitem\_fi} |
| 47 |
\_advance\_leftskip by\_iindent |
| 48 |
\_printitem=\_defaultitem |
| 49 |
\_the\_everylist \_relax |
| 50 |
} |
| 51 |
\_def\_enditems{\_par\_belowliskip\_egroup \_isnextchar\_par{}{\_noindent}} |
| 52 |
|
| 53 |
\_def\_startitem{\_par \_ifnum\_itemnum>0 \_vskip\_itemskipamount \_fi |
| 54 |
\_advance\_itemnum by1 |
| 55 |
\_the\_everyitem \_noindent\_llap{\_the\_printitem}\_ignorespaces |
| 56 |
} |
| 57 |
\_public \begitems \enditems \itemnum ; |
| 58 |
|
| 59 |
\_doc ---------------------------- |
| 60 |
\`\novspaces` sets \^`\_listskipab` and \^`\itemskipamount` to 0pt. |
| 61 |
Moreover, it deactivates \^`\_setlistskip` (for inner lists). |
| 62 |
\_cod ---------------------------- |
| 63 |
|
| 64 |
\_def\_novspaces {\_removelastskip |
| 65 |
\_listskipab=\_zoskip \_itemskipamount=\_zoskip \_let\_setlistskip=\_relax} |
| 66 |
\_public \novspaces ; |
| 67 |
|
| 68 |
\_doc ----------------------------- |
| 69 |
Various item marks are saved in `\_item:<letter>` macros. |
| 70 |
You can re-define then or define more such macros. |
| 71 |
The \`\style` `<letter>` does \`\_printitem``={\_item:<letter>}`. |
| 72 |
More exactly: \^`\begitems` does \^`\_printitem=`\^`\defaultitem` first, |
| 73 |
then \^`\style` `<letter>` does \^`\_printitem``={\_item:<letter>}` |
| 74 |
when it is used and finally, \^`\_startitem` alias `*` uses \^`\_printitem`. |
| 75 |
\_cod ----------------------------- |
| 76 |
|
| 77 |
\_def\_style#1{% |
| 78 |
\_ifcsname _item:#1\_endcsname \_printitem=\_ea{\_csname _item:#1\_endcsname}% |
| 79 |
\_else \_printitem=\_defaultitem \_fi |
| 80 |
} |
| 81 |
\_sdef{_item:o}{\_raise.4ex\_hbox{$\_scriptscriptstyle\_bullet$} } |
| 82 |
\_sdef{_item:-}{- } |
| 83 |
\_sdef{_item:n}{\_the\_itemnum. } |
| 84 |
\_sdef{_item:N}{\_the\_itemnum) } |
| 85 |
\_sdef{_item:i}{(\_romannumeral\_itemnum) } |
| 86 |
\_sdef{_item:I}{\_uppercase\_ea{\_romannumeral\_itemnum}\_kern.5em} |
| 87 |
\_sdef{_item:a}{\_athe\_itemnum) } |
| 88 |
\_sdef{_item:A}{\_uppercase\_ea{\_athe\_itemnum}) } |
| 89 |
\_sdef{_item:x}{\_raise.3ex\_fullrectangle{.6ex}\_kern.4em} |
| 90 |
\_sdef{_item:X}{\_raise.2ex\_fullrectangle{1ex}\_kern.5em} |
| 91 |
\_sdef{_item:d}{\_aftergroup\_dword} |
| 92 |
\_def\_dword#1#2{{\_bf #2 }\_ignorespaces} % #1 is \_ignorespaces from \_startitem |
| 93 |
|
| 94 |
\_doc ----------------------------- |
| 95 |
\`\_athe``{<num>}` returns the `<num>`s lowercase letter from the alphabet.\nl |
| 96 |
\`\_fullrectangle``{<dimen>}` prints full rectangle with given `<dimen>`. |
| 97 |
\_cod ----------------------------- |
| 98 |
|
| 99 |
\_def\_fullrectangle#1{\_hbox{\_vrule height#1 width#1}} |
| 100 |
|
| 101 |
\_def\_athe#1{\_ifcase#1?\_or a\_or b\_or c\_or d\_or e\_or f\_or g\_or h\_or |
| 102 |
i\_or j\_or k\_or l\_or m\_or n\_or o\_or p\_or q\_or r\_or s\_or t\_or |
| 103 |
u\_or v\_or w\_or x\_or y\_or z\_else ?\_fi |
| 104 |
} |
| 105 |
\_public \style ; |
| 106 |
|
| 107 |
\_doc ----------------------------- |
| 108 |
The \`\begblock` macro selects fonts from footnotes \^`\_fnset` |
| 109 |
and opens new indentation in a group. |
| 110 |
\`\endblock` closes the group. |
| 111 |
This is implemented as an counterpart |
| 112 |
of Markdown's Blockquotes. Redefine these macros if you want to declare |
| 113 |
different design. |
| 114 |
The \ulink[http://petr.olsak.net/optex/optex-tricks.html\#greyblock]{\OpTeX/ trick 0031} |
| 115 |
shows how to create blocks with grey background splittable to more pages. |
| 116 |
\_cod ----------------------------- |
| 117 |
|
| 118 |
\_def\_begblock{\_bgroup\_fnset \_medskip \_advance\_leftskip by\_iindent \_firstnoindent} |
| 119 |
\_def\_endblock{\_par\_medskip\_egroup\_isnextchar\_par{}{\_noindent}} |
| 120 |
|
| 121 |
\_public \begblock \endblock ; |
| 122 |
|
| 123 |
|
| 124 |
\_endcode % ------------------------------------- |
| 125 |
|
| 126 |
2023-10-20 \style d moved from OpTeX trick 0108 to the format |
| 127 |
2022-02-25 \olistskipamount, \ilistskipamount, \itemskipamount introduced |
| 128 |
2021-03-10 \_ifmmode*\_else\_ea\_startitem\_fi added to * definition |
| 129 |
2020-04-21 \isnextchar\par added to \enditems |
| 130 |
2020-03-18 introduced |