diff options
author | Norbert Preining <norbert@preining.info> | 2020-03-15 03:01:24 +0000 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2020-03-15 03:01:24 +0000 |
commit | 87cddce361c3b477029d13b27bdaa57190b2d74b (patch) | |
tree | 0b8f15ef416645c1438cdc4228a1ddb44691b17c /macros/luatex/optex/sections.opm | |
parent | 942e56ba7d147d18d379305e76f064cec0aade7d (diff) |
CTAN sync 202003150301
Diffstat (limited to 'macros/luatex/optex/sections.opm')
-rw-r--r-- | macros/luatex/optex/sections.opm | 355 |
1 files changed, 355 insertions, 0 deletions
diff --git a/macros/luatex/optex/sections.opm b/macros/luatex/optex/sections.opm new file mode 100644 index 0000000000..e528680d42 --- /dev/null +++ b/macros/luatex/optex/sections.opm @@ -0,0 +1,355 @@ +%% This is part of OpTeX project, see http://petr.olsak.net/optex + +\_codedecl \chap {Titles, chapters, sections, subsections <2020-03-02>} + + \_doc --------------------------- + We are using scaled fonts for titles. They are scaled from main fonts size + of the document, which is declared by first `\typosize[<fo-size>/<b-size>]` + command. + \_cod --------------------------- + +\_def \_titfont {\_scalemain\_boldify\_typoscale[\_magstep4/\_magstep5]} +\_def \_chapfont {\_scalemain\_boldify\_typoscale[\_magstep3/\_magstep3]} +\_def \_secfont {\_scalemain\_boldify\_typoscale[\_magstep2/\_magstep2]} +\_def \_seccfont {\_scalemain\_boldify\_typoscale[\_magstep1/\_magstep1]} + + \_doc --------------------------- + The `\tit` macro is defined by `\eoldef`, it means that the parameter is + separated by end of line. The macros `\chap`, `\sec` and `\secc` use + `\eoldef` too. + \_cod --------------------------- + +\_eoldef\_tit #1{\_vglue\_titskip + {\_leftskip=0pt plus1fill \_rightskip=\_leftskip % centering + \_titfont \_noindent #1\_par}% + \_nobreak\_bigskip +} +\_public \tit ; + + \_doc --------------------------- + You can re-define `\_printchap`, `\_printsec` or `\_printsecc` macros if + another design of section titles is needed. These macros gets the <title> + text in its parameter. The common recommendations for these macros are: + \begitems + * Use `\_abovetitle{<penaltyA>}{<skipA>}` and `\_belowtitle{<skipB>} + for inserting vertical material above and below the section title. + The arguments of these macros are normally used, i.e. \_abovetitle` + inserts <penaltyA><skipA> and `\_belowtitle` inserts <skipB>. + But there is an + exception: if `\_belowtitle{<skip>}` is immediately followed by next + `\_abovetitle{<penalty>}` (for example section title is immediately followed by + subsection title), then only <skipA> is generated, i.e. + <skipB><penaltyA><skipA> is reduced only to <skipA> + The reason of such behavior: we don't want to duplicate vertical skip + and we don't want to use negative penalty in such cases. + Moreower, `\_abovetitle{<penaltyA>}{<skipA>}` takes previous whatever + vertical skip (other than from `\_belowtitle`) and generates only + greater from this pair of skips. I.e. <whatever-skip><penaltyA><skipA> + is reduced to $<penaltyA>\max(<whatever-skip><skipA>)$. + The reason of such behavior: we don't want to + duplicate vertical skips (from `\_belowlistskip`, for example) above the title. + * Use `\_printrefnum[<pre>@<post>]` in horizontal mode. It prints + <pre><ref-num><post>. The <ref-num> is `\thechapnum` or `\thesecnum` + or `\theseccnum` depending on what type o title is processed. + If `\nonum` prefix is used then `\_printrefnum` prints nothing. + The macro `\_printrefnum` does more work: it creates destination of hyperlinks + (if `\hyperlinks{}{}` is used) and saves references from label (if + `\label[<label>]` precedes) and saves references for table of contents + (if `\maketoc` is used). + * Use `\nbpar` for closing the paragraph for printing title. This + command inserts `\_nobreak` between each line of such paragraph, so + the title cannot be broken to more pages. + \enditems + \_cod --------------------------- + +\_def\_printchap #1{\_vfill\_supereject + {\_chapfont \_noindent \_mtext{chap} \_printrefnum[@]\_par + \_nobreak\_smallskip + \_noindent \_raggedright #1\_nbpar}\_mark{}% + \_nobreak \_belowtitle{\_medskip}% + \_firstnoindent +} +\_def\_printsec#1{\_par + \_abovetitle{\_penalty-400}\_bigskip + {\_secfont \_noindent \_raggedright \_printrefnum[@\_quad]#1\_nbpar}\_insertmark{#1}% + \_nobreak \_belowtitle{\_medskip}% + \_firstnoindent +} +\_def\_printsecc#1{\_par + \_abovetitle{\_penalty-200}\_medskip + {\_seccfont \_noindent \_raggedright \_printrefnum[@\_quad]#1\_nbpar}% + \_nobreak \_belowtitle{\_medskip}% + \_firstnoindent +} + + \_doc -------------------------- + The `\_sectionlevel` is the level of the printed section: + \begitems + * `\_sectionlevel=0` -- reserved for parts of the book (unused by default) + * `\_sectionlevel=1` -- chapters (used in `\chap`) + * `\_sectionlevel=2` -- sections (used in `\sec`) + * `\_sectionlevel=3` -- subsections (used in `\secc`) + * `\_sectionlevel=4` -- subsubsections (unused by default) + \enditems + \_cod -------------------------- + +\_newcount\_sectionlevel +\_def \_secinfo {\_ifcase \_sectionlevel + part\_or chap\_or sec\_or secc\_or seccc\_fi +} + + \_doc -------------------------- + The `\_chapx` initializes counters used in chapters, + the `\_secx` initializes counters in sections + and `\_seccx` initializes counters in subsections. + If you have another concept of numbering objects used in your + document, you can re-define these macros. All settings here are global + because it is used by `{\_globaldefs=1 \_chapx}`. + + Default concept: Tables, figuers and display maths are numbered + from one in each section -- subsetions doesn't reset these counters. + + The `\_the*` macros includes the format of numbers used when the object + is printing. If chapter is never used in the document then `\_chapnum=0` + and `\_othe\_chapnum.` expands to empty. Sections have numbers <num> and + subsections <num>.<num>. On the other hand, if chapter is used in the + document then `\_chapnum>0` and sections have numbers <num>.<num> + and subsections have numbers <num>.<num>.<num>. + + If you have more types of numbered objects in your document then you can + declare appropriate counters and do `\addto\_chapx{\yourcounter=0 }` + for example. + \_cod -------------------------- + +\_newcount \_chapnum % chapters +\_newcount \_secnum % sections +\_newcount \_seccnum % subsections +\_newcount \_tnum % table numbers +\_newcount \_fnum % figure numbers +\_newcount \_dnum % numbered display maths + +\_def \_chapx {\_incr\_chapnum \_secnum=0 \_seccnum=0 \_tnum=0 \_fnum=0 \_dnum=0 \_lfnotenum=0 } +\_def \_secx {\_incr\_secnum \_seccnum=0 \_tnum=0 \_fnum=0 \_dnum=0 } +\_def \_seccx {\_incr\_seccnum } + +\_def \_thechapnum {\_the\_chapnum} +\_def \_thesecnum {\_othe\_chapnum.\_the\_secnum} +\_def \_theseccnum {\_othe\_chapnum.\_the\_secnum.\_the\_seccnum} +\_def \_thetnum {\_othe\_chapnum.\_the\_secnum.\_the\_tnum} +\_def \_thefnum {\_othe\_chapnum.\_the\_secnum.\_the\_fnum} +\_def \_thednum {(\_the\_dnum)} + +\_def\_othe #1.{\_ifnum#1>0 \_the#1.\_fi} +\_def\_incr #1{\_global\_advance#1by1 } + + \_doc ---------------------------- + The `\notoc` and `\nonum` prefixes are implemented by + internal `\_ifnotoc` and `\_ifnonum`. + \_cod ---------------------------- + +\_newifi \_ifnotoc \_notocfalse \_def\_notoc {\_global\_notoctrue} +\_newifi \_ifnonum \_nonumfalse \_def\_nonum {\_global\_nonumtrue} +\_def \_resetnonumnotoc{\_global\_notocfalse \_global\_nonumfalse} +\_public \notoc \nonum ; + + \_doc ---------------------------- + The `\chap`, `\sec` and `\secc` macros are implemnted here. + The `\_inchap`, `\_insec` and `\_insecc` macros does the real work, + First, we read the optional parameter `[<label>]`, if it exists. + \_cod ---------------------------- + +\_optdef\_chap[]{\_trylabel \_inchap} +\_optdef\_sec []{\_trylabel \_insec} +\_optdef\_secc[]{\_trylabel \_insecc} +\_def\_trylabel{\_istoksempty\_opt\_iffalse \_label[\_the\_opt]\_fi} + +\_eoldef\_inchap #1{\_par \_sectionlevel=1 + \_def \_savedtitle {#1}% saved to .ref file + \_ifnonum \_else {\_globaldefs=1 \_chapx}\_fi + \_edef \_therefnum {\_ifnonum \_space \_else \_thechapnum \_fi}% + \_printchap{#1}% + \_resetnonumnotoc +} +\_eoldef\_insec #1{\_par \_sectionlevel=2 + \_def \_savedtitle {#1}% saved to .ref file + \_ifnonum \_else {\_globaldefs=1 \_secx}\_fi + \_edef \_therefnum {\_ifnonum \_space \_else \_thesecnum \_fi}% + \_printsec{#1}% + \_resetnonumnotoc +} +\_eoldef\_insecc #1{\_par \_sectionlevel=3 + \_def \_savedtitle {#1}% saved to .ref file + \_ifnonum \_else {\_globaldefs=1 \_seccx}\_fi + \_edef \_therefnum {\_ifnonum \_space \_else \_theseccnum \_fi}% + \_printsecc{#1}% + \_resetnonumnotoc +} +\_public \chap \sec \secc ; + + \_doc ---------------------------- + The `\_printrefnum[<pre>@<post>]` macro is used in `\_print*` macros. + The `\_wtotoc {<level>}{<info>}{<ref-num>}{<title-text>}` + macro expands its parameters and does `\_wref`. + + Note that the <tite-text> is `\detokenize`d before `\wref`, so the + problem of \"fragile macros" from old \LaTeX/ never occurrs. + \_cod ---------------------------- + +\_def \_printrefnum [#1@#2]{\_leavevmode % we must be in horizontal mode + \_ifnonum \_else #1\_therefnum #2\_fi + \_wlabel \_therefnum % references, if `\label[<label>]` is declared + \_ifnotoc \_else \_incr \_tocrefnum + \_dest[toc:\_the\_tocrefnum]% + \_wtotoc{\_the\_sectionlevel}{\_secinfo}% + {\_therefnum}{\_detokenize\_ea{\_savedtitle}}% + \_fi +} +\_def \_wtotoc #1#2#3#4{\_edef\_tmp{{#1}{#2}{#3}{#4}}\_ea\_wtotocA\_tmp} +\_def \_wtotocA #1#2#3#4{\_wref\_Xtoc{{#1}{#2}{#3}{#4}}} + + \_doc ----------------------------- + The `\_abovetitle{<penaltyA>}{<skipA>}` and `\_belowtitle{<skipB>}` pair + communicates using a special penalty 11333 in vertical mode. + The `\_belowtitle` puts the vertical skip (its value is saved in + `\_savedtitleskip`) followed by this special penalty. + The `\_abovetitle` reads `\lastpenalty` and if it has this special value + then it removes the skip used before and dont use the parameter. + The `\abovetitle` creates <skipA> only if whatever previous skip is less + or equal than <skipA>. We must save <whatever-skip>, remove it, + create <penaltyA> (if belowtitle does not preceded) and create + <whatever-skip> or <skipA> depending on what is greater. + The amount of <skipA> is measured using `\setbox0=\vbox`. + \_cod ----------------------------- + +\_newskip \_savedtitleskip +\_newskip \_savedlastskip +\_def\_abovetitle #1#2{\_savedlastskip=\_lastskip % <whatever-skip> + \_ifdim\_lastskip>0pt \_vskip-\_lastskip \_fi + \_ifnum\_lastpenalty=11333 \_vskip-\_savedtitleskip \_else #1\_fi + \_ifdim\_savedlastskip>0pt \_setbox0=\_vbox{#2\_global\_tmpdim=\_lastskip}% + \_else \_tmpdim=\_maxdimen \_fi + \_ifdim\_savedlastskip>\_tmpdim \vskip\_savedlastskip \_else #2\_fi +} +\_def\_belowtitle #1{#1\_global\_savedtitleskip=\_lastskip \_penalty11333 } + + \_doc ----------------------------- + `\nbpar` sets `\interlinepenaty` value. + `\nl` is \"new line" in text (or titles), but space in toc or healdlines or outlines. + \_cod ----------------------------- + +\_def\_nbpar{{\_interlinepenalty=10000\_endgraf}} + +\_protected\def\_nl{\hfil\break} +\_regmacro {\def\_nl{\_unskip\_space}} {\def\_nl{\_unskip\_space}} {\def\_nl{ }} +\_regmacro {\def\nl{\_unskip\_space}} {\def\nl{\_unskip\_space}} {\def\nl{ }} + +\_public \nbpar \nl ; + + \_doc ----------------------------- + `\_firstnoindent` puts a material to `\everypar` in order to next + paragraph will be without indentation. It is useful after titles. + If you dislike this feature then you can say `\let\_firtnoindent=\relax`. + The `\_wipeepar` removes the material from `\everypar`. + \_cod ----------------------------- + +\_def \_afternoindent {\_global\_everypar={\_wipeepar \_setbox7=\_lastbox}} +\_def \_wipeepar {\_global\_everypar={}} +\_let \_firstnoindent=\_afternoindent + + \_doc ----------------------------- + The `\mark` (for running heads) is used in `\_printsection` only. We + suppose that chapters will be printed after `\vfil\break`, so user can + implement chapter titles for running headers directly by macros, no + `\mark` machanism is needed. But sections need `\mark`s. And they can be + mixed with chapter's running heads, of course. + + The `\_insermark{<title text>}` saves `\mark` in the format + `{<title-num>} {<title-text>}`, so it can be printed \"as is" in + `\headline` (see the space between them), or you can define a formating + macro with two parameters for processing these data, if you need it. + \_cod ----------------------------- + +\_def\_insertmark#1{\_mark{{\_ifnonum\_else\_therefnum\_fi} {\_unexpanded{#1}}}} + + \_doc ----------------------------- + \OpTeX/ sets `\headline={}` by default, so no running heads are printed. + You can activate the running heads by following code, for example: + \begtt + \addto \_chapx {\_edef\_runningchap {\_thechapnum: \_unexpanded\_ea{\_savedtitle}}} + \def \formathead #1#2{\isempty{#1}\iffalse #1: #2\fi} + \headline = {% + \ifodd \pageno + \hfil \ea\formathead\firstmark{}{}% + \else + Chapter: \runningchap \hfil + \fi + } + \endtt + + The `\caption/<letter>` uses `\_<letter>num` counter. + The group opened by `\caption` is finalized by first \par from + empty line or from `\vskip` or from `\endinsert`. + The `\_printcaption<letter>` is called, it starts with + printing of the caption. + \_cod ----------------------------- + +\_def\_caption/#1{\_def\_tmpa{#1}\_nospaceafter \_capA} +\_optdef\_capA []{\_trylabel \_incaption} +\_def\_incaption {\_bgroup + \_ifcsname _\_tmpa num\_endcsname \_ea\_incr \_csname _\_tmpa num\_endcsname + \_else \_opwarning{Unknown caption /\_tmpa}\_fi + \_edef\_thecapnum {\csname _the\_tmpa num\endcsname}% + \_edef\_thecaptitle{\_mtext{\_tmpa}}% + \_ifcsname _everycaption\_tmpa\_endcsname + \_ea\_the \_csname _everycaption\_tmpa\_endcsname \_fi + \_def\_par{\_nbpar\_egroup}\_let\par=\_par + \_cs{_printcaption\_tmpa}% +} + + \_doc ----------------------------- + The `\_printcaption<letter>` macro starts in vertical mode. It must + switch to horizontal mode, it must use `\_wlabel\_thecapnum` (in order to + make reference and hyperlink destination) a it can use: + \begitems + * `\_thecaptitle` ... expands to the word Table or Figure (depending on + the current language). + * `\_thecapnum` ... expands to `\the<letter>num` (caption number). + \enditems + \_cod ----------------------------- + +\_def \_printcaptiont {% + \_noindent \_wlabel\_thecapnum {\_bf\_thecaptitle~\_thecapnum}\_enspace + \_narrowlastlinecentered\_iindent +} +\_let \_printcaptionf = \_printcaptiont % caption of figures = caption of tables +\_def \_cskip {\_par\_nobreak\_medskip} % space between caption and the object + +\_public \caption \cskip ; + + \_doc ----------------------------- + The default format of `\caption` text is paragraph in block narrower by + `\_iindent` and with the last line is centered. This setting is done by + `\_narrowlastlinecentered` macro. + \_cod ----------------------------- + +\_def\_narrowlastlinecentered#1{% + \_leftskip=#1plus1fil + \_rightskip=#1plus-1fil + \_parfillskip=0pt plus2fil +} + + \_doc ----------------------------- + `\eqmark` is processed in display mode (we add `\eqno` primitive) + or in internal mode when `\eqaligno` is used (we don't add `\eqno`). + \_cod ----------------------------- + +\_optdef\_eqmark []{\_trylabel \_ineqmark} +\_def\_ineqmark{\_incr\_dnum + \_ifinner\_else\_eqno \_fi + \_wlabel\_thednum \_thednum +} +\_public \eqmark ; + +\_endcode % ------------------------------------- + + |