Debian Codegraph @

texmf-dist/tex/optex/base/basic-macros.opm

raw
1 %% This is part of the OpTeX project, see http://petr.olsak.net/optex
2
3 \_codedecl \sdef {Basic macros for OpTeX <2026-04-14>} % preloaded in format
4
5 \_doc ------------------------------
6 \`\bgroup`, \`\egroup`, \`\empty`, \`\space`, and \`\null`
7 are classical macros from plain \TeX/.
8 \_cod ------------------------------
9
10 \_let\_bgroup={ \_let\_egroup=}
11 \_def \_empty {}
12 \_def \_space { }
13 \_def \_null {\_hbox{}}
14 \_public \bgroup \egroup \empty \space \null ;
15
16 \_doc ------------------------------
17 \`\ignoreit` ignores next token or `{<text>}`,
18 \`\useit``{<text>}` expands to `<text>` (removes outer braces),
19 \`\ignoresecond` uses first, ignores second parameter and
20 \`\usesecond` ignores first, uses second parameter.
21 \_cod ------------------------------
22
23 \_long\_def \_ignoreit #1{}
24 \_long\_def \_useit #1{#1}
25 \_long\_def \_ignoresecond #1#2{#1}
26 \_long\_def \_usesecond #1#2{#2}
27 \_public \ignoreit \useit \ignoresecond \usesecond ;
28
29 \_doc ------------------------------
30 \`\bslash` is \"normal backslash" with category code 12.
31 \`\nbb` is double backslash
32 and \`\pcent` is normal~`%`.
33 They can be used in Lua codes, for example.
34 \_cod ------------------------------
35
36 \_edef \_bslash {\_csstring\\}
37 \_edef \_nbb {\_bslash\_bslash}
38 \_edef \_pcent{\_csstring\%}
39 \_public \bslash \nbb \pcent ;
40
41 \_doc ------------------------------
42 \`\sdef` `{<text>}` is equivalent to `\def\<text>`, where `\<text>` is a control
43 sequence. You can use arbitrary parameter mask after `\sdef{<text>}`, don't
44 put the (unwanted) space immediately after closing brace \code{\}}.
45 \nl
46 \`\sxdef` `{<text>}` is equivalent to `\xdef\<text>`.
47 \nl
48 \`\slet` `{<textA>}{<textB>}` is equivalent to `\let \<textA> = \<textB>`.
49 \_cod ------------------------------
50
51 \_def \_sdef #1{\_ea\_def \_csname#1\_endcsname}
52 \_def \_sxdef #1{\_ea\_xdef \_csname#1\_endcsname}
53 \_def \_slet #1#2{\_ea\_let \_csname#1\_ea\_endcsname
54 \_ifcsname#2\_ea\_endcsname \_begincsname#2\_endcsname \_else \_undefined \_fi
55 }
56 \_public \sdef \sxdef \slet ;
57
58 \_doc ------------------------------
59 \`\adef` `<char>{<body>}` defines active `<char>` as <body> and then
60 puts the <char> as active character. I.e. the `<body>` can include the
61 <char> as non-active charter (if it is non-active before `\adef`).
62 For example `\adef ?{\,?}`.
63 If the character is special, you can escape it, for example `\adef\%{...}`.
64 The space can be declared by `\adef{ }{<body>}`.
65 You can declare a macro with parameters too, for example
66 `\adef @#1{...#1...}`. You can use prefixes `\protected`, `\global`,
67 `\long` before `\adef`, they behave like prefixes before `\def`.\nl
68 \`\mathadef` `<char>{<body>}` defines active `<char>` only in math mode.
69 The catcode of the <char> is kept.
70 \_cod ------------------------------
71
72 \_def\_adef#1#2#{\_adefA{#1}{#2}}
73 \_def\_adefA#1#2#3{\_ea\_def\_directlua{tex.cprint(13,"\_luaescapestring{\_csstring#1}")}#2{#3}%
74 \_catcode`#1=13 }
75 \_def\_mathadef#1{\_mathcode`#1="8000 \_bgroup \_lccode`~=`#1 \_lowercase{\_egroup \_def~}}
76 \_public \adef \mathadef ;
77
78 \_doc ------------------------------
79 \`\cs` `{<text>}` is only a shortcut to `\csname <text>\endcsname`, but you need
80 one more `\_ea` if you need to get the real control sequence `\<text>`.
81 \nl
82 \`\trycs` `{<csname>}{<text>}` expands to `\<csname>`
83 if it is defined else to the `<text>`.
84 \_cod ------------------------------
85
86 \_def \_cs #1{\_csname#1\_endcsname}
87 \_def \_trycs#1#2{\_ifcsname #1\_endcsname \_csname #1\_ea\_endcsname \_else \_afterfi{#2}\_fi}
88 \_public \cs \trycs ;
89
90 \_doc ------------------------------
91 \`\addto` `\macro{<text>}` adds `<text>` to your `\macro`, which must be defined.\nl
92 \`\aheadto` `\macro{<text>}` defines `\macro` as `<text>` followed by the
93 original `\macro` body.
94 \_cod ------------------------------
95
96 \_long\_def \_addto #1#2{\_ea\_def\_ea#1\_ea{#1#2}}
97 \_long\_def \_aheadto #1#2{\_edef#1{\_unexpanded{#2}\_unexpanded\_ea{#1}}}
98
99 \_public \addto \aheadto ;
100
101 \_doc -----------------------------
102 \`\incr``<counter>` increases `<counter>` by one globally.
103 \`\decr``<counter>` decreases `<counter>` by one globally.
104 \_cod -----------------------------
105
106 \_def\_incr #1{\_global\_advance#1by1 }
107 \_def\_decr #1{\_global\_advance#1by-1 }
108 \_public \incr \decr ;
109
110 \_doc ------------------------------
111 \`\opwarning` `{<text>}` prints warning on the terminal and to the log file.
112 \_cod ------------------------------
113
114 \_def \_opwarning #1{\_wterm{WARNING l.\_the\_inputlineno: #1.}}
115 \_public \opwarning ;
116
117 \_doc ------------------------------
118 \`\loggingall` and \`\tracingall` are defined similarly as in
119 plain \TeX/, but they print
120 more logging information to the log file and the terminal, because e\TeX/
121 and pdf\TeX/ extensions are used.\nl
122 \`\tracingnone` sets the tracing registers to their default zero value.
123 \_cod ------------------------------
124
125 \_def\_loggingall{%
126 \_tracingstats=2 \_tracingpages=1
127 \_tracingoutput=1 \_tracingmacros=3 % \_tracinglostchars=2 is already set
128 \_tracingparagraphs=1 \_tracingscantokens=1 \_tracingifs=1 \_tracinggroups=1
129 \_tracingcommands=3 \_tracingrestores=1 \_tracingassigns=1 }
130 \_def\_tracingall{\_tracingonline=1 \_loggingall}
131 \_def\_tracingnone{\_tracingassigns=0 \_tracingcommands=0 \_tracingmacros=0 \_tracingifs=0
132 \_ea \_settracingzero \_loggingall \_tracingonline=0 }
133 \_def\_settracingzero #1=#2 {#1=0 \_ifnum#2>0 \_ea \_settracingzero \_fi}
134 \_public \loggingall \tracingall \tracingnone ;
135
136 \_doc ------------------------
137 The `\optexversion` and `\fmtname` are defined in the `optex.ini` file.
138 Maybe, somebody will need a private version of these macros.
139 We add \`\_banner` used in `\everyjob` and in \~`\docgen`
140 \_cod ------------------------
141
142 \_def\_banner {This is OpTeX (Olsak's Plain TeX), version <\_optexversion>}%
143 \_private \optexversion \fmtname ;
144
145 \_doc ------------------------------
146 \`\_byehook` is used in the \^`\bye` macro.
147 It writes a warning if the user did not load a Unicode Font and
148 writes a \"rerun" warning if the `.ref` file was newly created or it was
149 changed (compared to the previous \TeX/ run).
150 The last `\message{^^J}` separates the usable log info from the following
151 unusable font-loading info, which (unfortunatly) cannot be deactivated on the terminal.
152 \_cod ------------------------------
153
154 \_def\_byehook{%
155 \_ifx\_initunifonts\_relax \_relax\_else \_opwarning{Unicode font was not loaded}\_fi
156 \_immediate\_closeout\_reffile
157 \_edef\_tmp{\_mdfive{\_jobname.ref}}%
158 \_ifx\_tmp\_prevrefhash\_else \_opwarning{Try to rerun,
159 \_jobname.ref file was \_ifx\_prevrefhash\_empty created\_else changed\_fi}\_fi
160 \_message{^^J}%
161 }
162
163 \_endcode % -------------------------------------
164
165 2026-04-14: \tracingnone introduced
166 2026-03-23: \_byehook: \message{^^J} added
167 2026-03-01: \mathadef introduced
168 2023-11-11: \adef reimplemented, \protected, \long, \global allowed before \adef
169 2023-01-22: \trycs: afterfi used for second parameter
170 2022-11-22: \_banner definition moved here
171 2022-11-18: \ahead introduced
172 2022-10-29: \_fin introduced
173 2021-07-20: \_unresovedrefs removed from \_byehook
174 2021-07-18: \_byehook: checking `ref` file consistency added.
175 2021-05-16: \slet reimplemented (to allow \slet{foo}{undefined}).
176 2021-02-03: \useit defined.
177 2021-01-22: \trycs: \ea added in order to be able to use cs with parameters
178 2021-01-08: \opwarning format changed (secondly, hope that conclusively)
179 2020-10-12: \opwarning: line numbers added
180 2020-02-14: introduced