summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/optex/base/lists.opm
blob: 57b057d6c8c2c16a19dca930e33b4a5578ddccef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
%% This is part of the OpTeX project, see http://petr.olsak.net/optex

\_codedecl \begitems {Lists: begitems, enditems <2021-03-10>} % 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. Users can set
   initial value of `\itemnum` to another value after `\beitems` if they want.
   \nl
   Each level of nested lists is indented by the new `\iindent` from left.
   The 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*{\_relax\_ifmmode*\_else\_ea\_startitem\_fi}
  \_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 ;

   \_doc -----------------------------
   The \`\begblock` macro selects fonts from footnotes \^`\_fnset`
   and opens new indentation in a group.
   \`\endblock` closes the group.
   This is implemented as an counterpart
   of Markdown's Blockquotes. Redefine these macros if you want to declare
   different design.
   The \ulink[http://petr.olsak.net/optex/optex-tricks.html\#greyblock]{\OpTeX/ trick 0031}
   shows how to create blocks with grey background splittable to more pages.
   \_cod -----------------------------

\_def\_begblock{\_bgroup\_fnset \_medskip \_advance\_leftskip by\_iindent \_firstnoindent}
\_def\_endblock{\_par\_medskip\_egroup\_isnextchar\_par{}{\_noindent}}

\_public \begblock \endblock ;


\_endcode % -------------------------------------

2021-03-10 \_ifmmode*\_else\_ea\_startitem\_fi added to * defintition
2020-04-21 \isnextchar\par added to \enditems
2020-03-18 introduced