| 1 |
%% This is part of the OpTeX project, see http://petr.olsak.net/optex |
| 2 |
|
| 3 |
\_codedecl \chap {Titles, chapters, sections, subsections <2026-03-15>} % preloaded in format |
| 4 |
|
| 5 |
\_doc --------------------------- |
| 6 |
We are using scaled fonts for titles |
| 7 |
\`\_titfont`, \`\_chapfont`, \`\_secfont` and \`\_seccfont`. |
| 8 |
They are scaled from main fonts size |
| 9 |
of the document, which is declared by first `\typosize[<fo-size>/<b-size>]` |
| 10 |
command. |
| 11 |
\_cod --------------------------- |
| 12 |
|
| 13 |
\_def \_titfont {\_scalemain\_typoscale[\_magstep4/\_magstep5]\_boldify} |
| 14 |
\_def \_chapfont {\_scalemain\_typoscale[\_magstep3/\_magstep3]\_boldify} |
| 15 |
\_def \_secfont {\_scalemain\_typoscale[\_magstep2/\_magstep2]\_boldify} |
| 16 |
\_def \_seccfont {\_scalemain\_typoscale[\_magstep1/\_magstep1]\_boldify} |
| 17 |
|
| 18 |
\_doc --------------------------- |
| 19 |
The \`\tit` macro is defined using \^`\scantoeol` and \`\_printtit`. |
| 20 |
It means that the parameter is |
| 21 |
separated by end of line and inline verbatim is allowed. The same |
| 22 |
principle is used in the \^`\chap`, \^`\sec`, and \^`\secc` macros. |
| 23 |
\_cod --------------------------- |
| 24 |
|
| 25 |
\_def\_printtit #1{\_vglue\_titskip |
| 26 |
{\_leftskip=0pt plus1fill \_rightskip=\_leftskip % centering |
| 27 |
\_titfont \_noindent \_scantextokens{#1}\_par}% |
| 28 |
\_nobreak\_bigskip |
| 29 |
} |
| 30 |
\_def\_tit{\_scantoeol\_printtit} |
| 31 |
\_sdef{_eol:tit}{\_printtit} % enables \bracedparam\tit{title} |
| 32 |
|
| 33 |
\_public \tit ; |
| 34 |
|
| 35 |
\_doc --------------------------- |
| 36 |
You can re-define \`\_printchap`, \`\_printsec` or \`\_printsecc` macros if |
| 37 |
another design of section titles is needed. These macros get the |
| 38 |
`<title>` text in its parameter. The common recommendations for these macros are: |
| 39 |
\begitems |
| 40 |
* Use \^`\_abovetitle``{<penaltyA>}{<skipA>}` and \^`\_belowtitle``{<skipB>}` |
| 41 |
for inserting vertical material above and below the section title. |
| 42 |
The arguments of these macros are normally used, i.\,e.\ \^`\_abovetitle` |
| 43 |
inserts `<penaltyA><skipA>` and \^`\_belowtitle` inserts `<skipB>`. |
| 44 |
But there is an |
| 45 |
exception: if \^`\_belowtitle``{<skipB>}` is immediately followed by |
| 46 |
\^`\_abovetitle``{<penaltyA>}{<skipA>}` (for example section title is |
| 47 |
immediately followed by subsection title), then only `<skipA>` is generated, |
| 48 |
i.\,e.\ `<skipB><penaltyA><skipA>` is reduced only to `<skipA>`. |
| 49 |
The reason for such behavior: we don't want to duplicate vertical skip |
| 50 |
and we don't want to use the negative penalty in such cases. |
| 51 |
Moreover, \^`\_abovetitle``{<penaltyA>}{<skipA>}` takes previous whatever |
| 52 |
vertical skip (other than from `\_belowtitle`) and generates only |
| 53 |
greater from this pair of skips. It means that `<whatever-skip><penaltyA><skipA>` |
| 54 |
is transformed to `<penaltyA>`max(`<whatever-skip><skipA>`). |
| 55 |
The reason for such behavior: we don't want to |
| 56 |
duplicate vertical skips (from `\_belowlistskip`, for example) above the title. |
| 57 |
* Use \^`\_printrefnum``[<pre>@<post>]` in horizontal mode. It prints |
| 58 |
`<pre><ref-num><post>`. The `<ref-num>` is \^`\_thechapnum` or \^`\_thesecnum` |
| 59 |
or \^`\_theseccnum` depending on what type o title is processed. |
| 60 |
If \^`\nonum` prefix is used then \^`\_printrefnum` prints nothing. |
| 61 |
The macro \^`\_printrefnum` does more work: it creates destination of hyperlinks |
| 62 |
(if \^`\hyperlinks``{}{}` is used) and saves references from the label (if |
| 63 |
\^`\label``[<label>]` precedes) and saves references for the table of contents |
| 64 |
(if \^`\maketoc` is used). |
| 65 |
* Use \^`\nbpar` for closing the paragraph for printing title. This |
| 66 |
command inserts `\_nobreak` between each line of such paragraph, so |
| 67 |
the title cannot be broken into more pages. |
| 68 |
* You can use \^`\_firstnoindent` in order to the first paragraph after |
| 69 |
the title is not indented. |
| 70 |
\enditems |
| 71 |
\_cod --------------------------- |
| 72 |
|
| 73 |
\_def\_printchap #1{\_vfill\_supereject \_prevdepth=0pt |
| 74 |
\_vglue\_medskipamount % shifted by topkip+\medskipamount |
| 75 |
{\_chapfont \_noindent \_mtext{chap} \_printrefnum[@]\_par |
| 76 |
\_nobreak\_smallskip |
| 77 |
\_noindent \_raggedright #1\_nbpar}\_mark{}% |
| 78 |
\_nobreak \_belowtitle{\_bigskip}% |
| 79 |
\_firstnoindent |
| 80 |
} |
| 81 |
\_def\_printsec#1{\_par |
| 82 |
\_abovetitle{\_penalty-151}\_bigskip |
| 83 |
{\_secfont \_noindent \_raggedright \_printrefnum[@\_quad]#1\_nbpar}\_insertmark{#1}% |
| 84 |
\_nobreak \_belowtitle{\_medskip}% |
| 85 |
\_firstnoindent |
| 86 |
} |
| 87 |
\_def\_printsecc#1{\_par |
| 88 |
\_abovetitle{\_penalty-101}{\_medskip\_smallskip} |
| 89 |
{\_seccfont \_noindent \_raggedright \_printrefnum[@\_quad]#1\_nbpar}% |
| 90 |
\_nobreak \_belowtitle{\_medskip}% |
| 91 |
\_firstnoindent |
| 92 |
} |
| 93 |
|
| 94 |
\_doc -------------------------- |
| 95 |
The \`\_sectionlevel` is the level of the printed section: |
| 96 |
\begitems |
| 97 |
* `\_sectionlevel=0` -- reserved for parts of the book (unused by default) |
| 98 |
* `\_sectionlevel=1` -- chapters (used in `\chap`) |
| 99 |
* `\_sectionlevel=2` -- sections (used in `\sec`) |
| 100 |
* `\_sectionlevel=3` -- subsections (used in `\secc`) |
| 101 |
* `\_sectionlevel=4` -- subsubsections (unused by default, see the |
| 102 |
\ulink[http://petr.olsak.net/optex/optex-tricks.html\#seccc]{\OpTeX/ trick 0033}) |
| 103 |
\enditems |
| 104 |
\_cod -------------------------- |
| 105 |
|
| 106 |
\_newcount\_sectionlevel |
| 107 |
\_def \_secinfo {\_ifcase \_sectionlevel |
| 108 |
part\_or chap\_or sec\_or secc\_or seccc\_fi |
| 109 |
} |
| 110 |
|
| 111 |
\_doc -------------------------- |
| 112 |
The \`\_chapx` initializes counters used in chapters, |
| 113 |
the \`\_secx` initializes counters in sections |
| 114 |
and \`\_seccx` initializes counters in subsections. |
| 115 |
If you have more types of numbered objects in your document then you can |
| 116 |
declare appropriate counters and do `\addto\_chapx{\yourcounter=0 }` |
| 117 |
for example. If you have another concept of numbering objects used in your |
| 118 |
document, you can re-define these macros. All settings here are global |
| 119 |
because it is used by `{\_globaldefs=1 \_chapx}`. |
| 120 |
|
| 121 |
Default concept: Tables, figures, and display maths are numbered |
| 122 |
from one in each section -- subsections don't reset these counters. |
| 123 |
Footnotes declared by \^`\fnotenumchapters` are numbered in each chapter |
| 124 |
from one. |
| 125 |
|
| 126 |
The `\_the*` macros |
| 127 |
\`\_thechapnum`, \`\_thesecnum`, \`\_theseccnum`, |
| 128 |
\`\_thetnum`, \`\_thefnum` and \`\_thednum` |
| 129 |
include the format of numbers used when the object |
| 130 |
is printing. If chapter is never used in the document then `\_chapnum=0` |
| 131 |
and \`\_othe``\_chapnum.` expands to empty. Sections have numbers <num> and |
| 132 |
subsections <num>.<num>. On the other hand, if chapter is used in the |
| 133 |
document then `\_chapnum>0` and sections have numbers` <num>.<num>` |
| 134 |
and subsections have numbers `<num>.<num>.<num>`. |
| 135 |
\_cod -------------------------- |
| 136 |
|
| 137 |
\_newcount \_chapnum % chapters |
| 138 |
\_newcount \_secnum % sections |
| 139 |
\_newcount \_seccnum % subsections |
| 140 |
\_newcount \_tnum % table numbers |
| 141 |
\_newcount \_fnum % figure numbers |
| 142 |
\_newcount \_dnum % numbered display maths |
| 143 |
|
| 144 |
\_def \_chapx {\_secx \_secnum=0 \_lfnotenum=0 } |
| 145 |
\_def \_secx {\_seccx \_seccnum=0 \_tnum=0 \_fnum=0 \_dnum=0 \_resetABCDE } |
| 146 |
\_def \_seccx {} |
| 147 |
|
| 148 |
\_def \_thechapnum {\_the\_chapnum} |
| 149 |
\_def \_thesecnum {\_othe\_chapnum.\_the\_secnum} |
| 150 |
\_def \_theseccnum {\_othe\_chapnum.\_the\_secnum.\_the\_seccnum} |
| 151 |
\_def \_thetnum {\_othe\_chapnum.\_othe\_secnum.\_the\_tnum} |
| 152 |
\_def \_thefnum {\_othe\_chapnum.\_othe\_secnum.\_the\_fnum} |
| 153 |
\_def \_thednum {(\_the\_dnum)} |
| 154 |
|
| 155 |
\_def\_othe #1.{\_ifnum#1>0 \_the#1.\_fi} |
| 156 |
|
| 157 |
\_doc ---------------------------- |
| 158 |
The \`\notoc` and \`\nonum` prefixes are implemented by |
| 159 |
internal \`\_ifnotoc` and \`\_ifnonum`. They are reset |
| 160 |
after each chapter/section/subsection by the \`\_resetnonumnotoc` macro. |
| 161 |
\_cod ---------------------------- |
| 162 |
|
| 163 |
\_newifi \_ifnotoc \_notocfalse \_def\_notoc {\_global\_notoctrue} |
| 164 |
\_newifi \_ifnonum \_nonumfalse \_def\_nonum {\_global\_nonumtrue} |
| 165 |
\_def \_resetnonumnotoc{\_global\_notocfalse \_global\_nonumfalse} |
| 166 |
\_public \notoc \nonum ; |
| 167 |
|
| 168 |
\_doc ---------------------------- |
| 169 |
The \`\chap`, \`\sec`, and \`\secc` macros are implemented here. |
| 170 |
The \`\_inchap`, \`\_insec` and \`\_insecc` macros do the real work, |
| 171 |
First, we read the optional parameter `[<label>]`, if it exists. |
| 172 |
The `\chap`, `\sec` and `\secc` macro reads its parameter using |
| 173 |
\^`\scantoeol`. This causes that they cannot be used inside other macros. |
| 174 |
Use \^`\_inchap`, \^`\_insec`, and \^`\_insecc` macros directly in such case. |
| 175 |
Because the first token of the title parameter is tokenized already (due to |
| 176 |
\^`\optdef`), we have to use `\_scantoeolX` instead \^`\scantoeol`. This |
| 177 |
solves the problem `\sec {text}`. |
| 178 |
\_cod ---------------------------- |
| 179 |
|
| 180 |
\_optdef\_chap[]{\_trylabel \_scantoeolX\_inchap} |
| 181 |
\_optdef\_sec []{\_trylabel \_scantoeolX\_insec} |
| 182 |
\_optdef\_secc[]{\_trylabel \_scantoeolX\_insecc} |
| 183 |
\_def\_trylabel{\_istoksempty\_opt\_iffalse \_label[\_the\_opt]\_fi} |
| 184 |
\_def\_scantoeolX#1{\_isnextchar\_bgroup{\_ea\_scantoeol\_ea#1\_string}{\_scantoeol#1}} |
| 185 |
|
| 186 |
\_sdef{_eol:chap}{\_inchap} % enables \bracedparam\chap{title} |
| 187 |
\_sdef{_eol:sec}{\_insec} % enables \bracedparam\sec{title} |
| 188 |
\_sdef{_eol:secc}{\_insecc} % enables \bracedparam\secc{title} |
| 189 |
|
| 190 |
\_def\_inchap #1{\_par \_sectionlevel=1 |
| 191 |
\_def \_savedtitle {#1}% saved to .ref file |
| 192 |
\_ifnonum \_else {\_globaldefs=1 \_incr\_chapnum \_chapx}\_fi |
| 193 |
\_edef \_therefnum {\_ifnonum \_space \_else \_thechapnum \_fi}% |
| 194 |
\_printchap{\_scantextokens{#1}}% |
| 195 |
\_resetnonumnotoc |
| 196 |
} |
| 197 |
\_def\_insec #1{\_par \_sectionlevel=2 |
| 198 |
\_def \_savedtitle {#1}% saved to .ref file |
| 199 |
\_ifnonum \_else {\_globaldefs=1 \_incr\_secnum \_secx}\_fi |
| 200 |
\_edef \_therefnum {\_ifnonum \_space \_else \_thesecnum \_fi}% |
| 201 |
\_printsec{\_scantextokens{#1}}% |
| 202 |
\_resetnonumnotoc |
| 203 |
} |
| 204 |
\_def\_insecc #1{\_par \_sectionlevel=3 |
| 205 |
\_def \_savedtitle {#1}% saved to .ref file |
| 206 |
\_ifnonum \_else {\_globaldefs=1 \_incr\_seccnum \_seccx}\_fi |
| 207 |
\_edef \_therefnum {\_ifnonum \_space \_else \_theseccnum \_fi}% |
| 208 |
\_printsecc{\_scantextokens{#1}}% |
| 209 |
\_resetnonumnotoc |
| 210 |
} |
| 211 |
\_public \chap \sec \secc ; |
| 212 |
|
| 213 |
\_doc ---------------------------- |
| 214 |
The \`\_printrefnum``[<pre>@<post>]` macro is used in `\_print*` macros. |
| 215 |
|
| 216 |
Note that the `<tite-text>` is `\detokenize`d before `\_wref`, so the |
| 217 |
problem of \"fragile macros" from old \LaTeX/ never occurs. |
| 218 |
This fourth parameter is not delimited by `{...}` but by end of line. |
| 219 |
This gives possibility to have unbalanced braces in inline verbatim in titles. |
| 220 |
\_cod ---------------------------- |
| 221 |
|
| 222 |
\_def \_printrefnum [#1@#2]{\_leavevmode % we must be in horizontal mode |
| 223 |
\_ifnonum \_else #1\_numprint\_therefnum #2\_fi |
| 224 |
\_wlabel \_therefnum % references, if `\label[<label>]` is declared |
| 225 |
\_ifnotoc \_else \_incr \_tocrefnum |
| 226 |
\_dest[toc:\_the\_tocrefnum]% |
| 227 |
\_ewref\_Xtoc{{\_the\_sectionlevel}{\_secinfo}% |
| 228 |
{\_therefnum}{\_theoutline}\_detokenize\_ea{\_savedtitle}}% |
| 229 |
\_fi |
| 230 |
\_gdef\_theoutline{}% |
| 231 |
} |
| 232 |
|
| 233 |
\_doc ----------------------------- |
| 234 |
\`\thisoutline``{<text>}` saves text to the \`\_theoutline` macro. |
| 235 |
\^`\_printrefnum` uses it and removes it. |
| 236 |
\_cod ----------------------------- |
| 237 |
|
| 238 |
\_def\_theoutline{} |
| 239 |
\_def\_thisoutline#1{\_gdef\_theoutline{#1}} |
| 240 |
\_public \thisoutline ; |
| 241 |
|
| 242 |
\_doc ----------------------------- |
| 243 |
The \`\_abovetitle``{<penaltyA>}{<skipA>}` and \`\_belowtitle``{<skipB>}` pair |
| 244 |
communicates using a special penalty 11333 in vertical mode. |
| 245 |
The `\_belowtitle` puts the vertical skip (its value is saved in |
| 246 |
`\_savedtitleskip`) followed by this special penalty. |
| 247 |
The `\_abovetitle` reads `\lastpenalty` and if it has this special value |
| 248 |
then it removes the skip used before and doesn't use the parameter. |
| 249 |
The `\abovetitle` creates `<skipA>` only if whatever previous skip is less |
| 250 |
or equal than `<skipA>`. We must save `<whatever-skip>`, remove it, |
| 251 |
create `<penaltyA>` (if `\_belowtitle` does not precede) and create |
| 252 |
<whatever-skip> or `<skipA>` depending on what is greater. |
| 253 |
The amount of `<skipA>` is measured using `\setbox0=\vbox`. |
| 254 |
\_cod ----------------------------- |
| 255 |
|
| 256 |
\_newskip \_savedtitleskip |
| 257 |
\_newskip \_savedlastskip |
| 258 |
\_def\_abovetitle #1#2{\_savedlastskip=\_lastskip % <whatever-skip> |
| 259 |
\_ifdim\_lastskip>\_zo \_vskip-\_lastskip \_fi |
| 260 |
\_ifnum\_lastpenalty=11333 \_vskip-\_savedtitleskip \_else #1\_fi |
| 261 |
\_ifdim\_savedlastskip>\_zo \_setbox0=\_vbox{#2\_global\_tmpdim=\_lastskip}% |
| 262 |
\_else \_tmpdim=\_maxdimen \_fi |
| 263 |
\_ifdim\_savedlastskip>\_tmpdim \vskip\_savedlastskip \_else #2\_fi |
| 264 |
} |
| 265 |
\_def\_belowtitle #1{#1\_global\_savedtitleskip=\_lastskip \_penalty11333 } |
| 266 |
|
| 267 |
\_doc ----------------------------- |
| 268 |
\`\nbpar` sets `\interlinepenaty` value. |
| 269 |
\`\nl` is \"new line" in the text (or titles), but space in toc or headlines or outlines. |
| 270 |
\_cod ----------------------------- |
| 271 |
|
| 272 |
\_def\_nbpar{{\_interlinepenalty=10000\_endgraf}} |
| 273 |
|
| 274 |
\_protected\_def\_nl{\_unskip\_hfil\_break} |
| 275 |
\_regmacro {\_def\_nl{\_unskip\_space}} {\_def\_nl{\_unskip\_space}} {\_def\_nl{ }} |
| 276 |
\_regmacro {\_def\nl{\_unskip\_space}} {\_def\nl{\_unskip\_space}} {\_def\nl{ }} |
| 277 |
|
| 278 |
\_public \nbpar \nl ; |
| 279 |
|
| 280 |
\_doc ----------------------------- |
| 281 |
\`\_firstnoindent` puts a material to `\everypar` in order to next |
| 282 |
paragraph will be without indentation. It is useful after titles. |
| 283 |
If you dislike this feature then you can say `\let\_firtnoindent=\relax`. |
| 284 |
The \`\_wipeepar` removes the material from `\everypar`. |
| 285 |
\_cod ----------------------------- |
| 286 |
|
| 287 |
\_def \_firstnoindent {\_global\_everypar={\_wipeepar \_setbox7=\_lastbox}} |
| 288 |
\_def \_wipeepar {\_global\_everypar={}} |
| 289 |
|
| 290 |
\_doc ----------------------------- |
| 291 |
The `\mark` (for running heads) is used in `\_printsection` only. We |
| 292 |
suppose that chapters will be printed after `\vfil\break`, so users can |
| 293 |
implement chapter titles for running headers directly by macros, no |
| 294 |
`\mark` mechanism is needed. But sections need `\mark`s. And they can be |
| 295 |
mixed with chapter's running heads, of course. |
| 296 |
|
| 297 |
The \`\_insertmark``{<title text>}` saves `\mark` in the format |
| 298 |
`{<title-num>} {<title-text>}`, so it can be printed \"as is" in |
| 299 |
`\headline` (see the space between them), or you can define a formatting |
| 300 |
macro with two parameters for processing these data, if you need it. |
| 301 |
\_cod ----------------------------- |
| 302 |
|
| 303 |
\_def\_insertmark#1{\_mark{{\_ifnonum\_else\_therefnum\_fi} {\_unexpanded{#1}}}} |
| 304 |
|
| 305 |
\_doc ----------------------------- |
| 306 |
\OpTeX/ sets `\headline={}` by default, so no running headings are printed. |
| 307 |
You can activate the running headings by following code, for example. |
| 308 |
See also \ulink[https://github.com/olsak/OpTeX/issues/100]{issue 100}. |
| 309 |
\begtt |
| 310 |
\addto\_chapx {\globaldefs=0 \vfil\break % headline of previous chapter is printed |
| 311 |
\xdef\_runningchap {\_thechapnum: \unexpanded\_ea{\_savedtitle}}} |
| 312 |
\def \formathead #1#2{\isempty{#1}\iffalse #1: #2\fi} |
| 313 |
\headline = {% |
| 314 |
\ifodd \pageno |
| 315 |
\hfil \ea\formathead\firstmark{}{}% |
| 316 |
\else |
| 317 |
\ifx\_runningchap\_undefined \else Chapter \_runningchap \fi \hfil |
| 318 |
\fi |
| 319 |
} |
| 320 |
\endtt |
| 321 |
|
| 322 |
The \`\secl``<number> <title-text><eol>` |
| 323 |
should be used for various levels of sections (for example, when |
| 324 |
converting from Markdown to \OpTeX/). `\secl1` is `\chap`, `\secl2` is `\sec`, |
| 325 |
`\secl3` is `\secc` and all more levels (for <number>$>3$) |
| 326 |
are printed by the common \`\_seclp` macro. It declares only a simple design. |
| 327 |
If there is a requirement to use such more levels then the book designer can |
| 328 |
define something different here.\nl |
| 329 |
The variant `\_eol:secl` is defined to enable \^`\bracedparam``\secl<number> {<title-text>}`. |
| 330 |
\_cod ----------------------------- |
| 331 |
|
| 332 |
\_def\_secl{\_let\_secle=\_ea \_afterassignment\_secla \_sectionlevel=} |
| 333 |
\_sdef{_eol:secl}{\_def\_secle{\_ea\_bracedparam\_ea}\_afterassignment\_secla \_sectionlevel=} |
| 334 |
\_def\_secla{\_ifcase\_sectionlevel |
| 335 |
\_or \_secle\_chap \_or \_secle\_sec \_or \_secle\_secc \_else \_ea \_seclp\_fi} |
| 336 |
\_eoldef\_seclp#1{\_par \_ifnum\_lastpenalty=0 \_removelastskip\_medskip\_fi |
| 337 |
\_noindent{\_bf #1}\_vadjust{\_nobreak}\_nl\_ignorepars} |
| 338 |
\_def\_ignorepars{\_isnextchar\_par{\_ignoresecond\_ignorepars}{}} |
| 339 |
|
| 340 |
\_public \secl ; |
| 341 |
|
| 342 |
\_doc ----------------------------- |
| 343 |
The \`\caption``/<letter>` increases `\_<letter>num` counter, |
| 344 |
edefines \`\_thecapnum` as `\_the<letter>num` and |
| 345 |
defines \`\_thecaptitle` as language-dependent word using \^`\_mtext`, |
| 346 |
declares default format by \^`\_captionformat``{<letter>}` and |
| 347 |
runs the `\_everycaption<letter>` tokens register. |
| 348 |
The two groups opened by `\caption` are finalized by first `\_par` from |
| 349 |
an empty line or from `\vskip`, `\cskip` or from `\endinsert`. |
| 350 |
If a \code{\}} occurs first then `\_par` from `\aftergroup` is processed. |
| 351 |
The `\_printcaption<letter>` is called, it starts with |
| 352 |
printing of the caption.\nl |
| 353 |
The \`\cskip` macro inserts nonbreakable vertical space between the caption and |
| 354 |
the object. |
| 355 |
\_cod ----------------------------- |
| 356 |
|
| 357 |
\_def\_caption/#1{\_def\_tmpa{#1}\_nospaceafter \_capA} |
| 358 |
\_optdef\_capA []{\_trylabel \_incaption} |
| 359 |
\_def\_incaption {\_bgroup |
| 360 |
\_ifcsname _\_tmpa num\_endcsname \_ea\_incr \_csname _\_tmpa num\_endcsname |
| 361 |
\_else \_opwarning{Unknown caption /\_tmpa}\_fi |
| 362 |
\_edef\_thecapnum {\_csname _the\_tmpa num\_endcsname}% |
| 363 |
\_edef\_thecaptitle{\_mtext{\_tmpa}}% |
| 364 |
\_ea\_captionformat\_ea{\_tmpa}% |
| 365 |
\_ea\_the \_csname _everycaption\_tmpa\_endcsname |
| 366 |
\_def\_par{\_ifhmode\_nbpar\_egroup\_egroup\_fi}% |
| 367 |
\_ifx\par\_endgraf \_let\par=\_par \_fi |
| 368 |
\_bgroup \_aftergroup\_par |
| 369 |
\_cs{_printcaption\_tmpa}% |
| 370 |
} |
| 371 |
\_def \_cskip {\_par\_nobreak\_medskip} % space between caption and the object |
| 372 |
|
| 373 |
\_public \caption \cskip ; |
| 374 |
|
| 375 |
\_doc ----------------------------- |
| 376 |
The \`\_printcaptiont` and \`\_printcaptionf` macros start in vertical mode. |
| 377 |
They switch to horizontal mode and use `\_wlabel\_thecapnum` (in order to |
| 378 |
make reference and hyperlink destination). They can use: |
| 379 |
\begitems |
| 380 |
* \^`\_thecaptitle` ... expands to the word Table or Figure (depending on |
| 381 |
the current language). |
| 382 |
* \^`\_thecapnum` ... expands to `\the<letter>num` (caption number). |
| 383 |
\enditems |
| 384 |
The macro \^`\_printcaptiont` (or `f`) is processed inside group and the |
| 385 |
`\_par` can be run after this group. If you want to re-define formatting |
| 386 |
parameters for `\_par`, do this in the macro \^`\_captionformat`. |
| 387 |
The \`\_captionsep` inserts a separator between auto-generated |
| 388 |
caption number and the following caption text. Default separator |
| 389 |
is `\_enspace` but if the caption text starts with dot or colon, then |
| 390 |
the space is not inserted. A user can write `\caption/t: My table` |
| 391 |
and \"{\bf Table 1.1:} My table" is printed. You can re-define |
| 392 |
the \^`\_captionsep` macro if you want to use another separator. |
| 393 |
\_cod ----------------------------- |
| 394 |
|
| 395 |
\_def \_printcaptiont {% |
| 396 |
\_noindent \_wlabel\_thecapnum {\_bf\_thecaptitle~\_thecapnum}% |
| 397 |
\_futurelet\_next\_captionsep |
| 398 |
} |
| 399 |
\_def\_captionsep{\_ifx\_next.\_ea\_bfnext \_else\_ifx\_next:\_ea\_ea\_ea\_bfnext |
| 400 |
\_else \_enspace \_fi\_fi} |
| 401 |
\_def\_bfnext#1{{\_bf#1}} |
| 402 |
\_let \_printcaptionf = \_printcaptiont % caption of figures = caption of tables |
| 403 |
|
| 404 |
\_doc ----------------------------- |
| 405 |
If you want to declare a new type of `\caption` with independent counter, |
| 406 |
you can use following lines, where `\caption/a` for Algorithms are |
| 407 |
declared: |
| 408 |
\begtt |
| 409 |
\let\_printcaptiona = \_printcaptionf \let\_everycaptiona = \_everycaptionf |
| 410 |
\newcount\_anum \addto\_secx {\_anum=0 } |
| 411 |
\def\_theanum {\_othe\_chapnum.\_the\_secnum.\_the\_anum} |
| 412 |
\sdef{_mt:a:en}{Algorithm} \sdef{_mt:a:cs}{Algoritmus} % + your language... |
| 413 |
\endtt |
| 414 |
The format of the \^`\caption` text is given by the |
| 415 |
\`\_captionformat``{<caption-letter>}` macro. |
| 416 |
The default format for `t` and `f` is a paragraph in block narrower by |
| 417 |
`\_iindent` and with the last line is centered. This setting is done by |
| 418 |
the \`\_narrowlastlinecentered` macro. |
| 419 |
\_cod ----------------------------- |
| 420 |
|
| 421 |
\_def\_captionformat#1{\_narrowlastlinecentered\_iindent} |
| 422 |
\_def\_narrowlastlinecentered#1{% |
| 423 |
\_leftskip=#1plus1fil |
| 424 |
\_rightskip=#1plus-1fil |
| 425 |
\_parfillskip=0pt plus2fil\_relax |
| 426 |
} |
| 427 |
|
| 428 |
\_doc ----------------------------- |
| 429 |
\`\eqmark` is processed in display mode (we add `\eqno` primitive) |
| 430 |
or in internal mode when `\eqaligno` is used (we don't add `\eqno`). |
| 431 |
\_cod ----------------------------- |
| 432 |
|
| 433 |
\_optdef\_eqmark []{\_trylabel \_ineqmark} |
| 434 |
\_def\_ineqmark{\_incr\_dnum |
| 435 |
\_ifinner\_else\_eqno \_fi |
| 436 |
\_wlabel\_thednum \_hbox{\_numprint\_thednum}% |
| 437 |
} |
| 438 |
\_public \eqmark ; |
| 439 |
|
| 440 |
\_doc ----------------------------- |
| 441 |
The \`\numberedpar` `<letter>{<name>}` is implemented here. |
| 442 |
\_cod ----------------------------- |
| 443 |
|
| 444 |
\_newcount\_counterA \_newcount\_counterB \_newcount\_counterC |
| 445 |
\_newcount\_counterD \_newcount\_counterE |
| 446 |
|
| 447 |
\_def\_resetABCDE {\_counterA=0 \_counterB=0 \_counterC=0 \_counterD=0 \_counterE=0 } |
| 448 |
|
| 449 |
\_def \_theAnum {\_othe\_chapnum.\_othe\_secnum.\_the\_counterA} |
| 450 |
\_def \_theBnum {\_othe\_chapnum.\_othe\_secnum.\_the\_counterB} |
| 451 |
\_def \_theCnum {\_othe\_chapnum.\_othe\_secnum.\_the\_counterC} |
| 452 |
\_def \_theDnum {\_othe\_chapnum.\_othe\_secnum.\_the\_counterD} |
| 453 |
\_def \_theEnum {\_othe\_chapnum.\_othe\_secnum.\_the\_counterE} |
| 454 |
|
| 455 |
\_def\_numberedpar#1#2{\_ea \_incr \_csname _counter#1\_endcsname |
| 456 |
\_def\_tmpa{#1}\_def\_tmpb{#2}\_numberedparparam} |
| 457 |
\_optdef\_numberedparparam[]{% |
| 458 |
\_ea \_printnumberedpar \_csname _the\_tmpa num\_ea\_endcsname\_ea{\_tmpb}} |
| 459 |
|
| 460 |
\_public \numberedpar ; |
| 461 |
|
| 462 |
\_doc ----------------------------- |
| 463 |
The \`\_printnumberedpar` `\theXnum {<name>}` opens numbered paragraph and |
| 464 |
prints it. The optional parameter is in `\_the\_opt`. You can re-define |
| 465 |
it if you need another design. |
| 466 |
|
| 467 |
`\_printnumberedpar` needs not to be re-defined if you only want to print |
| 468 |
Theorems in italic and to insert vertical skips (for example). You can do this |
| 469 |
by the following code: |
| 470 |
\begtt |
| 471 |
\def\theorem {\medskip\bgroup\it \numberedpar A{Theorem}} |
| 472 |
\def\endtheorem {\par\egroup\medskip} |
| 473 |
|
| 474 |
\theorem Let $M$ be... \endtheorem |
| 475 |
\endtt |
| 476 |
\_cod ----------------------------- |
| 477 |
|
| 478 |
\_def \_printnumberedpar #1#2{\_par |
| 479 |
\_noindent\_wlabel #1% |
| 480 |
{\_bf #2 \_numprint{#1}\_istoksempty\_opt\_iffalse \_space \_the\_opt \_fi.}\_space |
| 481 |
\_ignorespaces |
| 482 |
} |
| 483 |
|
| 484 |
\_endcode % ------------------------------------- |
| 485 |
|
| 486 |
2026-03-15 \_scantoeolX introduced: bug fix of the case `\sec {text}` |
| 487 |
2024-01-19 \bracedparam\secl enabled |
| 488 |
2024-01-18 \tit, \chap, \sec, \secc: added cooperation with new \bracedparam |
| 489 |
2023-05-02 \_numprint used |
| 490 |
2022-10-19 More robust \caption (two opened groups, \_printcaption introduced) |
| 491 |
2022-08-02 Penalties in \_printsec, \_printsecc changed |
| 492 |
2022-07-11 \_printchap: \_prevdepth=0pt added, see issue 100 |
| 493 |
2021-03-03 \_captionsep introduced, \_othe used in \_thetnum, \_thefnum. |
| 494 |
2021-02-09 \thisoutline implemented |
| 495 |
2021-01-26 \_nl: \unskip added |
| 496 |
2021-01-11 \secl introduced |
| 497 |
2021-01-05 \_thednum printed in text mode in its both occurrences. |
| 498 |
2020-04-28 \_secfonts etc: \_boldify is last. |
| 499 |
2020-04-22 \_chapx, \_secx, \_seccx rewritten |
| 500 |
2020-03-14 introduced |