| 1 |
% This is macro package used by OpTeX, see http://petr.olsak.net/optex |
| 2 |
% math.opm, Petr Olšák <[email protected]>, 2022 |
| 3 |
% This file can serve as an template for other package files |
| 4 |
% See end of the file for more information |
| 5 |
|
| 6 |
\_def\_math_version {0.25, 2026-04-07} |
| 7 |
\_codedecl \replacemissingchars {Doing math more comfortably <\_math_version>} |
| 8 |
\_namespace{math} |
| 9 |
|
| 10 |
\_doc |
| 11 |
The `math` package provides options, they can be declared using |
| 12 |
the \`\mathsetup``{<options>}` macro. For example `\mathsetup {vert, dots}`. |
| 13 |
If you create your own package with options, provide a similar |
| 14 |
`\<pkg>set` macro. The \`\.kv` macro is similar to \OpTeX's `\kv`, but |
| 15 |
with specific `pkg:math` dictionary. |
| 16 |
\_cod |
| 17 |
|
| 18 |
\_def\.mathsetup #1{% |
| 19 |
\_edef\.restorekvdict{\_kvdict{\_the\_kvdict}}% |
| 20 |
\_kvdict{pkg:math}% |
| 21 |
\_nokvx {\_opwarning{\_the\_kvdict: unknown option "##1", ignored}}% |
| 22 |
\_kvx {vert} {\.smartvert}% sets | as math active, to do better |x| or ||x|| |
| 23 |
\_kvx {dots} {\.smartdots}% \dots behaves like \ldots or \cdots |
| 24 |
\_kvx {interval} {\_let\_=\.interval}% enables \_<0,1) |
| 25 |
\_kvx {rmsbsp} {\.rmsbsp}% activates x_[text] and x^[text] |
| 26 |
\_kvx {ibrackets}{\.ibrackets}% intelligent brackets |
| 27 |
\_kvx {multiprimes} {\.multiprimes}% enables multi-prime symbols in script, scriptsizes |
| 28 |
\_kvx {flexipa} {\.flexipa}% flexible partial symbol |
| 29 |
\_kvx {mstyle} {\.mstyle{##1}}% sets mstyle=TeX or ISO or french or upright |
| 30 |
\_kvx {bstyle} {\.bstyle{##1}}% sets bstyle=TeX or ISO or upright or OpTeX |
| 31 |
\_kvx {bfserif} {\.bfserif}% \bf, \bi select fonts with serifs |
| 32 |
\_kvx {rmchars} {\.rmchars{##1}}% does \.rmchars{<list>} |
| 33 |
\_kvx {vargreek} {\.vargreek{##1}}% does \.vargreek{<list>} |
| 34 |
\_kvx {text} {\.dotext{##1}}% does \.dotext{<list>} |
| 35 |
\_kvx {enablefic}{\.enablefic}% enables final italic correction |
| 36 |
\_readkv{#1}% |
| 37 |
\.restorekvdict |
| 38 |
} |
| 39 |
\_def\.kv #1{\_trycs{_kv:pkg:math:#1}{\_kvunknown}}% for accessing values given by \mathsetup |
| 40 |
|
| 41 |
\_nspublic \mathsetup ; |
| 42 |
\_newpublic \_let\mathset = \.mathsetup % for backward compatibility |
| 43 |
|
| 44 |
\_doc |
| 45 |
\`\bigp`, \`\bbigp`, \`\Bigp`, \`\biggp`, \`\Biggp`, \`\autop`, \`\normalp` are inspired from |
| 46 |
\tricklink[bigp]{0094} |
| 47 |
\_cod |
| 48 |
|
| 49 |
\_def\.bigp #1{\.fparam{#1}\_bigl\_bigr} |
| 50 |
\_def\.bbigp #1{\.fparam{#1}\_bbigl\_bbigr} |
| 51 |
\_def\.Bigp #1{\.fparam{#1}\_Bigl\_Bigr} |
| 52 |
\_def\.biggp#1{\.fparam{#1}\_biggl\_biggr} |
| 53 |
\_def\.Biggp#1{\.fparam{#1}\_Biggl\_Biggr} |
| 54 |
\_def\.autop#1{\.fparam{#1}\_left\_right} |
| 55 |
\_def\.normalp#1{\.fparam{#1}\_relax\_relax} |
| 56 |
\_def\.fparam#1#2#3{% |
| 57 |
\_isequal .{#1}\_iffalse #1\_fi |
| 58 |
\_let\.bigleft=#2\_let\.bigright=#3\_nospacefuturelet\.next\.fparamA} |
| 59 |
\_def\.fparamA{% |
| 60 |
\_casesof \.next |
| 61 |
( {\.fparamB()}% |
| 62 |
[ {\.fparamB[]}% |
| 63 |
\{ {\.fparamB\{\}}% |
| 64 |
\_bgroup {\_def\.lparen{\{}\_def\.rparen{\}}\.fparamC}% |
| 65 |
\_finc {}% |
| 66 |
} |
| 67 |
\_def\.fparamB#1#2{% |
| 68 |
\_def\.lparen{#1}\_def\.rparen{#2}% |
| 69 |
\_def\.next#1##1#2{\_trick_ensurebalanced#1#2\.fparamC{##1}}% |
| 70 |
\.next |
| 71 |
} |
| 72 |
\_def\.fparamC#1{% |
| 73 |
\_ifx\.bigleft\_left \_mathopen{}\_bgroup\_fi |
| 74 |
\.bigleft\.lparen{#1}\.bigright\.rparen |
| 75 |
\_ifx\.bigright\_right \_egroup\_fi |
| 76 |
} |
| 77 |
\_nspublic \bigp \bbigp \Bigp \biggp \Biggp \autop \normalp ; |
| 78 |
|
| 79 |
\_doc |
| 80 |
We need macro \`\.ensurebalanced``<open-b><close-b><macro>` for balancing nested parentheses from |
| 81 |
\tricklink[balancing]{0043}. We use `trick` namespace for these macros. |
| 82 |
\_cod |
| 83 |
|
| 84 |
\_resetnamespace{trick} |
| 85 |
\_def\.ensurebalanced#1#2#3{\_immediateassigned{% |
| 86 |
\_def\.balopen{#1}\_def\.balclose{#2}\_let\.balaction=#3% |
| 87 |
\_def\.readnextbal##1##2#2{\.ensurebalancedA{##1#2##2}}}% |
| 88 |
\.ensurebalancedA} |
| 89 |
\_def\.ensurebalancedA#1{\.isbalanced#1% |
| 90 |
\_iftrue\_afterfi{\.balaction{#1}}\_else\_afterfi{\.readnextbal{#1}}\_fi} |
| 91 |
\_def\.isbalanced#1\_iftrue{\_immediateassignment\_tmpnum=0 \.isbalancedA#1{\.isbalanced}} |
| 92 |
\_def\.isbalancedA#1#{\.countbalanced#1\.isbalanced \.isbalancedB} |
| 93 |
\_def\.isbalancedB#1{% |
| 94 |
\_ifx\.isbalanced#1\_afterfi{\_cs{ifnum}\_tmpnum=0 }\_else\_ea\.isbalancedA\_fi} |
| 95 |
\_def\.countbalanced#1{\_ea\_ifx\.balopen #1\_immediateassignment\_incr\_tmpnum\_fi |
| 96 |
\_ea\_ifx\.balclose#1\_immediateassignment\_decr\_tmpnum\_fi |
| 97 |
\_ifx\.isbalanced#1\_else\_ea\.countbalanced\_fi} |
| 98 |
\_resetnamespace{math} |
| 99 |
|
| 100 |
\_doc |
| 101 |
\`\smartdots` re-sets `\dots` to `\.dots`. |
| 102 |
The `\.dots` lets `\.next` using `\futurelet` and checks the `\.next`: |
| 103 |
It it is declared by `\_chardef` then `\.mchar` is the real Unicode character |
| 104 |
with `\chardef`ed code. |
| 105 |
If `\.next` is a real Unicode character then `\.mchar` includes it. This |
| 106 |
is done by the expandable \o`\cstochar` macro provided by \OpTeX/. |
| 107 |
If `\.next` is something else (i.e.\ `\.mchar` is empty) then print |
| 108 |
\o`\ldots` else print \o`\cdots` for Op, Bin, Rel, Open, Close math |
| 109 |
classes of the `\.next` math object or prints \o`\ldots` in other cases. |
| 110 |
\_cod |
| 111 |
|
| 112 |
\_def\.smartdots {\_let\dots=\.dots} |
| 113 |
\_def\.dots{\_relax \_ifmmode \_ea\.specdots \_else \_dots \_fi} |
| 114 |
\_def\.specdots{\_futurelet\.next\.specdotsA} |
| 115 |
\_def\.specdotsA{% |
| 116 |
\.ischardef\.next\_iftrue \_edef\.mchar{\_Uchar\.next}% |
| 117 |
\_else \_edef\.mchar{\_cstochar\.next}% |
| 118 |
\_fi |
| 119 |
\_ifx\.mchar\_empty \_ldots |
| 120 |
\_else \_Umathcharnumdef\.next=\_Umathcode\_ea`\.mchar \_relax |
| 121 |
\_ifcase \.readclass\.next |
| 122 |
\_ldots\_or \_cdots\_or \_cdots\_or \_cdots\_or \_cdots\_or \_cdots \_else \_ldots \_fi |
| 123 |
\_fi |
| 124 |
} |
| 125 |
\_def\.ischardef #1\_iftrue {\_ea\.ischardefA\_meaning#1\_fin} |
| 126 |
\_def\.ischardefA #1#2#3#4#5#6\_fin {\_def\.tmpa{#1#2#3#4#5}\_ifx\.tmpa\.stringchar} |
| 127 |
\_edef\.stringchar{\_string\char} |
| 128 |
\_def\.readclass#1{\_ea\.readclassA\_meaning#1\_fin} |
| 129 |
\_def\.readclassA#1"#2"#3\_fin{#2} |
| 130 |
|
| 131 |
\_nspublic \smartdots ; |
| 132 |
|
| 133 |
\_doc |
| 134 |
The macro \`\.interval` reads following tokens until the `)` or `>` is found in the input |
| 135 |
queue and replaces \code{<} to `\langle` and `>` to rangle. The reading and replacing |
| 136 |
process saves the tokens to the `\intevalL` macro only and finally this macro is launched. |
| 137 |
\_cod |
| 138 |
|
| 139 |
\_def\.interval{\_def\.intervalL{}\.intervalA} |
| 140 |
\_def\.intervalA{\_nospacefuturelet\.next\.intervalB} |
| 141 |
\_def\.intervalB{\_ifx\.next\_bgroup \_ea\.intervalC \_else \_ea\.intervalD \_fi} |
| 142 |
\_def\.intervalC#1{\_addto\.intervalL{{#1}}\.intervalA} |
| 143 |
\_def\.intervalD#1{\_casesof #1 |
| 144 |
< {\_addto\.intervalL{\langle}\.intervalA} |
| 145 |
> {\_addto\.intervalL{\rangle}\.intervalL} |
| 146 |
) {\_addto\.intervalL{)}\.intervalL} |
| 147 |
\_finc {\_addto\.intervalL{#1}\.intervalA}% |
| 148 |
} |
| 149 |
|
| 150 |
\_doc |
| 151 |
\`\smartvert` sets `|` as math-active character and declares it |
| 152 |
equal to `\.autovert` macro. This macro checks two variants: there |
| 153 |
is single `|` or there is double `||`. It runs \`\.autovertA` or |
| 154 |
\`\.autoVertA`. These macros find the closing `|` or `||` and use |
| 155 |
`|` or `‖` in context of `\left`, `\right`. The \`\singlevert` |
| 156 |
is declared here if a user want to use a single vertical bar. |
| 157 |
\_cod |
| 158 |
|
| 159 |
\_newpublic\_mathchardef \singlevert=\_mathcode`| |
| 160 |
\_def\.autovert {\_isnextchar|{\.autoVertA}{\.autovertA}} |
| 161 |
\_def\.autovertA #1|{\_mathopen{}\_mathclose{\_left|#1\_right|}} |
| 162 |
\_def\.autoVertA|#1||{\_mathopen{}\_mathclose{\_left‖#1\_right‖}} |
| 163 |
\_bgroup \_lccode`\~=`\| \_lowercase{\_egroup |
| 164 |
\_def\.smartvert{\_let~=\.autovert \_mathcode`|="8000 }} |
| 165 |
|
| 166 |
\_nspublic \smartvert ; |
| 167 |
|
| 168 |
\_doc |
| 169 |
\`\rmsbsp` activates `^` and `_` so they check the next character. |
| 170 |
If it is `[` then `\mathbox` is used for subscript or superscript, else |
| 171 |
normal behavior of subscript or superscript is kept. |
| 172 |
\_cod |
| 173 |
|
| 174 |
\_def\.rmsbsp{% |
| 175 |
\_adef ^{\_isnextchar[{\.rmsp}{\_sp}} |
| 176 |
\_adef _{\_isnextchar[{\.rmsb}{\_sb}} |
| 177 |
\_def\.rmsp[##1]{\_sp{\_mathbox{##1}}} |
| 178 |
\_def\.rmsb[##1]{\_sb{\_mathbox{##1}}} |
| 179 |
\_catcode `\^=12 \_catcode`\_=11 |
| 180 |
\_mathcode`_="8000 \_mathcode`^="8000 |
| 181 |
% because ^ has different catcode, we need to re-define \_primes in order to work f'^2: |
| 182 |
\_def\_primes{\_prime\_isnextchar'{\_primesA}{\_ea\_isnextchar\_string^{\_primesB}{\_egroup}}} |
| 183 |
} |
| 184 |
\_nspublic \rmsbsp ; |
| 185 |
|
| 186 |
\_doc |
| 187 |
The control sequences \`\N`, \`\Z`, \`\Q`, \`\R`, \`\C` |
| 188 |
\`\sgn`, \`\argmin`, \`\argmax`, \`\grad`, \`\rank`, \`\tr`, \`\diag`, \`\Span`, |
| 189 |
\`\Rng`, \`\Null`, \`\Ker`, \`\Res`, \`\tg`, \`\cotg`, \`\arctg`, \`\arccotg`, |
| 190 |
\`\frac`, \`\dfrac`, \`\tfrac`, \`\.` |
| 191 |
are defined directly in the user space by \o`\_newpublic`. |
| 192 |
The \`\.pdef` is a shortcut for `\protected\def`. |
| 193 |
\_cod |
| 194 |
|
| 195 |
\_def\.pdef{\_protected\_def} |
| 196 |
|
| 197 |
\_newpublic\.pdef \N {{\_bbchar N}} |
| 198 |
\_newpublic\.pdef \Z {{\_bbchar Z}} |
| 199 |
\_newpublic\.pdef \Q {{\_bbchar Q}} |
| 200 |
\_newpublic\.pdef \R {{\_bbchar R}} |
| 201 |
\_newpublic\.pdef \C {{\_bbchar C}} |
| 202 |
|
| 203 |
\_newpublic\.pdef \sgn {\_mathop{\_rm sgn}\_nolimits} |
| 204 |
\_newpublic\.pdef \argmin {\_mathop{\_rm argmin}} |
| 205 |
\_newpublic\.pdef \argmax {\_mathop{\_rm argmax}} |
| 206 |
\_newpublic\.pdef \grad {\_mathop{\_rm grad}\_nolimits} |
| 207 |
\_newpublic\.pdef \rank {\_mathop{\_rm rank}\_nolimits} |
| 208 |
\_newpublic\.pdef \tr {\_mathop{\_rm tr}\_nolimits} |
| 209 |
\_newpublic\.pdef \diag {\_mathop{\_rm diag}\_nolimits} |
| 210 |
\_newpublic\.pdef \Span {\_mathop{\_rm Span}\_nolimits} |
| 211 |
\_newpublic\.pdef \Rng {\_mathop{\_rm Rng}\_nolimits} |
| 212 |
\_newpublic\.pdef \Null {\_mathop{\_rm Null}\_nolimits} |
| 213 |
\_newpublic\.pdef \Ker {\_mathop{\_rm Ker}\_nolimits} |
| 214 |
\_newpublic\.pdef \Res {\_mathop{\_rm Res}\_nolimits} |
| 215 |
\_newpublic\.pdef \tg {\_mathop{\_rm tg}\_nolimits} |
| 216 |
\_newpublic\.pdef \cotg {\_mathop{\_rm cotg}\_nolimits} |
| 217 |
\_newpublic\.pdef \arctg {\_mathop{\_rm arctg}\_nolimits} |
| 218 |
\_newpublic\.pdef \arccotg {\_mathop{\_rm arccotg}\_nolimits} |
| 219 |
|
| 220 |
\_newpublic\.pdef \frac #1#2{{{#1}\_over#2}} |
| 221 |
\_newpublic\.pdef \dfrac #1#2{{\_displaystyle{{#1}\_over#2}}} |
| 222 |
\_newpublic\.pdef \tfrac #1#2{{\_textstyle{{#1}\_over#2}}} |
| 223 |
|
| 224 |
\_newpublic\.pdef \.#1{{\_bf#1}} |
| 225 |
|
| 226 |
\_doc |
| 227 |
\`\harrowto``<dimen>{<arrow>}` creates horizontal <arrow> extended to |
| 228 |
<dimen> if the <dimen> is greater than the natural width of the <arrow>. |
| 229 |
Let the width of the <arrow> is $w$. The <arrow> is divided to its |
| 230 |
left part (0.4$w$), central part (0.2$w$) and right part (0.4$w$).\nl |
| 231 |
The `\hbox to<dimen>{left part, extended central part, right part} ` |
| 232 |
is printed. The parts are printed by clipping path and the extended |
| 233 |
central part is printed by `\pdfscale{<coeff>}{1}`. The parts are |
| 234 |
overlapped by 0.01$w$. |
| 235 |
\nl |
| 236 |
\`\varrowto``<dimen>{<arrow>}` does the same as \^`\harrowto` but in |
| 237 |
vertical direction. |
| 238 |
\nl |
| 239 |
\`\exw` uses \^`\scanlimits` for scaning parameters and creates `\mathop` in |
| 240 |
`\mathrel`. If optional parameter isn't specified then it measures the |
| 241 |
width of the limits by `\setbox0` (the \`\exwdist` amount is added) |
| 242 |
and then runs the \^`\harrowto` macro. |
| 243 |
\nl |
| 244 |
\`\exh` creates `\vcenter` and \^`\varrowto` is in it. |
| 245 |
\_cod |
| 246 |
|
| 247 |
\_def\.harrowto#1#{\_tmpdim=#1\_relax\.harrowtoA} |
| 248 |
\_def\.harrowtoA#1{% |
| 249 |
\_setbox0=\_hbox{$#1$}% |
| 250 |
\_ifdim\_tmpdim>\_wd0 |
| 251 |
\_hbox to\_tmpdim{% |
| 252 |
\_edef\.clip{\_bp{-\_dp0-3pt} \_bp{.4\_wd0} \_bp{\_ht0+\_dp0+6pt} re W n}% |
| 253 |
\_pdfliteral{q 0 \.clip}% |
| 254 |
\_rlap{\_unhcopy0}\_pdfliteral{Q}% |
| 255 |
\_kern.39\_wd0 |
| 256 |
\_pdfsave \_pdfscale{\_expr[4]{5*\_number\_tmpdim/\_number\_wd0-3.9}}{1}% |
| 257 |
\_pdfliteral{0 0 \_bp{.2\_wd0} \_bp{\_ht0} re W n}% |
| 258 |
\_rlap{\_kern-.4\_wd0 \_unhcopy0}\_pdfrestore |
| 259 |
\_hss |
| 260 |
\_pdfliteral{q \_bp{-.4\_wd0} \.clip}% |
| 261 |
\_llap{\_unhbox0}\_pdfliteral{Q}}% |
| 262 |
\_else \_box0 \_fi |
| 263 |
} |
| 264 |
\_def\.varrowto#1#{\_tmpdim=#1\_relax\.varrowtoA} |
| 265 |
\_def\.varrowtoA#1{% |
| 266 |
\_setbox0=\_hbox{$#1$}\_setbox0=\_hbox{\_raise\_dp0\_box0}% |
| 267 |
\_ifdim\_tmpdim>\_ht0 |
| 268 |
\_vbox to\_tmpdim{\_offinterlineskip |
| 269 |
\_def\.vlap##1:##2{\_vbox to0pt{\_vss##2\_kern-##1}}% |
| 270 |
\_edef\.clip{\_bp{\_wd0} \_bp{.4\_ht0} re W n}% |
| 271 |
\_pdfliteral{q 0 \_bp{-.4\_ht0} \.clip}% |
| 272 |
\.vlap\_ht0:{\_copy0}\_pdfliteral{Q}% |
| 273 |
\_kern.39\_ht0 |
| 274 |
\_pdfsave \_pdfscale{1}{\_expr[4]{5*\_number\_tmpdim/\_number\_ht0-3.9}}% |
| 275 |
\_pdfliteral{0 \_bp{-.2\_ht0} \_bp{\_wd0} \_bp{.2\_ht0} re W n}% |
| 276 |
\.vlap.6\_ht0:{\_copy0}\_pdfrestore |
| 277 |
\_vss |
| 278 |
\_pdfliteral{q 0 0 \.clip}% |
| 279 |
\.vlap 0pt:{\_box0}\_pdfliteral{Q}% |
| 280 |
} |
| 281 |
\_else \_vbox{\_box0}\_fi |
| 282 |
} |
| 283 |
\_newdimen\.exwdist \.exwdist=1.5pt |
| 284 |
\_optdef\.exw[]#1{\.scanlimits{\.exwA{#1}}} |
| 285 |
\_def\.exwA#1#2#3{\_mathrel{\_mathop{% |
| 286 |
\_if^\_the\_opt^% |
| 287 |
\_def\.sp{\_hskip\.exwdist\_relax}% |
| 288 |
\_setbox0=\_hbox{$\_mathop{#1}\_limits^{\.sp#2\.sp}_{\.sp#3\.sp}$}% |
| 289 |
\_tmpdim=\_wd0 |
| 290 |
\_else\_tmpdim=\_the\_opt\_relax |
| 291 |
\_fi |
| 292 |
\.harrowto\_tmpdim{#1}}\_limits^{#2}_{#3}}% |
| 293 |
} |
| 294 |
\_optdef\.exh[0pt]#1{\_vcenter{\.varrowto\_the\_opt{#1}}} |
| 295 |
|
| 296 |
\_nspublic \exw \exh \harrowto \varrowto \exwdist ; |
| 297 |
|
| 298 |
\_doc |
| 299 |
\`\multiprimes` sets {\def\\{\kern-3.8pt}{\tt '}, |
| 300 |
{\tt '\\'}, {\tt '\\'\\'}, {\tt '\\'\\'\\'}} |
| 301 |
as active characters. It enables to use them naturally |
| 302 |
in script and script-script sizes. |
| 303 |
These special characters defined here are probably invisible |
| 304 |
in the following code in `math-doc.pdf`. |
| 305 |
\_cod |
| 306 |
|
| 307 |
\_def\.multiprimes{\.unionly\multiprimes{% |
| 308 |
\_adef ′{^′}\_adef ″{^″} \_adef ‴{^‴} \_adef ⁗{^⁗}}} |
| 309 |
\_nspublic \multiprimes ; |
| 310 |
|
| 311 |
\_doc |
| 312 |
\`\eqsystem``{<equations>}` saves its parameter to `\.tmpb` |
| 313 |
and does a collection of `\_replstring`s. It replaces all spaces by `&` |
| 314 |
(but ignores the optional first and last space), it removes spaces before `\cr`, |
| 315 |
it precedes `\mathord` before all `-` |
| 316 |
(but not if the minus is alone in the column) and runs `\halign`. |
| 317 |
The \n`\baselineskip` is enlarged by \O`\openup`\`\eqskip`. |
| 318 |
Each item adds 0.5\`\eqsep` around it and \`\eqfil` to the left side and |
| 319 |
`\hfil` to the right side. |
| 320 |
\_cod |
| 321 |
|
| 322 |
\_protected \_optdef\.eqsystem[]#1{\_vcenter{% |
| 323 |
\_def\.tmpb{\.bb#1\.bb}\_replstring\.tmpb{ }{&}% |
| 324 |
\_replstring\.tmpb{\.bb&}{}\_replstring\.tmpb{&\.bb}{}\_replstring\.tmpb{&\cr}{\cr}% |
| 325 |
\_replstring\.tmpb{-}{\_mathord-}\_replstring\.tmpb{&\_mathord-&}{&-&}% |
| 326 |
\_replstring\.tmpb{+}{\_mathord+}\_replstring\.tmpb{&\_mathord+&}{&+&}% |
| 327 |
\_let ~=\_relax |
| 328 |
\_the\_opt \_relax \_openup\.eqskip |
| 329 |
\_halign{&\_the\.eqfil\_kern.5\.eqsep$\_displaystyle{{}##{}}$\_kern.5\.eqsep\_hfil\_cr |
| 330 |
\.tmpb\_crcr}% |
| 331 |
}} |
| 332 |
\_let\.bb=\_empty |
| 333 |
\_newdimen\.eqskip |
| 334 |
\_newdimen\.eqsep |
| 335 |
\_newtoks\.eqfil \.eqfil={\_hfill} |
| 336 |
\_nspublic \eqsystem \eqskip \eqsep \eqfil ; |
| 337 |
|
| 338 |
\_doc |
| 339 |
The \`\toright` and \`\toleft` macros are based on the |
| 340 |
\o`\setpos` and \o`\posx` macros. The printing point is shifted by `\posx` |
| 341 |
to the left (i.e.\ to the left boundary of the sheet) and then it is shifted |
| 342 |
to the desired space by `\kern\hoffset+\hsize`. |
| 343 |
This idea is moved from \tricklink[torighteq]{0028}. |
| 344 |
\_cod |
| 345 |
|
| 346 |
\_newcount \.tomarginno |
| 347 |
\_def\.toright #1{\_incr\.tomarginno {\_setpos[_math_tr:\_the\.tomarginno]% |
| 348 |
\_rlap{\_kern-\_posx[_math_tr:\_the\.tomarginno]\_kern\_hoffset\_kern\_hsize\_llap{#1}}}} |
| 349 |
\_def\.toleft #1{\_incr\.tomarginno {\_setpos[_math_tr:\_the\.tomarginno]% |
| 350 |
\_rlap{\_kern-\_posx[_math_tr:\_the\.tomarginno]\_kern\_hoffset\_rlap{#1}}}} |
| 351 |
|
| 352 |
\_nspublic \toright \toleft ; |
| 353 |
|
| 354 |
\_doc |
| 355 |
The \`\subeqmark` works because the internal \O`\_thednum` |
| 356 |
is re-defined. The \`\.dnumpost` is added here. If you want to use another format |
| 357 |
for \O`\_thednum` then you have to add the \^`\.dnumpost` to it too. |
| 358 |
\_cod |
| 359 |
|
| 360 |
\_def \_thednum {(\_the\_dnum \.dnumpost)} |
| 361 |
\_def\.dnumpost{} |
| 362 |
\_def\.subeqmark #1{\_def\.dnumpost{#1}\_lowercase{\_ifx a#1}\_else \_decr\_dnum\_fi \_eqmark} |
| 363 |
|
| 364 |
\_nspublic \subeqmark ; |
| 365 |
|
| 366 |
\_doc |
| 367 |
\`\ibrackets` is implemented analogically as in the \LaTeX/ package `ibrackets`. |
| 368 |
I.e.\ the `[` and `]` are math active and they are set as `\mathord` by defualt, |
| 369 |
but they are `\mathopen` if the `+` or `-` follows. |
| 370 |
\_cod |
| 371 |
|
| 372 |
\_def\.ibrackets{\.unionly\ibrackets{% |
| 373 |
\_mathchardef\.openbracket\_mathcode`[ |
| 374 |
\_mathchardef\.closebracket\_mathcode`] |
| 375 |
\_mathcode`[="8000 \_mathcode`]="8000 |
| 376 |
{\_global\_adef[{\_futurelet\.next\.openbr}% |
| 377 |
\_global\_adef]{\_futurelet\.next\.closebr}}% |
| 378 |
}} |
| 379 |
\_def\.openbr{\.setbracket \.openbracket} |
| 380 |
\_def\.closebr{\.setbracket \.closebracket} |
| 381 |
\_def\.setbracket{\_ifx\.next+\_mathopen\_else \_ifx\.next-\_mathopen\_else \_mathord\_fi\_fi} |
| 382 |
|
| 383 |
\_nspublic \ibrackets ; |
| 384 |
|
| 385 |
\_doc |
| 386 |
\`\flexipa` (or \`\flexiblepartial`) runs |
| 387 |
\~`\partialsymbolvars` `{it}`\,`{rm}`\,`{bfsans}`\,`{it}`\,`{bfitsans}`. |
| 388 |
The \`\partialsymbolvars` macro adds two tokens `\.partialvar \m<var>partial` |
| 389 |
to `\_mit`, `\_marm`, `\_mabf`, `\_mait`, `\_mabi` macros. |
| 390 |
The \`\.partialvar` macro sets appropriate |
| 391 |
`\_Umathcode` of the `\.partialchar` to the code given by the parameter |
| 392 |
`\m<var>partial`. Five macros |
| 393 |
\`\mbfpartial`, \`\mitpartial`, \`\mbfitpartial`, \`\mbfsanspartial`, \`\mbfitsanspartial` |
| 394 |
are declared in the macro file `unimath-table.opm`. |
| 395 |
The math character \`\mrmpartial` (for upright variant) is declared here. |
| 396 |
\_cod |
| 397 |
|
| 398 |
\_chardef\.partialchar="2202 |
| 399 |
\_Umathchardef\.mrmpartial=0 1 \.partialchar |
| 400 |
\_def\.partialvar #1{\_Umathcode \.partialchar 0 1 |
| 401 |
\_ifx#1\.mrmpartial \.partialchar \_else\_ea`#1 \_fi |
| 402 |
} |
| 403 |
\_def\.inadd#1#2{\_ea\.inaddA#1{#2}#1} |
| 404 |
\_def\.inaddA\_inmath#1#2#3{\_protected\_def#3{\_inmath{#1#2}}} |
| 405 |
|
| 406 |
\_def\.partialsymbolvars #1#2#3#4#5{% |
| 407 |
\_ifx\_ncharrmA\_undefined \_opwarning{\_string\flexipa: Unicode math must be loaded first}% |
| 408 |
\_else |
| 409 |
\_def\.tmp{\_ea\_addto \_ea\_mit \_ea {\_ea\.partialvar \_csname m#1partial\_endcsname}}% |
| 410 |
\_ifx\_mit\mit \.tmp \_let\mit=\_mit \_else \.tmp \_fi |
| 411 |
\_ea\.inadd \_ea\_marm \_ea {\_ea\.partialvar \_csname m#2partial\_endcsname}% |
| 412 |
\_ea\.inadd \_ea\_mabf \_ea {\_ea\.partialvar \_csname m#3partial\_endcsname}% |
| 413 |
\_ea\.inadd \_ea\_mait \_ea {\_ea\.partialvar \_csname m#4partial\_endcsname}% |
| 414 |
\_ea\.inadd \_ea\_mabi \_ea {\_ea\.partialvar \_csname m#5partial\_endcsname}% |
| 415 |
\_mit |
| 416 |
\_fi |
| 417 |
} |
| 418 |
\_def\.flexipa{\.unionly\flexipa{\.partialsymbolvars {it}{rm}{bfsans}{it}{bfitsans}}} |
| 419 |
\_newpublic \_let \flexiblepartial=\.flexipa |
| 420 |
\_nspublic \flexipa \partialsymbolvars \mrmpartial ; |
| 421 |
|
| 422 |
\_doc |
| 423 |
The options `mstyle`, resp. `bstyle` run \`\.mstyle`, resp. \`\.bstyle` |
| 424 |
and these macros set required shapes of math variables. This can be done |
| 425 |
only when Unicode-math is loaded already. This is a reason why |
| 426 |
\`\.unionly``{<text>}{<code>}` is used: it runs <code> only when |
| 427 |
Unicode-math is loaded, otherwise it prints a warning. |
| 428 |
\_cod |
| 429 |
|
| 430 |
\_def\.mstyle #1{\.unionly{mstyle}{\_lowercase{\_cs{_math_mstyle_#1}}}} |
| 431 |
\_def\.bstyle #1{\.unionly{bstyle}{\_lowercase{\_cs{_math_bstyle_#1}}}} |
| 432 |
|
| 433 |
\_def\.mstyle_tex {% |
| 434 |
\_protected\_def\_mit {\_itvariables \_rmdigits \_itgreek \_rmGreek}\_mit |
| 435 |
} |
| 436 |
\_def\.mstyle_iso {% |
| 437 |
\_protected\_def\_mit {\_itvariables \_rmdigits \_itgreek \_itGreek}\_mit |
| 438 |
} |
| 439 |
\_def\.mstyle_french {% |
| 440 |
\_protected\_def\_mit {\_umathrange{A-Z}71\_ncharrmA \_umathrange{a-z}71\_ncharita |
| 441 |
\_rmdigits \_rmgreek \_rmGreek}% |
| 442 |
\_mit |
| 443 |
} |
| 444 |
\_def\.mstyle_upright {% |
| 445 |
\_protected\_def\_mit {\_rmvariables \_rmdigits \_rmgreek \_rmGreek}\_mit |
| 446 |
} |
| 447 |
\_def\.bstyle_tex {% |
| 448 |
\_protected\_def\_mabf {\_inmath{\_bfvariables\_bigreek\_bfGreek\_bfdigits}}% |
| 449 |
\_protected\_def\_mabi {\_inmath{\_bivariables\_bigreek\_bfGreek\_bidigits}}% |
| 450 |
} |
| 451 |
\_def\.bstyle_optex {% |
| 452 |
\_protected\_def\_mabf {\_inmath{\_bsansvariables \_bsansgreek \_bsansGreek \_bsansdigits}}% |
| 453 |
\_protected\_def\_mabi {\_inmath{\_bisansvariables \_bisansgreek \_bsansGreek \_bsansdigits}}% |
| 454 |
} |
| 455 |
\_def\.bstyle_iso {% |
| 456 |
\_protected\_def\_mabf {\_inmath{\_bivariables\_bigreek\_biGreek\_bfdigits}}% |
| 457 |
\_protected\_def\_mabi {\_inmath{\_bivariables\_bigreek\_bfGreek\_bidigits}}% |
| 458 |
} |
| 459 |
\_def\.bstyle_upright {% |
| 460 |
\_protected\_def\_mabf {\_inmath{\_bfvariables\_bfgreek\_bfGreek\_bfdigits}}% |
| 461 |
\_protected\_def\_mabi {\_inmath{\_bivariables\_bigreek\_biGreek\_bidigits}}% |
| 462 |
} |
| 463 |
\_def\.unionly #1{\_ifx\_rmvariables\_undefined |
| 464 |
\_opwarning{pkg:math: \_string#1 ignored: Unicode-math must be loaded}% |
| 465 |
\_ea\_ignoreit \_else \_ea\_useit \_fi |
| 466 |
} |
| 467 |
|
| 468 |
\_doc |
| 469 |
\`\bfserif` re-defines internal \OpTeX/ \O`\_mabf` and \O`\_mabi` macros. |
| 470 |
\_cod |
| 471 |
|
| 472 |
\_def\.bfserif{\.unionly\bfserif{% |
| 473 |
\_protected\_def\_mabf {\_inmath{\_bfvariables\_bfgreek\_bfGreek\_bfdigits}}% |
| 474 |
\_protected\_def\_mabi {\_inmath{\_bivariables\_bigreek\_bfGreek\_bfdigits}}% |
| 475 |
}} |
| 476 |
|
| 477 |
\_nspublic \bfserif ; |
| 478 |
|
| 479 |
\_doc |
| 480 |
\`\rmchars``{<list>}` is implemented using \O`\foreach`. The list is |
| 481 |
expanded first because we want to expand control sequences like `\alpha` |
| 482 |
to a real character $\_rmgreek \alpha$.\nl |
| 483 |
\`\vargreek``{<list>}` is implemented using \O`\foreach`. The |
| 484 |
parameter is not expanded because we want to keep control sequences like |
| 485 |
`\alpha` unchanged. |
| 486 |
\_cod |
| 487 |
|
| 488 |
\_def\.rmchars#1{\.unionly\rmchars{\_ea\_foreach\_expanded{#1}\_do{\_ifx,##1\_else\.rmchar##1\_fi}}} |
| 489 |
\_def\.rmchar#1{\_Umathcode`#1=0 1 `#1 } |
| 490 |
|
| 491 |
\_def\.vargreek#1{\_foreach#1\_do{\_ifx,##1\_else \.vargreekchar##1\_fi}} |
| 492 |
\_def\.vargreekchar#1{% |
| 493 |
\_ifcsname var\_csstring#1\_endcsname \_slet{\_csstring#1}{var\_csstring#1}% |
| 494 |
\_else \_opwarning{\_string\vargreek: the \_bslash var\_csstring#1\_space doesn't exists}% |
| 495 |
\_fi |
| 496 |
} |
| 497 |
\_nspublic \rmchars \vargreek ; |
| 498 |
|
| 499 |
\_doc |
| 500 |
\`\textvariables`, \`\textdigits`, \`\textmoremath` initialize |
| 501 |
new two families 5, 6 using `\.textmathini` and sets `\mathcode`s |
| 502 |
of given characters to these families. |
| 503 |
Moreover, `\textvariables` adds `\fam` register setting to `\rm` and `\it` |
| 504 |
selectors and re-set Greek variables to use only math font (because we |
| 505 |
are not sure if Greek letters are in the current text fonts).\nl |
| 506 |
\`\.dotext``{<list of words>}` runs `\.text<word>` for each <word> in the list. |
| 507 |
It is used when the option `text={<list of words>}` is used. |
| 508 |
\_cod |
| 509 |
|
| 510 |
\_def\.textmathini{% |
| 511 |
\_fontdef\.mathrm{\_rm}\_fontdef\.mathit{\_it}% |
| 512 |
\_fontdef\.mathbf{\_bf}\_fontdef\.mathbi{\_bi}% |
| 513 |
\_addto\_normalmath{% |
| 514 |
\_setmathfamily 5 \.mathrm |
| 515 |
\_setmathfamily 6 \.mathit |
| 516 |
}% |
| 517 |
\_addto\_boldmath{% |
| 518 |
\_setmathfamily 5 \.mathbf |
| 519 |
\_setmathfamily 6 \.mathbi |
| 520 |
}% |
| 521 |
\_normalmath |
| 522 |
\_let\.textmathini=\_relax |
| 523 |
} |
| 524 |
\_def\.textvariables {\.unionly\textvariables {% |
| 525 |
\.textmathini \_mathcodes 6 {7{\_Urange a-z \_Urange A-Z}}% |
| 526 |
\_def\_marm {\_fam5 }\_def\_mait{\_itGreek \_fam6 }% |
| 527 |
\_protected\_def\_itgreek {\_umathrangegreek01\_greekita}% |
| 528 |
\_protected\_def\_rmgreek {\_umathrangegreek01\_greekrma}% |
| 529 |
\_protected\_def\_itGreek {\_umathrangeGREEK01\_greekitA} |
| 530 |
\_protected\_def\_rmGreek {\_umathrangeGREEK01\_greekrmA} |
| 531 |
\_itgreek \_rmGreek |
| 532 |
}} |
| 533 |
\_def\.textdigits {\.unionly\textdigits{\.textmathini \_mathcodes 5 {7{\_Urange 0-9}}}} |
| 534 |
\_def\.textmoremath {\.unionly\textmoremath{% |
| 535 |
\.textmathini |
| 536 |
\_mathcodes 5 {5{!?} 2{*+-} 3{=<>} 6{,:;} 0{./|} 4{([\{} 5{\})]}}% |
| 537 |
\_Umathcode `- = 2 5 "2212 % hyphen behaves like minus in math mode |
| 538 |
}} |
| 539 |
\_def\.dotext#1{\_foreach #1 \_do |
| 540 |
##1 {\_trycs{_math_text##1}{\_opwarning{text option: "##1" unknown}}}} |
| 541 |
|
| 542 |
\_nspublic \textvariables \textdigits \textmoremath ; |
| 543 |
|
| 544 |
\_doc |
| 545 |
\`\mathselector` `\sequence {<fontspec-A>} {<fontspec-B>} {<factor>} {<ffeatures>}` |
| 546 |
declares `\sequence` as a new math selector of the math family `\sequence_fam`. |
| 547 |
If such family is declared already then new setting is ignored. |
| 548 |
The font is set by \o`\fontdef` and then its name without size clause and without font features |
| 549 |
is saved to `\.mselF` using `\.mselA`. The line |
| 550 |
`\_loadmathfamily <fam> {{<fontname>:<ffeatures>}}` is saved to \o`\_normalmath` |
| 551 |
and analogical line is saved to \o`\_boldmath`. |
| 552 |
Finally, if the declared `\sequence` is in `\rm`,`\it`,`\bf`,`\bi`,`\tt` then |
| 553 |
`\_marm`, `\_mait`, etc.\ is defined else `\sequence` is defined. |
| 554 |
It guarantees that the re-declaration of `\rm`, `\it`, etc.\ affects their |
| 555 |
behavior only in math mode. |
| 556 |
\_cod |
| 557 |
|
| 558 |
\_def\.mathselector #1#2#3#4#5{\.unionly\mathselector{% |
| 559 |
\_ifcsname \_csstring#1_fam\_endcsname |
| 560 |
\_opwarning{\_string#1 already defined as \_string\mathselector, ignored}% |
| 561 |
\_else |
| 562 |
\_ea\_newfam \_csname \_csstring#1_fam\_endcsname |
| 563 |
\_ifx^#4^\_else \_sxdef{_mfactor:\_the\_numexpr\_cs{\_csstring#1_fam}}{#4}\_fi |
| 564 |
\_ifx^#5^\_def\.mselFF{mode=base;script=latn}\_else \_def\.mselFF{#5}\_fi |
| 565 |
\_fontdef\.mselF{#2}\_ea\.mselA \_fontname\.mselF :\_relax |
| 566 |
\_edef\.tmp{\_noexpand \_loadmathfamily \_cs{\_csstring#1_fam}{{\.mselF:\.mselFF;}} }% |
| 567 |
\_global \_ea\_aheadto \_ea\_normalmath \_ea{\.tmp}% |
| 568 |
\_normalmath |
| 569 |
\_ifx^#3^\_addto\.mselFF{;embolden=1.7}% |
| 570 |
\_else \_fontdef\.mselF{#3}\_ea\.mselA \_fontname\.mselF :\_relax \_fi |
| 571 |
\_edef\.tmp{\_noexpand \_loadmathfamily \_cs{\_csstring#1_fam}{{\.mselF:\.mselFF;}} }% |
| 572 |
\_global \_ea\_aheadto \_ea\_boldmath \_ea{\.tmp}% |
| 573 |
\_isinlist{\rm\it\bf\bi\tt}#1\_iftrue |
| 574 |
\_ea\.mselB \_csname _ma\_csstring#1\_ea\_endcsname \_csname \_csstring#1_fam\_endcsname |
| 575 |
\_else \_ea\.mselB \_ea#1\_csname \_csstring#1_fam\_endcsname |
| 576 |
\_fi\_fi |
| 577 |
}} |
| 578 |
\_def\.mselA #1:#2\_relax{\_def\.mselF{#1}} |
| 579 |
\_def\.mselB #1#2{\_gdef#1{\_inmath{\_rmvariables \_rmdigits \_rmgreek \_rmGreek \_fam#2}}} |
| 580 |
|
| 581 |
\_nspublic \mathselector ; |
| 582 |
|
| 583 |
\_doc |
| 584 |
\`\replacemissingchars``<family>` defines `\UnicodeMathSymbol` and reads |
| 585 |
`unimath-table.opm`, i.e.\ it does for each math character following |
| 586 |
if the character is missing in main math font and if it is present in |
| 587 |
added font and if it is not already replaced character then apply new math |
| 588 |
code or `\Umathaccent` definition. Its name is added to `\.alist` or |
| 589 |
`\.clist`. The new codes are declared by `\matchars<family>{<expanded>\clist}`. |
| 590 |
The `\.rlist` is the list of characters already replaced. They are not |
| 591 |
replaced again if a new `\replacemissingchars` is used. |
| 592 |
\_cod |
| 593 |
|
| 594 |
\_def\.rlist{\sqrt\cuberoot\fourthroot} % they cannot be replaced by \mathchars |
| 595 |
\_def\.replacemissingchars#1{\.unionly\replacemissingchars{% |
| 596 |
\_def\.alist{}\_def\.clist{} |
| 597 |
\_def\UnicodeMathSymbol##1##2##3##4{% |
| 598 |
\_iffontchar\_textfont1##1 \_else % not in main math font |
| 599 |
\_iffontchar\_textfont#1 ##1 % is presnet in added font |
| 600 |
\_isinlist\.rlist{##2}\_iffalse % not already replaced |
| 601 |
\_ifx##3\_mathaccent |
| 602 |
\_protected\_def##2{\_Umathaccent fixed 7 #1 ##1 }% |
| 603 |
\_addto\.alist{##2}% |
| 604 |
\_else |
| 605 |
\_addto\.clist{##2}% |
| 606 |
\_fi\_fi\_fi\_fi |
| 607 |
} |
| 608 |
\_input unimath-table.opm |
| 609 |
\_wlog{^^J\_string\replacemissingchars: From \_string\fam=\_string#1 is printed now:^^J% |
| 610 |
CHARACTERS: \_unexpanded\_ea{\.clist}^^JACCENTS: \_unexpanded\_ea{\.alist}^^J}% |
| 611 |
\_def\.tmp{\_mathchars #1}\_ea\.tmp\_ea{\.clist}% |
| 612 |
\_ea\_addto \_ea\.rlist \_ea{\.clist}\_ea\_addto \_ea\.rlist \_ea{\.alist}% |
| 613 |
\_def\.alist{}\_def\.clist{}\_let\UnicodeMathSymbol=\_undefined |
| 614 |
}} |
| 615 |
\_nspublic \replacemissingchars ; |
| 616 |
|
| 617 |
\_doc |
| 618 |
\`\scriptspaces``{<s-rel>}{<s-bin>}{<ss-rel>}{<ss-bin>}` |
| 619 |
sets internal \LuaTeX/ registers represented by |
| 620 |
appropriate primitives, see section 7.5 in the \LuaTeX/ manual. |
| 621 |
\_cod |
| 622 |
|
| 623 |
\_def\.scriptspaces #1#2#3#4{% |
| 624 |
\_Umathordrelspacing\_scriptstyle=\.orzeromu{#1}\_relax |
| 625 |
\_Umathrelordspacing\_scriptstyle=\.orzeromu{#1}\_relax |
| 626 |
\_Umathrelopspacing \_scriptstyle=\.orzeromu{#1}\_relax |
| 627 |
\_Umathordrelspacing\_crampedscriptstyle=\.orzeromu{#1}\_relax |
| 628 |
\_Umathrelordspacing\_crampedscriptstyle=\.orzeromu{#1}\_relax |
| 629 |
\_Umathrelopspacing \_crampedscriptstyle=\.orzeromu{#1}\_relax |
| 630 |
\_Umathordbinspacing\_scriptstyle=\.orzeromu{#2}\_relax |
| 631 |
\_Umathbinordspacing\_scriptstyle=\.orzeromu{#2}\_relax |
| 632 |
\_Umathbinopspacing \_scriptstyle=\.orzeromu{#2}\_relax |
| 633 |
\_Umathordbinspacing\_crampedscriptstyle=\.orzeromu{#2}\_relax |
| 634 |
\_Umathbinordspacing\_crampedscriptstyle=\.orzeromu{#2}\_relax |
| 635 |
\_Umathbinopspacing \_crampedscriptstyle=\.orzeromu{#2}\_relax |
| 636 |
\_Umathordrelspacing\_scriptscriptstyle=\.orzeromu{#3}\_relax |
| 637 |
\_Umathrelordspacing\_scriptscriptstyle=\.orzeromu{#3}\_relax |
| 638 |
\_Umathrelopspacing \_scriptscriptstyle=\.orzeromu{#3}\_relax |
| 639 |
\_Umathordrelspacing\_crampedscriptscriptstyle=\.orzeromu{#3}\_relax |
| 640 |
\_Umathrelordspacing\_crampedscriptscriptstyle=\.orzeromu{#3}\_relax |
| 641 |
\_Umathrelopspacing \_crampedscriptscriptstyle=\.orzeromu{#3}\_relax |
| 642 |
\_Umathordbinspacing\_scriptscriptstyle=\.orzeromu{#4}\_relax |
| 643 |
\_Umathbinordspacing\_scriptscriptstyle=\.orzeromu{#4}\_relax |
| 644 |
\_Umathbinopspacing \_scriptscriptstyle=\.orzeromu{#4}\_relax |
| 645 |
\_Umathordbinspacing\_crampedscriptscriptstyle=\.orzeromu{#4}\_relax |
| 646 |
\_Umathbinordspacing\_crampedscriptscriptstyle=\.orzeromu{#4}\_relax |
| 647 |
\_Umathbinopspacing \_crampedscriptscriptstyle=\.orzeromu{#4}\_relax |
| 648 |
} |
| 649 |
\_def\.orzeromu#1{\_ifx^#1^0mu\_else#1\_fi} |
| 650 |
|
| 651 |
\_nspublic \scriptspaces ; |
| 652 |
|
| 653 |
\_doc |
| 654 |
\`\mathclap``{<formula>}`, \`\mathrlap``{<formula>}`, and \`\mathllap``{<formula>}` |
| 655 |
are based on the \OpTeX/ macros \O`\mathstyles` and \O`\currstyle`.\nl |
| 656 |
\`\scanlimits``\macro` or `\scanlimits{<text>}` saves its first parameter |
| 657 |
to `#1` and transforms following. |
| 658 |
\_cod |
| 659 |
|
| 660 |
\_def\.mathclap#1{\_mathstyles{\_hbox to0pt{\_hss$\_currstyle#1$\_hss}}} |
| 661 |
\_def\.mathrlap#1{\_mathstyles{\_rlap{$\_currstyle#1$}}} |
| 662 |
\_def\.mathllap#1{\_mathstyles{\_llap{$\_currstyle#1$}}} |
| 663 |
|
| 664 |
\_def\.scanlimits#1{% |
| 665 |
\_nospaceafter{\_isnextchar _{\.limiB#1}{\_isnextchar ^{\.limiU{#1}}{#1{}{}}}}} |
| 666 |
\_def\.limiB#1_#2{\_nospaceafter{\_isnextchar ^{\.limiUf{#1}{#2}}{#1{}{#2}}}} |
| 667 |
\_def\.limiU#1^#2{\_nospaceafter{\_isnextchar _{\.limiBf{#1}{#2}}{#1{#2}{}}}} |
| 668 |
\_def\.limiBf#1#2_#3{#1{#2}{#3}} |
| 669 |
\_def\.limiUf#1#2^#3{#1{#3}{#2}} |
| 670 |
|
| 671 |
\_nspublic \mathclap \mathrlap \mathllap \scanlimits ; |
| 672 |
|
| 673 |
\_doc |
| 674 |
\`\enablefic` enables final italic correction. The relevant lua function is |
| 675 |
registered to `mlist_to_hlist` callback and \`\finalitalcorr` is set to one. |
| 676 |
\_cod |
| 677 |
|
| 678 |
\_newcount \.finalitalcorr |
| 679 |
\_ifnum\_luatexversion > 123 |
| 680 |
\_def\.enablefic{% |
| 681 |
\_opwarning{\_noexpand\enablefic is obsolete, LuaTeX v>1.23 fixes this issue}% |
| 682 |
} |
| 683 |
\_else |
| 684 |
\_directlua{ |
| 685 |
define_lua_command("\_pkglabel _enablefic", function() |
| 686 |
lua.get_functions_table()[optex.registernumber("\_pkglabel _enablefic")] = function() |
| 687 |
% add the function to the callback only once |
| 688 |
return tex.setcount("\_pkglabel _finalitalcorr", 1) |
| 689 |
end |
| 690 |
tex.setcount("\_pkglabel _finalitalcorr", 1) |
| 691 |
luatexbase.add_to_callback("post_mlist_to_hlist_filter", function(head, style) |
| 692 |
if style~="text" or tex.count.\_pkglabel _finalitalcorr<=0 then |
| 693 |
return true |
| 694 |
end |
| 695 |
local last = node.tail(head) |
| 696 |
if last.id ~= node.id("glyph") then return true end % last is glyph |
| 697 |
local k = font.fonts[last.font].characters[last.char].italic |
| 698 |
if not k or k<=0 then return true end |
| 699 |
local kn = node.new("kern", 3) |
| 700 |
kn.kern = k |
| 701 |
head = node.insert_after(head, n, kn) % kern node is inserted |
| 702 |
return head |
| 703 |
end, "italcorr after math") end)} |
| 704 |
\_fi |
| 705 |
\_nspublic \enablefic \finalitalcorr ; |
| 706 |
|
| 707 |
|
| 708 |
\_endnamespace |
| 709 |
\_endcode |
| 710 |
|
| 711 |
\sec Summary |
| 712 |
|
| 713 |
This package provides various extensions usable for math typesetting. Mostly |
| 714 |
of them are inspired from |
| 715 |
\ulink[http://petr.olsak.net/optex/optex-tricks.html]{\OpTeX/ tricks} www page. |
| 716 |
|
| 717 |
The following macros are defined in this package: |
| 718 |
\begitems |
| 719 |
* \~`\bigp`, \~`\bbigp`, \~`\Bigp`, \~`\biggp`, \~`\Biggp`, \~`\autop`, \~`\normalp` |
| 720 |
gives better controlling of sizes of parentheses. |
| 721 |
* \~`\smartdots` declares `\dots` macro more intelligent. |
| 722 |
\~`\smartvert` declares \"`|`" for better spacing. |
| 723 |
* \~`\rmsbsp` activates roman subscripts and superscripts in `[...]`. |
| 724 |
* There are many common math macros for sets or for operators, for example |
| 725 |
\~`\R` or \~`\sgn`. |
| 726 |
* \~`\eqsystem` enables to write systems of equations comfortably, |
| 727 |
* \~`\toright`, \~`\toleft` puts the \o`\eqmark` to desired position, |
| 728 |
\~`\subeqmark` prints the given suffix as a part of the equation mark. |
| 729 |
* \~`\scriptspaces` sets more spaces around rel, bin in script and scripscript styles. |
| 730 |
* \~`\ibrackets` sets `[` and `]` as intelligent brackets. |
| 731 |
* \~`\multiprimes` sets double, triple, quadruple primes as active. |
| 732 |
* \~`\flexipa` enables flexible partial symbol. |
| 733 |
* \~`\bfserif` sets `\bf` and `\bi` for math typesetting as for bold-serif, bold-italic-serif. |
| 734 |
* \~`\rmchars` sets selected characters printed as `\rm`, |
| 735 |
\~`\vargreek` sets Greek leters to their variants. |
| 736 |
* \~`\textvariables`, \~`\textdigits`, \~`\textmoremath` |
| 737 |
enables characters from used text font in math mode |
| 738 |
(variables, digits, more characters). |
| 739 |
* \~`\mathselector` declares a new math alphabet using text fonts. |
| 740 |
* \~`\replacemissingchars` allows to re-declare all characters missing in math font |
| 741 |
for printing them from additional math font. |
| 742 |
* \~`\enablefic` enables final italic correction of inline-math lists. |
| 743 |
* \~`\scanlimits` transforms the limits format (usage of `^` and `_`) to the parameters pair. |
| 744 |
* \~`\exw`, \~`\exh` extend the horizontal and vertical arrows. |
| 745 |
\enditems |
| 746 |
|
| 747 |
Following options are provided by the `math` package. You can set them by |
| 748 |
\^`\mathsetup``{<options>}` after `\load[math]`, for example |
| 749 |
`\mathsetup{dots, vert, vargreek={\epsilon,\rho}}`. The options are: |
| 750 |
\begitems |
| 751 |
* `dots` sets more intelligent `\dots`, the same as \~`\smartdots`. |
| 752 |
* `interval` sets `\_` as prefix of intervals, see section~\ref[interval]. |
| 753 |
* `vert` sets more intelligent `|`, the same as \~`\smartvert`. |
| 754 |
* `rmsbsp` sets roman sub/supscripts in `[...]`, the same as \~`\rmsbsp`. |
| 755 |
* `ibrackets` sets intelligent brackets, the same as \~`\ibrackets`. |
| 756 |
* `multiprimes` sets double, triple, quadruple primes as active. |
| 757 |
* `flexipa` enables flexible partial symbol, the same as \~`\flexipa`. |
| 758 |
* `mstyle=<style>`, `bstyle=<style>` are math styles explained in section~\ref[mstyle]. |
| 759 |
* `bfserif` sets bold-serif, bold-italic-serif, the same as \~`\bfserif`. |
| 760 |
* `rmchars={<list>}` sets `\rm` for selected characters, the same as \~`\rmchars`, |
| 761 |
see section~\ref[rmchars]. |
| 762 |
* `vargreek={<list>}` sets variants for Greek letetters, the same as \~`\vargreek`, |
| 763 |
see section~\ref[rmchars]. |
| 764 |
* `text={<list>}` sets \~`\textvariables`, \~`\textdigits`, or \~`\textmoremath`, |
| 765 |
see section~\ref[textvars], |
| 766 |
* `enablefic` enables final italic correction of inline-math lists, does |
| 767 |
\~`\enablefic`. |
| 768 |
\enditems |
| 769 |
|
| 770 |
This package is not definitive. I plan to add more features in new versions |
| 771 |
if needed. Moreover, this package gives an example for package writers how |
| 772 |
to write their own packages, see section~\ref[pkgtemplate]. |
| 773 |
|
| 774 |
\sec Controlled sizes of parentheses |
| 775 |
|
| 776 |
If you write `$f(x(y+z))$` then the outer parentheses should be bigger. |
| 777 |
Classical Plain \TeX/ provides macros \O`\bigl`, \O`\bigr`, etc., they can |
| 778 |
be used in this manner: `$f\bigl(x(y+z)\bigr)$`. But the source file looks |
| 779 |
bad with such markup. Better is to say that parentheses have to be bigger |
| 780 |
using a single prefix before functional symbol, i.e. `$\bigp f(x(y+z))$`. |
| 781 |
This should be print the same as previous example with \O`\bigl`, \O`\bigr`. |
| 782 |
|
| 783 |
The prefixes \^`\bigp` (big pair), \^`\bbigp` (bbig pair), \^`\Bigp` (Big pair), |
| 784 |
\^`\biggp` (bigg pair) and \^`\Biggp` (Bigg pair) are provided, |
| 785 |
they can be used before a functional symbol. The scaled parentheses |
| 786 |
surrounding the functional parameter can be (...) or [...] or `\{`...`\}` or |
| 787 |
\{...\}. I.e.\ `\Bigp\Gamma [x]` is the same as `\Gamma \Bigl[x\bigr]`. |
| 788 |
Moreover, the functional parameter gets its own \TeX/ group, so |
| 789 |
`\Bigp G(a\over2)` results to `G\Bigl({a\over2}\bigr)`. |
| 790 |
There are two more prefixes \^`\autop` and \^`\normalp`. First one applies |
| 791 |
`\left`, `\right` to the parentheses of the parameter, second one keeps |
| 792 |
the parentheses unscaled. If you want to scale the parentheses without |
| 793 |
preceding functional symbol then use dot instead this symbol, for example |
| 794 |
`\Bigp.(a)` is equal to `\Bigl(a\Bigr)`. |
| 795 |
|
| 796 |
Examples: |
| 797 |
\begtt |
| 798 |
$$ |
| 799 |
\displaylines{ |
| 800 |
\biggp F (1+\Bigp g (1+\bbigp f(1+\bigp f(1+f(x))))) \cr |
| 801 |
f(x(y+z)),\quad \bigp f(x(y+z)),\quad \autop f (a\over b)\cr |
| 802 |
\Bigp f(a\over b+c),\quad \Bigp f(x^2\over2),\quad \Bigp.(a\over b) |
| 803 |
} |
| 804 |
$$ |
| 805 |
\endtt |
| 806 |
gives: |
| 807 |
$$ |
| 808 |
\displaylines{ |
| 809 |
\biggp F (1+\Bigp g (1+\bbigp f(1+\bigp f(1+f(x))))) \cr |
| 810 |
f(x(y+z)),\quad \bigp f(x(y+z)),\quad \autop f (a\over b)\cr |
| 811 |
\Bigp f(a\over b+c),\quad \Bigp f(x^2\over2),\quad \Bigp.(a\over b) |
| 812 |
} |
| 813 |
$$ |
| 814 |
|
| 815 |
\sec Intelligent `\dots` like in AMS\TeX |
| 816 |
|
| 817 |
AMS\TeX/ provides \o`\dots` macro which works depending on the context. If it is surrounded |
| 818 |
by symbols like $+$, $-$, $=$ then it works like \o`\cdots`, if it is surrounded by |
| 819 |
comma or similar symbols then it works like \o`\ldots`. |
| 820 |
This package keeps \o`\dots` unchanged but it is changed (and behaves as |
| 821 |
mentioned above) after the \^`\smartdots` declaration. |
| 822 |
|
| 823 |
\smartdots |
| 824 |
You can try this after the \^`\smartdots` declaration: |
| 825 |
\medskip |
| 826 |
|
| 827 |
`$a_1, a_2, \dots, a_n$ ` prints $a_1, a_2, \dots, a_n$, |
| 828 |
|
| 829 |
`$a_1 + a_2 + \dots + a_n$ ` prints $a_1 + a_2 + \dots + a_n$, |
| 830 |
|
| 831 |
|
| 832 |
\sec[interval] Creating intervals more comfortable |
| 833 |
|
| 834 |
Several math books uses `\langle`, `\rangle` for denoting the interval boundary |
| 835 |
if the boundary number is element of the interval too. For example `$\langle 0,1)$` |
| 836 |
is printed as $\langle 0,1)$ and it |
| 837 |
means an interval from zero to one, zero is element of the interval but one |
| 838 |
isn't. The \TeX/ source of such math books looks badly because we cannot mark |
| 839 |
them like \code{$<0,1)$} because it prints $\string<0,1)$ but we want $\langle 0,1)$. |
| 840 |
|
| 841 |
This package creates the \^`\.interval` macro which can be set to be equal to `\_` |
| 842 |
(using the `interval` option). Then `\_` can be used just before the interval |
| 843 |
as a prefix. The \code{<} or `>` are automatically replaced by `\langle`, `\rangle` |
| 844 |
if `\_` is prefixed. So, you can write \code{$\\_<0,1)$} or `$\_(0,1>$` or \code{$\\_<0,1>$} |
| 845 |
or `$\_(0,1)$` in order to get $\langle0,1)$ or $(0,1\rangle$ or $\langle0,1\rangle$ |
| 846 |
or $(0,1)$. The source with such intervals looks better. |
| 847 |
|
| 848 |
Note that `interval` option does `\let\_=`\^`\.interval`, so the original |
| 849 |
meaning of the `\_` control sequence (from plain \TeX/) is re-defined. |
| 850 |
The `\_` control sequence can be used for this purpose because |
| 851 |
the next token is `(` or \code{<}, i.e. it is non-letter. |
| 852 |
|
| 853 |
|
| 854 |
\sec Using vertical bars with better spacing |
| 855 |
|
| 856 |
The character \"`|`" is declared with Ord class by default in Plain \TeX/, |
| 857 |
but we are using it typically in the context `$|x|$`. It means there should |
| 858 |
be Open and Close classes. This example gives correct result but try to use |
| 859 |
`$|-1|$` which gives bad spacing: $|-1|$. |
| 860 |
And `$||x||$` gives bad result too. |
| 861 |
|
| 862 |
When you declare \^`\smartvert`, these problems are solved. Moreover, the |
| 863 |
\"`|`" or \"`||`" are expected to be always in pairs and they are scaled by |
| 864 |
`\left` and `\right` primitives automatically. If you don't want to use it |
| 865 |
in a pair, use \^`\singlevert` or `\big|`, or `\Big|` etc. Compare |
| 866 |
the result of `$|\sum a_n|+||x||$`: |
| 867 |
$$ |
| 868 |
\eqalign{ |
| 869 |
|\sum a_n|+||x|| &\quad \hbox{if \scantextokens{`\smartvert`} isn't initialized,}\cr |
| 870 |
\smartvert |
| 871 |
|\sum a_n|+||x|| &\quad \hbox{if \scantextokens{`\smartvert`} is initialized.} |
| 872 |
} |
| 873 |
$$ |
| 874 |
|
| 875 |
|
| 876 |
\sec Roman subscript and superscript in `[...]` |
| 877 |
|
| 878 |
When you declare \^`\rmsbsp`, then you can write `x_[text]` or `x^[text]` |
| 879 |
and it is equivalent to `x_{\mathbox{text}}` or `x^{\mathbox{text}}`. |
| 880 |
|
| 881 |
|
| 882 |
\sec Basic and typical macros for sets, functions etc. |
| 883 |
|
| 884 |
These typical macros are defined in `math.opm`: |
| 885 |
\^`\N` for $\N$, \^`\Z` for $\Z$, \^`\Q` for $\Q$, \^`\R` for $\R$, \^`\C` for $\C$, |
| 886 |
\^`\sgn`, \^`\argmin`, \^`\argmax`, \^`\grad`, \^`\rank`, \^`\tr`, \^`\diag`, \^`\Span`, \^`\Rng`, |
| 887 |
\^`\Null`, \^`\Ker`, \^`\Res`, \^`\tg`, \^`\cotg`, \^`\arctg`, \^`\arccotg`. |
| 888 |
|
| 889 |
I hate the \^`\frac`, \^`\dfrac` and \^`\tfrac` macros defined in \LaTeX/ |
| 890 |
but someone may want to use them. This package defines them. |
| 891 |
But I note: usage of `$1\over2$` for $1\over2$ |
| 892 |
is much more understandable than \LaTeX's `$\frac12$`. |
| 893 |
|
| 894 |
The vectors and matrices are usually printed by `{\bf A}{\bf x}`. |
| 895 |
The package provides a shortcut `\.<letter>` to do the same, so user can write |
| 896 |
`\.A\.x` for multiplication of a matrix $\.A$ by a vector $\.x$. |
| 897 |
We strictly don't recommend usage of `\.`, `\v`, `\=`, etc.\ for accents, so |
| 898 |
`math.opm` can define `\.` differently than the classical meaning \"dotaccent". |
| 899 |
|
| 900 |
|
| 901 |
\sec Extensible arrows |
| 902 |
|
| 903 |
You can use \^`\exw <arrow> <limits>`, where <arrow> is arbitrary horizontal |
| 904 |
arrow, for example `\leftarrow`, `\Leftrightarrow`, `\mapsto`, `\hookleftarrow`, `=`, |
| 905 |
`-`. The parameter <limit> is limits specification, for example `^a_b` or `_{\rm text}`. |
| 906 |
The given arrow is printed as mathrel atom with given limits above and |
| 907 |
below. The arrow is automatically extended in order to be slightly wider |
| 908 |
that the widest limit text. If you give an optional parameter: |
| 909 |
\^`\exw[<dimen>] <arrow> <limits>` then the arrow is printed with given |
| 910 |
<width> regardless of widths of limits. The `\exw` means extend width. |
| 911 |
|
| 912 |
You can use \^`\exh[<dimen>] <arrow>`, where <arrow> is arbitrary vertical arrow. |
| 913 |
The arrow extends its height to given <dimen> and the result is packed to |
| 914 |
`\vcenter`, i.e. the math axis is respected. |
| 915 |
|
| 916 |
Examples: `$\exw\rightarrowtail _{\rm long\ text}^x$` gives |
| 917 |
$\exw\rightarrowtail _{\rm long\ text}^x$, |
| 918 |
|
| 919 |
`$\exh[2em]\upwhitearrow$` gives $\exh[2em]\upwhitearrow$,\quad |
| 920 |
`$\exw[3em]\equiv^{\rm def}$` gives $\exw[3em]\equiv^{\rm def}$. |
| 921 |
\smallskip |
| 922 |
|
| 923 |
You can control the size by which the horizontal arrow is larger than its |
| 924 |
limits by the \^`\exwdist` register. Default is `\exwdist=1.5pt`. |
| 925 |
|
| 926 |
See also \^`\harrowto` and \^`\varrowto` macros. They extend the given |
| 927 |
horizontal or vertical arrow to given <dimem> and they are used for |
| 928 |
implementation of \^`\exw` and \^`\exh` macros. |
| 929 |
|
| 930 |
|
| 931 |
\sec System of equations printed by `\eqsystem` |
| 932 |
|
| 933 |
The \^`\eqsystem``{<equations>}` enables to write systems of equations more |
| 934 |
comfortably. The equations are separated by `\cr` and the aligned columns |
| 935 |
are separated by space. For example: |
| 936 |
\begtt |
| 937 |
$$ |
| 938 |
\eqsystem{ x + y - 2z = 10 \cr |
| 939 |
2x - 7y + z = 13 \cr |
| 940 |
-x + y ~ ~ = -5 } |
| 941 |
$$ |
| 942 |
\endtt |
| 943 |
prints |
| 944 |
$$ |
| 945 |
\eqsystem{ x + y - 2z = 10 \cr |
| 946 |
2x - 7y + z = 13 \cr |
| 947 |
-x + y ~ ~ = -5 } |
| 948 |
$$ |
| 949 |
Note that empty columns have to be filled by `~` mark. |
| 950 |
There are columns for variables (possibly multiplied by a constant) and for |
| 951 |
binary operators `+` and `-` or relations `=`, `>` etc. or constants. Each column |
| 952 |
is aligned to right. The number of columns is unlimited (we have 7 columns in |
| 953 |
the example above). All given equations are packed to the `\vcenter` box. |
| 954 |
|
| 955 |
The spaces between lines are enlarged by the value of \^`\eqskip` |
| 956 |
and the horizontal spaces between columns are enlaged by \^`\eqsep`. |
| 957 |
Both registers are set to 0\,pt by default. |
| 958 |
|
| 959 |
The \^`\eqfil` register is \"left filler" applied to each item in the \^`\eqsystem` columns. |
| 960 |
Its default is `\eqfil={\hfill}`. The right filler is hardwired and it is `\hfil`. |
| 961 |
This makes columns aligned to right by default. For example, when you set |
| 962 |
`\eqfil={\hfil}` then you have columns centered. |
| 963 |
|
| 964 |
The \^`\eqsystem` macro allows optional parameter which is processed inside |
| 965 |
group before printing equations. You can do local settings here, for example |
| 966 |
`\eqsystem[\eqskip=2pt \eqsep=5pt]{...}`. |
| 967 |
|
| 968 |
|
| 969 |
\sec Equation marks in atypical cases |
| 970 |
|
| 971 |
We may want to put equation marks `\eqmark` in more lines in display mode when we |
| 972 |
are using macros not designed for such case. For example in the lines of |
| 973 |
the `\cases` macro: |
| 974 |
|
| 975 |
\begtt |
| 976 |
$$ f(x) = \cases{0 & for $x<0$\toright\eqmark \cr |
| 977 |
1 & otherwise\toright\eqmark } $$ |
| 978 |
\endtt |
| 979 |
This puts the equation marks to the right margin in each line generated by |
| 980 |
the `\cases` macro. |
| 981 |
$$ f(x) = \cases{0 & for $x\string<0$\toright\eqmark \cr |
| 982 |
1 & otherwise\toright\eqmark } |
| 983 |
$$ |
| 984 |
The \^`\toright`\o`\eqmark` is used here. Analogically, |
| 985 |
\^`\toleft`\o`\eqmark` puts the equation mark to the left margin. |
| 986 |
The position of these marks are correct after second or more \TeX/ run |
| 987 |
because \TeX/ needs to read data from its previous run in this case. |
| 988 |
|
| 989 |
Sometimes we want to declare a bunch of equations with the same numeric |
| 990 |
equation marks but with different suffixes, for example (1.1a), (1.1b). We |
| 991 |
provide the macro \^`\subeqmark``<suffix>` here. |
| 992 |
If `<suffix>` is `a` or `A` then \^`\subeqmark` starts a new bunch of |
| 993 |
equations with the next number. Following `\subeqmark b`, `\subeqmark c`, |
| 994 |
etc.\ use the same equation number, they differ only by given suffixes: |
| 995 |
You can put `[<label>]` after `<suffix>` for referencing purposes. |
| 996 |
Example: |
| 997 |
|
| 998 |
\begtt |
| 999 |
$$ \eqsystem[\eqskip=3pt]{ |
| 1000 |
x + 2y + 3z = 600 \toright{\subeqmark a}\cr |
| 1001 |
12x + y - 3z = -7 \toright{\subeqmark b[label]}\cr |
| 1002 |
4x - y + 5z = 5 \toright{\subeqmark c}\cr } |
| 1003 |
$$ |
| 1004 |
The equation~\ref[label] has negative right side. Moreover, it applies |
| 1005 |
$$ |
| 1006 |
a^2 + b^2 = c^2. \eqmark |
| 1007 |
$$ |
| 1008 |
\endtt |
| 1009 |
prints |
| 1010 |
$$ \eqsystem[\eqskip=3pt]{ |
| 1011 |
x + 2y + 3z = 600 \toright{\subeqmark a}\cr |
| 1012 |
12x + y - 3z = -7 \toright{\subeqmark b[label]}\cr |
| 1013 |
4x - y + 5z = 5 \toright{\subeqmark c}\cr |
| 1014 |
} |
| 1015 |
$$ |
| 1016 |
The equation~\ref[label] has negative right side. Moreover, it applies |
| 1017 |
$$ |
| 1018 |
a^2 + b^2 = c^2. \eqmark |
| 1019 |
$$ |
| 1020 |
|
| 1021 |
\sec Setting more spaces in script styles |
| 1022 |
|
| 1023 |
Classical \TeX/ puts \n`\thickmuskip` around relations and \n`\medmuskip` around |
| 1024 |
binary operators only in \n`\textstyle` and \n`\displaystyle`. These spaces are |
| 1025 |
missing in \n`\scripstyle` and \n`\scriptscriptstyle`. It means that we get, for |
| 1026 |
example |
| 1027 |
$$ |
| 1028 |
\sum_{i=j+1}^\infty a_i |
| 1029 |
$$ |
| 1030 |
The formula $i=k+1$ has no spaces here, so it looks unattractive. \LuaTeX/ |
| 1031 |
provides better control of all such spaces, so `math.opm` declares the macro |
| 1032 |
\^`\scriptspaces``{<s-rel>}{<s-bin>}{<ss-rel>}{<ss-bin>}` for setting |
| 1033 |
these spaces. <s-rel> is \"muskip" value used around relations in \n`\scriptstyle`, |
| 1034 |
<s-bin> is \"muskip" used around binary operators in \n`\scriptstyle` and the |
| 1035 |
last two parameters gives these spacing in \n`\scriptscriptstyle`. |
| 1036 |
If a parameter is empty, it means that it has zero value. |
| 1037 |
For example after `\scriptspaces {2mu}{1.3mu}{}{}` |
| 1038 |
the formula mentioned above looks like |
| 1039 |
$$ |
| 1040 |
\scriptspaces {2mu}{1.3mu}{}{} |
| 1041 |
\sum_{i=j+1}^\infty a_i |
| 1042 |
$$ |
| 1043 |
It looks better, doesn't it? |
| 1044 |
|
| 1045 |
\sec[mstyle] `\bf` and `\bi` shapes, math styles |
| 1046 |
|
| 1047 |
\OpTeX/ sets `\bf` and `\bi` math selectors as sans serif, because this |
| 1048 |
follows the old traditional math typesetting of vectors and matrices. |
| 1049 |
But Knuth's \TeX/ has another default behavior:`\bf` and `\bi` select serifed |
| 1050 |
shapes. So, many people consider it as a standard. You can declare \^`\bfserif` if |
| 1051 |
you want serifed `\bf` and `\bi` math letters. |
| 1052 |
|
| 1053 |
Moreover, this package provides `mstyle=<style>` and `bstyle=<style>` options. |
| 1054 |
The `mstyle` option can be `TeX`, `ISO`, `french` or `upright` and `bstyle` |
| 1055 |
option can be `TeX`, `OpTeX`, `ISO`, `upright`. The `mstyle` and `bstyle` |
| 1056 |
options set the upright/italic versions of math Latin/Greek variables in the same |
| 1057 |
manner as `math-style` and `bold-style` options (from \LaTeX's |
| 1058 |
`unicode-math`) do it. The `bstyle=OpTeX` sets sans serif bold variables, |
| 1059 |
which is default in \OpTeX. |
| 1060 |
|
| 1061 |
\sec[rmchars] Selected upright letters and variants for Greek letters |
| 1062 |
|
| 1063 |
Some mathematicians claim that the letters $e$, $i$ and $\pi$ in meaning |
| 1064 |
\"a constant" should be printed in upright form. \TeX/ prints all variables in |
| 1065 |
math italic, but this package enables to set exceptions for some letters. |
| 1066 |
For example after \^`\rmchars``{e, i, \pi}`, all occurrences of these three letters |
| 1067 |
in math mode will be set in upright shape. If you set this, then the |
| 1068 |
well-known math identity `$e^{i\pi}=-1$` looks like this: |
| 1069 |
$$ |
| 1070 |
{\rm e}^{\rm i\muppi} = -1, \qquad \hbox{compare with:}\quad e^{i\pi} = -1. |
| 1071 |
$$ |
| 1072 |
The syntax is \^`\rmchars``{<list>}`, where <list> is a list of characters |
| 1073 |
separated by (optional) commas. The character is `a` to `z` or `A` to `Z` or |
| 1074 |
`\alpha` to `\omega`. |
| 1075 |
|
| 1076 |
If you set a character by `\rmchars` globally and you want to print it in italic |
| 1077 |
locally then use `\mit`, for example `{\mit e}` prints $e$. |
| 1078 |
|
| 1079 |
Several Greek letters have their variant shape: |
| 1080 |
`\epsilon`~$\epsilon$, `\varepsilon`~$\varepsilon$, |
| 1081 |
`\sigma`~$\sigma$, `\varsigma`~$\varsigma$, |
| 1082 |
`\phi`~$\phi$, `\varphi`~$\varphi$, |
| 1083 |
`\theta`~$\theta$, `\vartheta`~$\vartheta$, |
| 1084 |
`\pi`~$\pi$, `\varpi`~$\varpi$, |
| 1085 |
`\kappa`~$\kappa$, `\varkappa`~$\varkappa$, |
| 1086 |
`\rho`~$\rho$, `\varrho`~$\varrho$, |
| 1087 |
`\Theta`~$\Theta$, `\varTheta`~$\varTheta$. |
| 1088 |
Maybe, there is a tradition of usage variant shapes instead of standard ones |
| 1089 |
in your mathematics field. Then you can use |
| 1090 |
\^`\vargreek``{<list>}`, where <list> includes the list of no-var control |
| 1091 |
sequences for these letters (separated by optional comma). |
| 1092 |
For example `\vargreek{\epsilon \phi \rho}` causes that `\epsilon` is |
| 1093 |
printed as $\varepsilon$, `\phi` as $\varphi$ and `\rho` as $\varrho$. |
| 1094 |
|
| 1095 |
If you want to declare a Greek letter by both `\vargreek` and `\rmchars`, |
| 1096 |
use `\rmchars` first. |
| 1097 |
|
| 1098 |
The package provides two options `rmchars` and `vargreek`. The equation |
| 1099 |
sign must follow and then the `{<list>}` with syntax mentioned above. For example |
| 1100 |
`\mathsetup{vargreek={\epsilon,\rho}}`. |
| 1101 |
|
| 1102 |
\sec[ibrackets] Intelligent brackets |
| 1103 |
|
| 1104 |
Some mathematicians write open intervals like this: $\left]0,1\right[$. But |
| 1105 |
\TeX/ is not ready (by default) to set proper spaces around these symbols, |
| 1106 |
because `[` is set as `\mathopen` and `]` is set as `\mathclose` atom. When |
| 1107 |
\^`\ibrackets` is declared, then the characters `[` and `]` are more intelligent: |
| 1108 |
the spaces around then are correct in both cases: `$x\in [0,1]$` and |
| 1109 |
`$x\in ]0,1[$`. See `ibrackets` \LaTeX/ package for more detail. |
| 1110 |
|
| 1111 |
\sec[multiprime] Double, triple, quadruple primes |
| 1112 |
|
| 1113 |
\def\tprime{\hbox to.5em{\tt\hss'\kern-3.7pt'\kern-3.7pt'\hss}} |
| 1114 |
|
| 1115 |
The single quotation character is used as derivation symbol, for example |
| 1116 |
`$f'$`. It is defined (in plain \TeX/ and in \OpTeX/ too) as a math-active |
| 1117 |
character which internally does `^\prime`. Moreover it checks if another |
| 1118 |
prime symbol follows like in this example: `$f'''$`. Then the macro does a |
| 1119 |
bit more work (we don't dive to details here). On the other hand, the double |
| 1120 |
prime (or triple or quadruple) symbols are provided in OpenType math fonts |
| 1121 |
and they are not defined as active macros. The reason is that these symbols |
| 1122 |
are shifted to the right position by default in their text-style sizes. So, |
| 1123 |
we can write `$f`\tprime`$` and we get~$f‴$. But the concept introduced by |
| 1124 |
D. Knuth works too: `$f^`\tprime`$` gives $f^‴$. The reason it works is that |
| 1125 |
the script and scriptscript style sizes of these symbols are implemented in |
| 1126 |
the OpenType font similarly like the original `\prime` symbol drawn by D. |
| 1127 |
Knuth in Computer Modern fonts (i.e. they are bigger and at the baseline). |
| 1128 |
|
| 1129 |
This mixed concept provided by fonts brings into a problem: if the `f`{\tprime} |
| 1130 |
is used in script style, then we get unaccepted result. For example |
| 1131 |
`$f`\tprime`\over2$` gives $f‴\over2$. Of course, we can use `$f^`\tprime`\over2$` |
| 1132 |
but previous notation is more natural. If you are using `$f`\tprime`$` etc. |
| 1133 |
in your \TeX/ source in various sizes, you can use the option `multiprimes` |
| 1134 |
or use the \^`\multiprimes` macro. It sets the symbols for double, triple and |
| 1135 |
quadruple primes as active characters and they are defined as `^` followed |
| 1136 |
by the character. Now, the notation `$f`\tprime`$` works in all sizes, but |
| 1137 |
notation `$f^`\tprime`$` doesn't work. |
| 1138 |
|
| 1139 |
\sec[flexipa] Flexible partial symbol $\partial$ |
| 1140 |
|
| 1141 |
Classical \TeX/ with Computer Modern fonts uses slanted `\partial` symbol |
| 1142 |
$\mitpartial$. On the other hand, default setting of Unicode math gives |
| 1143 |
upright `\partial` $\rm\partial$ but six variants of this symbol are provided: |
| 1144 |
roman (upright) \^`\mrmpartial` $\mrmpartial$, bold \^`\mbfpartial` $\mbfpartial$, |
| 1145 |
italic \^`\mitpartial` $\mitpartial$, bold italic \^`\mbfitpartial` $\mbfitpartial$, |
| 1146 |
bold sans serif \^`\mbfsanspartial` $\mbfsanspartial$, bold italic sans serif |
| 1147 |
\^`\mbfitsanspartial` $\mbfitsanspartial$. |
| 1148 |
|
| 1149 |
When you declare \^`\flexipa` or \^`\flexiblepartial` or use the `flexipa` |
| 1150 |
package option, then the `\partial` symbols get italic variant as default |
| 1151 |
and behaves like others Greek symbols: it changes its variant according to |
| 1152 |
the `\rm`, `\it`, `\bf`, `\bi` selectors in math mode. You can declare what |
| 1153 |
variant of the `\partial` character will be shown at what selector. This can |
| 1154 |
be done by the \^`\partialsymbolvars`~`<default> <rm> <bf> <it> <bi>` macro. |
| 1155 |
Each of these five parameters can be `{rm}` or `{bf}` or `{it}` or `{bfit}` |
| 1156 |
or `{bfsans}` or `{bfitsans}`. For example the third parameter declares |
| 1157 |
what variant of the partial symbol is printed when `\bf` selector is used |
| 1158 |
in math mode. The `\flexipa` macro runs the following default setting: |
| 1159 |
\begtt |
| 1160 |
\partialsymbolvars {it} {rm} {bfsans} {it} {bfitsans} |
| 1161 |
\endtt |
| 1162 |
It means that default is italic variant and when `\rm` is selected then roman |
| 1163 |
(upright) variant is printed, when `\bf` is selected then bold sans serif |
| 1164 |
variant is printed etc. |
| 1165 |
|
| 1166 |
|
| 1167 |
\sec[textvars] Variables and digits from currently used text font |
| 1168 |
|
| 1169 |
When Unicode math font is loaded then all variables and digits are printed |
| 1170 |
from it in math mode. If you are using text fonts with another visual |
| 1171 |
concept then you can see a differences when you use digits in text mode and in |
| 1172 |
math mode. You can specify \^`\textdigits` if you want to use digits from |
| 1173 |
current text `\rm` font in math and \^`\textvariables` if you want to use |
| 1174 |
variables from current text `\it` font in math. |
| 1175 |
You can set printing of |
| 1176 |
+−*/=<>\{([])\} from text `\rm` font in math by \^`\textmoremath`. |
| 1177 |
You can inspire from the \^`\textmoremath` macro and set more similar |
| 1178 |
characters from text font. |
| 1179 |
|
| 1180 |
You have to load a text font family (using \o`\fontfam` for example) first and |
| 1181 |
use \^`\textdigits`, \^`\textvariables`, \^`\textmoremath` after it. This is |
| 1182 |
due to these macros reads {\em current} text \o`\rm` and \o`\it` fonts and set |
| 1183 |
them to math printing. |
| 1184 |
|
| 1185 |
Note that we cannot avoid a visual incompatibility of parentheses when they |
| 1186 |
are use in the context \n`\left`, \n`\right`. These parentheses must be printed |
| 1187 |
from math font always because text font is unable to create bigger versions of |
| 1188 |
them. |
| 1189 |
|
| 1190 |
The package provides the option `text={<list of words>}`, each <word> from the |
| 1191 |
<list> can be `digits` or `variables` or `moremath`. It runs corresponding macro(s) |
| 1192 |
described above. For example `\mathsetup{text=digits variables}` is equal to the |
| 1193 |
declaration of `\textdigits` `\textvariables`. |
| 1194 |
|
| 1195 |
\sec Adding a new math alphabet from a text font |
| 1196 |
|
| 1197 |
Each individual Unicode math font includes several math alphabets together: default |
| 1198 |
italic shape and others, which can be selected by `\rm`, `\it`, `\bf`, |
| 1199 |
`\bi`, `\tt`, `\cal`, `\frak`, `\bbchar` in math mode. For example, if you |
| 1200 |
use `\frak` in math mode, the fracture shapes from loaded Unicode math font are |
| 1201 |
used. |
| 1202 |
|
| 1203 |
If you have a text font with a special alphabet, you can use it in your math formulas |
| 1204 |
by a new math selector declared by the \~`\mathselector` macro. For example: |
| 1205 |
|
| 1206 |
\begtt |
| 1207 |
\fontfam[lm] |
| 1208 |
\load[math] |
| 1209 |
\font\missaali=[Missaali-Regular] % Bold fraktur |
| 1210 |
\mathselector \bfrak {\missaali} {\missaali} {} {} |
| 1211 |
|
| 1212 |
Test: $a = {\frak A}, b = {\bfrak A}_{\bfrak C}$. |
| 1213 |
\endtt |
| 1214 |
This example declares a new math selector `\bfrak`. When `\bfrak` is used in math mode, |
| 1215 |
then the letters are rendered from `Missali-Regular.otf` font. |
| 1216 |
|
| 1217 |
\^`\mathselector` `\sequence {<fontspec-A>} {<fontspec-B>} {<factor>} {<ffeatures>}` |
| 1218 |
declares a new font selector `\sequence` which can be used in math mode. |
| 1219 |
This selector selects a text font given by <fontspec-A> in normal math mode |
| 1220 |
and by <fontspec-B> in `\boldmath`. |
| 1221 |
If <fontspec-B> is empty then faked bold font declared by <fontspec-A> |
| 1222 |
is used for `\boldmath`. <fontspec-A> cannot be empty. |
| 1223 |
|
| 1224 |
The <fontspec-A> and <fontspec-B> declare text fonts. They can be: |
| 1225 |
\begitems |
| 1226 |
* a font switch deflared by the `\font` primitive, |
| 1227 |
* an optional family selector followed by optional font modifiers |
| 1228 |
followed by a variant selector. |
| 1229 |
The actual font selected by this rule is configured as math selector. |
| 1230 |
\enditems |
| 1231 |
|
| 1232 |
The <factor> parameter gives correction scaling factor according to the size |
| 1233 |
of the main Unicode math font. If it is empty then factor 1 is assumed. |
| 1234 |
|
| 1235 |
The <ffeatures> parameter enables you to give font features used for loading |
| 1236 |
given fonts. If it is empty, then default font features |
| 1237 |
`mode=base;script=latn;` are used. |
| 1238 |
|
| 1239 |
\^`\mathselector` `\sequence` declares internally a new math family with |
| 1240 |
the name `\sequence_fam`. The `\sequence` selector switches to this |
| 1241 |
family. So, the declared text fonts work in all math sizes but only for math |
| 1242 |
alphabets, Greek letters and digits, because other math symbols (+, =, etc.) are |
| 1243 |
bounded (by default) to the fixed math family 1 where Unicode math font is loaded. |
| 1244 |
|
| 1245 |
Other example: |
| 1246 |
\begtt |
| 1247 |
\fontfam[lm] |
| 1248 |
\mathselector \textit {\it} {\bi} {} {} |
| 1249 |
$AVA$ -- default italic variables from math font.\par |
| 1250 |
$\it AVA$ -- default italic letters from math font.\par |
| 1251 |
$\textit AVA$ -- italic letters from text font. |
| 1252 |
\endtt |
| 1253 |
You will probably see no difference between these three examples. Where is |
| 1254 |
the difference? `$AVA$` uses italic shapes from the |
| 1255 |
Unicode math font, `script=math` is specified. Italic corrections between |
| 1256 |
characters are inserted. `$\it AVA$` uses the same shapes from the same math font, |
| 1257 |
but `script=latn`. This disables italic corrections between |
| 1258 |
characters and enables kerning and ligatures. But typical Unicode math font |
| 1259 |
doesn't include tables for kerning and ligatures. So, these features |
| 1260 |
typically don't work. Finally `$\textit AVA$` uses shapes from text font like |
| 1261 |
`{\it ABC}` in text mode. If the font has data for kerning and ligatures |
| 1262 |
(which is probably true) then you get this feature in math formulas. |
| 1263 |
|
| 1264 |
When you re-declare `\rm`, `\it`, `bf`, `\bi` or `\tt` by the `\mathselector` macro, |
| 1265 |
then these selectors keep their meaning used in text mode but re-define |
| 1266 |
their behavior in math mode according to the declaration. For example |
| 1267 |
`\mathselector \it {\it} {\bi} {} {}` declares new behavior of `\it` in math mode |
| 1268 |
but `\it` is unchanged in text mode. |
| 1269 |
|
| 1270 |
|
| 1271 |
\sec Replacing all missing math characters from another font |
| 1272 |
|
| 1273 |
If we load an additional math font by \o`\addUmathfont`, for example: |
| 1274 |
\begtt |
| 1275 |
\addUmathfont \xits {[XITSMath-Regular]}{} {[XITSMath-Bold]}{} {} |
| 1276 |
\endtt |
| 1277 |
then we can re-declare the code of arbitrary math character in such a way |
| 1278 |
that it is printed from this additional font. It can be done by \o`\mathchars` |
| 1279 |
provided by \OpTeX/, for example: |
| 1280 |
\begtt |
| 1281 |
\mathchars \xits {\leftdasharrow \updasharrow \rightdasharrow \downdasharrow} |
| 1282 |
\endtt |
| 1283 |
But this method enables to re-declare only selected characters. Maybe, you |
| 1284 |
want to re-declare {\em all} Unicode math characters which are missing in the main font. |
| 1285 |
This can be done by \^`\replacemissingchars`\,`<family>` provided by the |
| 1286 |
`math.opm`. For example |
| 1287 |
\begtt |
| 1288 |
\replacemissingchars \xits |
| 1289 |
\endtt |
| 1290 |
replaces all characters missing in the main font by characters from the |
| 1291 |
`\xits` declared by previous \o`\addUmathfont`. |
| 1292 |
The names of all replaced characters are printed in log file. |
| 1293 |
If the additional math font doesn't provide all Unicode math characters |
| 1294 |
then you can load a next additional math font using another \o`\addUmathfont` and do |
| 1295 |
\^`\replacemissingchars`\,`<family>` again. Only those characters not replaced |
| 1296 |
by previous steps are replaced. |
| 1297 |
|
| 1298 |
|
| 1299 |
\sec Final italic correction |
| 1300 |
|
| 1301 |
{\bf Note:} {\em This issue was corrected in \LuaTeX/ version 1.24, so the |
| 1302 |
\^`\enablefic` is no longer needed. It prints only warning when \LuaTeX\,$\succeq$1.24 |
| 1303 |
and does the following described feature when \LuaTeX\,$\prec$1.24. We will completely remove this |
| 1304 |
feature from future versions of math.opm package.} |
| 1305 |
|
| 1306 |
Classical \TeX/ adds italic correction after each Ord atom with a single |
| 1307 |
letter from math italic font including the last one in inline-math. \LuaTeX/ |
| 1308 |
and \OpTeX/ does the same only when classical `tfm` math fonts are used. When |
| 1309 |
you switch to Unicode math, the italic correction of the last glyph of the |
| 1310 |
inline-math list is lost, unfortunately. Try this: |
| 1311 |
|
| 1312 |
\begtt |
| 1313 |
$T$' the italic correction after $T$ is inserted (classical fonts) |
| 1314 |
|
| 1315 |
\fontfam[lm] |
| 1316 |
$T$' the italic correction after $T$ isn't inserted (Unicode fonts) |
| 1317 |
\bye |
| 1318 |
\endtt |
| 1319 |
|
| 1320 |
This package provides the \^`\enablefic` command which enables the classical TeX |
| 1321 |
feature: the final italic correction of the inline-math list is automatically added. |
| 1322 |
|
| 1323 |
When \^`\enablefic` (or `enablefic` option) is declared then you can control |
| 1324 |
the behavior of this feature by the \^`\finalitalcorr` register: if it is positive |
| 1325 |
then the feature is activated and if it is zero, the feature is deactivated. |
| 1326 |
The \^`\enablefic` macro sets \^`\finalitalcorr``=1`. |
| 1327 |
|
| 1328 |
|
| 1329 |
\sec Miscellaneous commands |
| 1330 |
|
| 1331 |
I created various commands at the requests of users. They asked me to create |
| 1332 |
commands similar to ones from \LaTeX/ packages. |
| 1333 |
|
| 1334 |
\^`\mathclap``{<formula>}` creates `{\hbox to0pt{\hss $<formula>$\hss}}` and |
| 1335 |
respects the math style.\nl |
| 1336 |
\^`\mathrlap``{<formula>}` and \^`\mathllap``{<formula>}` is \O`\rlap` and |
| 1337 |
\O`\llap` analogue of \^`\mathclap`. |
| 1338 |
|
| 1339 |
\^`\scanlimits``\macro`<limits> transforms the parameters given in <limits> |
| 1340 |
(there are `^` or `_` or both in any order) to two parameters `{<sup>}{<sub>}`. |
| 1341 |
The `\macro` may have simply two parameters `#1` and `#2` declared and the |
| 1342 |
macro-programer is sure, that `#1` is superscript and `#2` subscript. |
| 1343 |
Examples: |
| 1344 |
\begtt |
| 1345 |
\scanlimits \macro _{aa} % expands to \macro {}{aa} |
| 1346 |
\scanlimits \macro ^b % expands to \macro {b}{} |
| 1347 |
\scanlimits \macro _{aa} ^b % expands to \macro {b}{aa} |
| 1348 |
\scanlimits \macro ^b_{aa} % expands to \macro {b}{aa} |
| 1349 |
\scanlimits \macro . % expands to \macro {}{}. |
| 1350 |
\scanlimits {\macro XY} _a^{bb} % expands to \macro XY{bb}{a} |
| 1351 |
\endtt |
| 1352 |
|
| 1353 |
\sec[pkgtemplate] General recommendation for writing \OpTeX/ packages |
| 1354 |
|
| 1355 |
This section has nothing common with the subject of this package but this package |
| 1356 |
can serve as inspiration for another package writers. It should be a template |
| 1357 |
for another `<pkg>.opm` files. We emphasize several principles here. |
| 1358 |
The basic information can be found in |
| 1359 |
\ulink[https://petr.olsak.net/ftp/olsak/optex/optex-doc.pdf\#ref:basic-code] |
| 1360 |
{section 2.2} of the \OpTeX/ manual. |
| 1361 |
Try to run\fnote{Run it three times because Table of contents and Index are created.} |
| 1362 |
\begtt |
| 1363 |
optex -jobname math-doc '\docgen math' |
| 1364 |
\endtt |
| 1365 |
for creating this documentation. You can see (from the log file) that the |
| 1366 |
`math.opm` is read four times during this process. First one is due to |
| 1367 |
\o`\docgen`~`math`. It skips the part before \o`\_endcode` and searches the |
| 1368 |
following {`\_doc...\_cod`} pair in the file and processes it (see the end |
| 1369 |
of the file `math.opm`). The macros and main instruction about generating |
| 1370 |
toc, index, etc.\ are here. First instruction is \o`\load``[doc,math]` which |
| 1371 |
initializes `doc` mode of \OpTeX/ and loads `math.opm` secondly because we |
| 1372 |
want to show some effects provided by this package. Then there is |
| 1373 |
\o`\printdoctail`~`math.opm` which loads the `math.opm` again and prints the |
| 1374 |
documentation starting from \o`\_endcode`. Finally, there is |
| 1375 |
\o`\printdoc`~`math.opm` which prints the codes mixed by the documentation |
| 1376 |
text inside pairs {`\_doc...\_cod`}. This causes the fourth loading of the |
| 1377 |
`math.opm` file. |
| 1378 |
|
| 1379 |
The first part of the `math.opm` file looks like: |
| 1380 |
\begtt \catcode`\<=13 \adef!{\string} |
| 1381 |
% Optional comments |
| 1382 |
|
| 1383 |
\_def\_<pkg>_version {<version-number>, <version-date>} |
| 1384 |
\_codedecl \pkgsequence {Doing the life more comfortable !<\_<pkg>_version>} |
| 1385 |
\_namespace{<pkg>} |
| 1386 |
\endtt |
| 1387 |
The `\_<pkg>_version` macro should be declared here. The macro should expand |
| 1388 |
to version number followed by version date. User can check |
| 1389 |
the package version simply by expanding this macro after the package is |
| 1390 |
loaded. And we want to have this data only at single place of the file. |
| 1391 |
You may check the log file if the text given by \o`\_codedecl` isn't too long |
| 1392 |
and isn't broken to more lines. Keeping single line is better because users can |
| 1393 |
`grep @:` on log file in order to get information of all loaded packages |
| 1394 |
and their version numbers. |
| 1395 |
|
| 1396 |
The \o`\_namespace``{<pkg>}` opens the name space used by your package where all |
| 1397 |
`\.foo` are internally transformed to `\_<pkg>_foo`. Next part of the file |
| 1398 |
includes the code itself documented in {`\_doc...\_cod`} pairs. It is |
| 1399 |
finished by \o`\_endnamespace` which finalizes the scope where `\.foo` are |
| 1400 |
transformed to `\_<pkg>_foo` and by \o`\_endcode` which does \n`\endinput` when |
| 1401 |
the macros are load. Final part of the file after \o`\_endcode` can include |
| 1402 |
more detailed documentation. |
| 1403 |
|
| 1404 |
If your package requires other packages then insert |
| 1405 |
\o`\load``[<package1>,<package2>]` after \o`\_codedecl` and before the the |
| 1406 |
\o`\_namespace` command. Each package uses its own namespace, so it is |
| 1407 |
important to load these packages before your \o`\_namespace` is opened. |
| 1408 |
|
| 1409 |
If you have any idea of creating a macro package, you probably start with |
| 1410 |
experimental macros in the public namespace. It means that there are |
| 1411 |
`\def\mymacro` etc. Once such a code is working, you can include it to the |
| 1412 |
macro package introduced by \o`\_namespace``{<pkg>}`. You have to go through |
| 1413 |
your code carefully sequence per sequence and insert `_` or `.` in front of |
| 1414 |
their names. The \"`_`" prefix have to be used if the sequence is a primitive or |
| 1415 |
an \OpTeX/ macro and the \"`.`" prefix if it is your macro. So, the code fragment |
| 1416 |
`\def\mymacro` have to be rewritten to `\_def\.mymacro`. If the macro |
| 1417 |
`\mymacro` is intended for end users, then export it to the |
| 1418 |
public name space after it is defined by the \o`\_nspublic` `\mymacro ;` command. |
| 1419 |
|
| 1420 |
Sometimes you may want to define a macro only in public namespace. Then |
| 1421 |
use prefix \o`\_newpublic` before your declaration, see declaration of |
| 1422 |
\^`\sgn` in this package as an example. The reason is: if |
| 1423 |
a user has defined such a macro already then the warning is printed. |
| 1424 |
The user can read this warning and declare the macro after |
| 1425 |
`\load[<pkg>]` in this case. |
| 1426 |
|
| 1427 |
\_doc |
| 1428 |
% optex -jobname math-doc '\docgen math' |
| 1429 |
\load [doc,math] |
| 1430 |
\def\opurl{http://petr.olsak.net/ftp/olsak/optex/optex-doc.pdf} |
| 1431 |
\def\tnurl{http://petr.olsak.net/ftp/olsak/optex/tex-nutshell.pdf} |
| 1432 |
\def\trurl{http://petr.olsak.net/optex/optex-tricks.html} |
| 1433 |
\def\tricklink[#1]#2{\ea\ulink \ea[\trurl\##1]{\OpTeX/ trick #2}} |
| 1434 |
\def\exlink#1#2{\ea\ulink\expanded{[#2\csstring#1]{\hbox{\tt\string#1\,}}}} |
| 1435 |
\def\o`#1`{\exlink#1{\opurl\#cs:^}} |
| 1436 |
\def\O`#1`{\exlink#1{\opurl\#cs:}} |
| 1437 |
\def\n`#1`{\exlink#1{\tnurl\#cs:}} |
| 1438 |
\outlines 0 |
| 1439 |
\tracinglostchars=0 |
| 1440 |
|
| 1441 |
\tit Macros for doing math more comfortably |
| 1442 |
\hfill Version: \_math_version \par |
| 1443 |
\centerline{\it Petr Olšák\/\fnotemark1, 2022, 2023, 2024, 2025, 2026} |
| 1444 |
\fnotetext{\url{https://petr.olsak.net}} |
| 1445 |
|
| 1446 |
\notoc\nonum\sec Table of contents |
| 1447 |
\maketoc |
| 1448 |
\printdoctail math.opm % prints the documentation written after \_endcode |
| 1449 |
\sec Implementation |
| 1450 |
\printdoc math.opm % prints \_doc...\_cod parts + code before \_endcode |
| 1451 |
\nonum\sec Index |
| 1452 |
\begmulti 3 |
| 1453 |
\tt \makeindex % prints index in three columns |
| 1454 |
\endmulti |
| 1455 |
\bye |
| 1456 |
\_cod |
| 1457 |
|
| 1458 |
\endinput |
| 1459 |
|
| 1460 |
0.25 2026-04-07 \eqsystem: plus operator processed analogically like minus. |
| 1461 |
0.24 2026-03-08 \scanlimits introduced, extended arrows \exw, \exh implemented. |
| 1462 |
0.23 2026-02-15 \enablefic prints warning only when LuaTeX v>1.23 |
| 1463 |
0.22 2025-12-22 \multiprimes introduced |
| 1464 |
0.21 2025-11-30 \rmsbsp: \_primes correction |
| 1465 |
0.20 2025-06-10 \ibrackets introduced |
| 1466 |
0.19 2025-02-14 \mathselector introduced. |
| 1467 |
0.18 2025-01-15 \enablefic modified. |
| 1468 |
0.17 2024-12-04 \mathsetup instead \mathset, \.unionly modified |
| 1469 |
0.16 2024-10-17 \mathclap, etc. corrected. |
| 1470 |
0.15 2024-04-28 \_ as interval prefix added. |
| 1471 |
0.14 2024-03-18 \flexipa introduced. |
| 1472 |
0.13 2024-03-06 \enablefic introduced. |
| 1473 |
0.12 2024-03-02 \rmsbsp introduced. |
| 1474 |
0.11 2023-04-15: \bbigp introduced. |
| 1475 |
0.10 2023-03-12: \mathclap etc. introduced. |
| 1476 |
0.09 2023-03-11: mstyle, bstyle options introduced. |
| 1477 |
0.08 2023-01-28: \eqsystem introduced, \eqfil added. |
| 1478 |
0.07 2023-01-23: \sgn etc. defined as \protected\def. |
| 1479 |
2023-01-15: \replacemissingchars: bug fixed |
| 1480 |
0.06, 2023-01-14: \rmchars, \vargreek, \bfserif introduced |
| 1481 |
0.05, 2023-01-07: \mathset introduced |
| 1482 |
0.04, 2022-12-26: \casesof used in \.fparamA |
| 1483 |
\singlevert declared instead \_singlevert (bug fix) |
| 1484 |
0.03, 2022-12-19: \cotg, \arccotg defined, |
| 1485 |
\autop: \mathclose{} replaced by \bgroup...\egroup, |
| 1486 |
\scriptspaces: Rel-Op, Bin-Op spacing added. |
| 1487 |
0.02, 2022-11-26: \smartvert introduced |
| 1488 |
0.01, 2022-11-25: released |