diff options
author | Karl Berry <karl@freefriends.org> | 2023-02-09 21:13:26 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2023-02-09 21:13:26 +0000 |
commit | 8e0a627bb31e2495bca858b5c44e63e510c3448c (patch) | |
tree | de89817c8a0600c0389a47b4259f736a63046b66 /Master/texmf-dist/tex/optex | |
parent | 151bcdb5be17d5cd47c6b6128602294a6835f119 (diff) |
optex (9feb23)
git-svn-id: svn://tug.org/texlive/trunk@65766 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/optex')
23 files changed, 774 insertions, 389 deletions
diff --git a/Master/texmf-dist/tex/optex/base/alloc.opm b/Master/texmf-dist/tex/optex/base/alloc.opm index d4f823fec4a..fae88d286ed 100644 --- a/Master/texmf-dist/tex/optex/base/alloc.opm +++ b/Master/texmf-dist/tex/optex/base/alloc.opm @@ -1,6 +1,6 @@ %% This is part of the OpTeX project, see http://petr.olsak.net/optex -\_codedecl \newdimen {Allocators for registers <2022-06-10>} % preloaded in format +\_codedecl \newdimen {Allocators for registers <2023-02-03>} % preloaded in format \_doc ----------------------------- The limits are set first. @@ -46,9 +46,10 @@ \_errmessage{No room for a new \_ea\_string\_csname #2\_endcsname}% \_else \_global#3#1=\_cs{_#2alloc}% - \_wlog{\_string#1=\_ea\_string\_csname #2\_endcsname\_the\_cs{_#2alloc}}% + \_wloga{\_string#1=\_ea\_string\_csname #2\_endcsname\_the\_cs{_#2alloc}}% \_fi } +\_let\_wloga=\_wlog % you can suppress the logging by \_let\_wloga=\_ignoreit \_doc ----------------------------- The allocation macros @@ -177,6 +178,7 @@ the array-like declarator of counters. \_endinput +2023-02-03 \_wloga introduced 2022-06-10 \_famalloc set to 42 (answer to the biggest fundamental question) 2022-03-07 \_noattr allocated 2022-02-19 \_newlanguage introduced diff --git a/Master/texmf-dist/tex/optex/base/basic-macros.opm b/Master/texmf-dist/tex/optex/base/basic-macros.opm index ae5c833140d..92275056787 100644 --- a/Master/texmf-dist/tex/optex/base/basic-macros.opm +++ b/Master/texmf-dist/tex/optex/base/basic-macros.opm @@ -1,6 +1,6 @@ %% This is part of the OpTeX project, see http://petr.olsak.net/optex -\_codedecl \sdef {Basic macros for OpTeX <2022-11-22>} % preloaded in format +\_codedecl \sdef {Basic macros for OpTeX <2023-01-22>} % preloaded in format \_doc ------------------------------ \`\bgroup`, \`\egroup`, \`\empty`, \`\space`, and \`\null` @@ -73,7 +73,7 @@ \_cod ------------------------------ \_def \_cs #1{\_csname#1\_endcsname} -\_def \_trycs#1#2{\_ifcsname #1\_endcsname \_csname #1\_ea\_endcsname \_else #2\_fi} +\_def \_trycs#1#2{\_ifcsname #1\_endcsname \_csname #1\_ea\_endcsname \_else \_afterfi{#2}\_fi} \_public \cs \trycs ; \_doc ------------------------------ @@ -142,6 +142,7 @@ \_endcode % ------------------------------------- +2023-01-22: \trycs: afterfi used for second parameter 2022-11-22: \_banner definition moved here 2022-11-18: \ahead introduced 2022-10-29: \_fin introduced diff --git a/Master/texmf-dist/tex/optex/base/doc.opm b/Master/texmf-dist/tex/optex/base/doc.opm index dc5d037e72d..fb96d35007e 100644 --- a/Master/texmf-dist/tex/optex/base/doc.opm +++ b/Master/texmf-dist/tex/optex/base/doc.opm @@ -1,6 +1,6 @@ %% This is part of the OpTeX project, see http://petr.olsak.net/optex -\_codedecl \printdoc {Macros for documentation printing <2022-11-21>} % loaded on demand by \load[doc] +\_codedecl \printdoc {Macros for documentation printing <2022-12-11>} % loaded on demand by \load[doc] \_doc ----------------------------- General decalarations. @@ -204,7 +204,7 @@ \_doc ----------------------------- If this macro is loaded by \^`\load` then we need to initialize - catcodes using the `\_afteroad` macro. + catcodes using the `\_afterload` macro. \_cod ----------------------------- \_def\_afterload{\_catcode`\<=13 \_catcode`\`=13 @@ -229,26 +229,32 @@ Link to user documentation point: \code{\\~`\\foo}. \_cod ----------------------------- +\_def\_docrefcodes{\_catcode`\.=11\_relax} + \_verbchar` -\_def\`#1`{\_leavevmode\_edef\_tmp{\_csstring#1}\_iindex{\_tmp}% - \_ifcsname cs:\_tmp\_endcsname\_else \_dest[cs:\_tmp]\_fi +\_def\`{\_bgroup \_docrefcodes \_mainpoint} +\_def\_mainpoint #1`{\_egroup\_leavevmode\_edef\_tmp{\_csstring#1}\_iindex{\_tmp}% + \_ifcsname cs:\_tmp\_endcsname \_moremainpoints \_else \_dest[cs:\_tmp]\_fi \_sxdef{cs:\_tmp}{}% \_hbox{\_ifcsname cs:^\_tmp\_endcsname \_link[cs:^\_tmp]{\mlinkcolor}{\_tt\_csstring\\\_tmp}\_else {\_tt\mlinkcolor\_csstring\\\_tmp}\_fi}% } -\_def\^`#1{\_leavevmode\_edef\_tmp{\_csstring#1}\_iindex{\_tmp}% +\_def\^`{\_bgroup \_docrefcodes \_docpoint} +\_def\_docpoint #1{\_egroup\_leavevmode\_edef\_tmp{\_csstring#1}\_iindex{\_tmp}% \_hbox{\_ifcsname cs:^\_tmp\_endcsname \_else \_dest[cs:^\_tmp]\_sxdef{cs:^\_tmp}{}\_fi \_link[cs:\_tmp]{\ulinkcolor}{\_tt\_string#1}}% \_futurelet\_next\_cslinkA } \_def\_cslinkA{\_ifx\_next`\_ea\_ignoreit \_else \_ea\_ea\_ea`\_ea\_string\_fi} -\_def\~`#1{\_leavevmode\_edef\_tmp{\_csstring#1}\_iindex{\_tmp}% +\_def\~`{\_bgroup \_docrefcodes \_doctpoint} +\_def\_doctpoint #1{\_egroup\_leavevmode\_edef\_tmp{\_csstring#1}\_iindex{\_tmp}% \_hbox{\_link[cs:^\_tmp]{\ulinkcolor}{\_tt\_string#1}}% \_futurelet\_next\_cslinkA } +\_def\_moremainpoints{\_opwarning{Second main documentation point \_bslash\_tmp}} \_doc ----------------------------- The \`\fw` macro for forward links to user documentation point (given later) @@ -357,6 +363,8 @@ have the same meaning: `\optexdoclink` in this example. And \endinput +2022-12-11 \_opwaning "Second main documentation point" introduced. +2022-12-11 \_docrefcodes added (bug due to 2022-11-13 fixed). 2022-11-21 magenta color for internal links instead green. 2022-11-13 \catcode`.=11: only local settings 2022-07-01 \_printii improved, colors declaration part added. diff --git a/Master/texmf-dist/tex/optex/base/f-heros.opm b/Master/texmf-dist/tex/optex/base/f-heros.opm index 2531573ca4b..d7495538826 100644 --- a/Master/texmf-dist/tex/optex/base/f-heros.opm +++ b/Master/texmf-dist/tex/optex/base/f-heros.opm @@ -193,12 +193,16 @@ so the first font from the new family is loaded and it is ready to use it. \seccc Name conventions -Create font modifiers, new variants, and the `\<Familyselector>` only as public, i.e. -in user namespace without `_` prefix. We assume that if a user re-defines them then he/she needs +Create font modifiers, new variants, and the `\<Familyselector>` only in +public namespace without `_` prefix. We assume that if a user re-defines them then he/she needs not them, so we have no problems. If the user's definition was done before loading the font family file then it is re-defined and \OpTeX/ warns about it. See the end of section~\ref[fontcommands]. +If you need to use an internal control sequence declared in your fontfile, +use the reserved name space with names starting with two `_` followed by family +indentifier or by `vf` if it relates to variable fonts. + The name of `\<Familyselector>` should begin with an uppercase letter. Please, look at diff --git a/Master/texmf-dist/tex/optex/base/fonts-resize.opm b/Master/texmf-dist/tex/optex/base/fonts-resize.opm index 34885d44bd7..e76596611b4 100644 --- a/Master/texmf-dist/tex/optex/base/fonts-resize.opm +++ b/Master/texmf-dist/tex/optex/base/fonts-resize.opm @@ -107,7 +107,7 @@ The \`\_regtfm` `<font id> <optical size data>` registers optical sizes data directly by the font file names. This can be used for `tfm` files or OpenType files without - various font features. See also \`\_regoptsizes` in section~\ref[optsizes]. + various font features. See also \^`\_regoptsizes` in section~\ref[optsizes]. The `\_regtfm` command saves the <optical size data> concerned to the `<font id>`. The `<optical size data>` is in the form as shown below in the code where `\_regtfm` is used. diff --git a/Master/texmf-dist/tex/optex/base/fonts-select.opm b/Master/texmf-dist/tex/optex/base/fonts-select.opm index 7e00c9baea1..6b10f75aff0 100644 --- a/Master/texmf-dist/tex/optex/base/fonts-select.opm +++ b/Master/texmf-dist/tex/optex/base/fonts-select.opm @@ -733,10 +733,10 @@ Compare ex-height of Termes \rmsans with Heros \rm and Termes. \endtt The variant selectors (declared by \~`\famvardef`) or font -modifiers (declared by \~`\moddef`) are (typically) control sequences in user name -space (`\mf`, `\caps`). They are most often declared in font family files and +modifiers (declared by \~`\moddef`) are (typically) control sequences in the public +namespace (`\mf`, `\caps`). They are most often declared in font family files and they are loaded by \^`\fontfam`. A conflict with such names in -user namespace can be here. For example: if `\mf` is defined by a user and then +the public namespace can be here. For example: if `\mf` is defined by a user and then `\fontfam[Roboto]` is used then `\famvardef\mf` is performed for Roboto family and the original meaning of `\mf` is lost. But \OpTeX/ prints warning about it. There are two cases: diff --git a/Master/texmf-dist/tex/optex/base/hisyntax-c.opm b/Master/texmf-dist/tex/optex/base/hisyntax-c.opm index 3c1f228f88c..d0a4217b31e 100644 --- a/Master/texmf-dist/tex/optex/base/hisyntax-c.opm +++ b/Master/texmf-dist/tex/optex/base/hisyntax-c.opm @@ -52,7 +52,7 @@ User can re-declare his/her own colors by `\hicolors` which has precedence before `\_hicolors<name>`. The public variants can be declared if you want to give these token lists to -the user namespace. But it is not explicitly needed. +the public namespace. But it is not explicitly needed. All settings must be global here because the file is typically read inside a group and we need not read it repeatedly before each code chunk diff --git a/Master/texmf-dist/tex/optex/base/if-macros.opm b/Master/texmf-dist/tex/optex/base/if-macros.opm index 9113b5f8beb..148c8559413 100644 --- a/Master/texmf-dist/tex/optex/base/if-macros.opm +++ b/Master/texmf-dist/tex/optex/base/if-macros.opm @@ -1,6 +1,6 @@ %% This is part of the OpTeX project, see http://petr.olsak.net/optex -\_codedecl \newif {Special if-macros, is-macros and loops <2022-12-02>} % preloaded in format +\_codedecl \newif {Special if-macros, is-macros and loops <2023-01-16>} % preloaded in format \_doc ---------------------------- \secc Classical \code{\\newif} @@ -64,6 +64,7 @@ \_def \_iterate {\_body \_ea \_iterate \_fi} \_doc ----------------------------- + {\_let\_moremainpoints=\_relax \`\foreach` `<list>`\`\do` `{<what>}` repeats `<what>` for each element of the `<list>`. The `<what>` can include `#1` which is substituted by each @@ -82,7 +83,7 @@ Recommendation: it is better to use private variants of \`\_foreach`. When the user writes `\input tikz` then `\foreach` macro is redefined in each TikZ environment. - The private variants use \`\_do` separator instead `\do` separator. + The private variants use \`\_do` separator instead `\do` separator.} \_cod ----------------------------- \_newcount\_frnum % the numeric variable used in \fornum @@ -101,6 +102,7 @@ \_afterfi{\_foreachA{#1}{##1}}\_else\_afterfi{\_foreachA{#1}{#2}}\_fi} \_doc ----------------------------- + {\_let\_moremainpoints=\_relax \`\fornum` `<from>..<to>` \`\do` `{<what>}` or \`\fornumstep` `<num>: <from>..<to>` \`\do` `{<what>}` repeats `<what>` for each number from `<from>` to `<to>` (with step `<num>` @@ -110,7 +112,7 @@ The test in the \`\_fornumB` says: if (<to> $\string<$ <current number> AND <step> is positive) or if (<to> $>$ <current number> AND <step> is negative) then close loop by `\_getforstack`. Sorry, the condition is - writen by somewhat cryptoid \TeX/ language. + writen by somewhat cryptoid \TeX/ language.} \_cod ----------------------------- \_def\_fornum#1..#2\_do{\_fornumstep 1:#1..#2\_do} @@ -292,16 +294,17 @@ \_public \isfont ; \_doc ---------------------------- - The last macro \`\isnextchar` `<char>{<codeA>}{<codeB>}` + The macro \`\isnextchar` `<char>{<codeA>}{<codeB>}` has a different syntax than all other is-macros. It executes `<codeA>` if next character is equal to <char>. - Else the `<codeB>` is executed. The macro is not expandable. + Else the `<codeB>` is executed. The macro is expandable. \_cod ---------------------------- -\_long\_def\_isnextchar#1#2#3{\_begingroup\_toks0={\_endgroup#2}\_toks1={\_endgroup#3}% - \_let\_tmp= #1\_futurelet\_next\_isnextcharA +\_long\_def\_isnextchar#1#2#3{\_immediateassignment + \_def\_isnextcharA{\_isnextcharB{#1}{#2}{#3}}% + \_immediateassignment\_futurelet \_next \_isnextcharA } -\_def\_isnextcharA{\_the\_toks\_ifx\_tmp\_next0\_else1\_fi\_space} +\_long\_def\_isnextcharB#1{\_ifx\_next#1\_ea\_ignoresecond\_else\_ea\_usesecond\_fi} \_public \isnextchar ; @@ -359,6 +362,7 @@ \_endcode +2023-01-16 \isnextchar created expandable. 2022-12-02 \xcasesof: its first parameter is \long too. 2022-11-29 renamed to \casesof, \xcasesof. 2022-11-26 \casesby, \casesbyif introduced. diff --git a/Master/texmf-dist/tex/optex/base/keyval.opm b/Master/texmf-dist/tex/optex/base/keyval.opm index 7d089ce6b1f..21e6f9acf34 100644 --- a/Master/texmf-dist/tex/optex/base/keyval.opm +++ b/Master/texmf-dist/tex/optex/base/keyval.opm @@ -1,26 +1,39 @@ %% This is part of the OpTeX project, see http://petr.olsak.net/optex -\_codedecl \readkv {Key-value dictionaries <2020-12-21>} % preloaded in format +\_codedecl \readkv {Key-value dictionaries <2023-01-14>} % preloaded in format \_doc ---------------------------- - {\bf Implementation.} + {\bf Implementation.}\nl The \`\readkv``<list>` expands its parameter and does replace-strings in order to - remove spaces around equal signs and after commas. Double commas are - removed. Then \`\_kvscan` reads the parameters list finished by the double - comma and saves values to `\_kv:<key>` macros.\nl - The \`\kv``{<key>}` expands the `\_kv:<key>` macro. If this macro isn't - defined then \`\_kvunknown` is processed. You can re-define it if you want. + remove spaces around equal signs and after commas. + Then \`\_kvscan` reads the parameters list finished by `,\_fin,` + and saves values to `\_kv:<dict>:<key>` macros. + The `\_kvx:<dict>:<key>` is processed (if it is defined) with parameter + <value> after it.\nl + The \`\kvx``{<key>}{<code>}` defines the `\_kvx:<dict>:<key>#1` macro + and \`\nokvx``{<code>}` defines the `\_nokvx:<dict>:<key>` macro.\nl + The \`\kv``{<key>}` expands the `\_kv:<dict>:<key>` macro. If this macro isn't + defined then \`\_kvunknown` is processed. You can re-define it if you want.\nl + The \`\iskv``{<key>}\iftrue` (or `\iffalse`) is the test, + if the `<key>` is defined in current <dict>. \_cod ---------------------------- \_def\_readkv#1{\_ea\_def\_ea\_tmpb\_ea{#1}% - \_replstring\_tmpb{= }{=}\_replstring\_tmpb{ =}{=}% - \_replstring\_tmpb{, }{,}\_replstring\_tmpb{,,}{,}% - \_ea \_kvscan \_tmpb,,=,} -\_def\_kvscan #1#2=#3,{\_ifx#1,\_else \_sdef{_kv:#1#2}{#3}\_ea\_kvscan\_fi} -\_def\_kv#1{\_trycs{_kv:#1}{\_kvunknown}} + \_replstring\_tmpb{= }{=}\_replstring\_tmpb{ =}{=}\_replstring\_tmpb{, }{,}% + \_ea \_kvscan\_tmpb,\_fin,} +\_def\_kvscan#1,{\_ifx\_fin#1\_empty\_ea\_ignoreit \_else\_ea\_useit \_fi + {\_kvsd #1==\_fin \_kvscan}} +\_def\_kvsd#1=#2=#3\_fin{\_sdef{\_kvcs#1}{#2}% + \_trycs{_kvx:\_the\_kvdict:#1}% + {\_trycs{_nokvx:\_the\_kvdict}{\_ea\_ignoreit}{#1}\_ea\_ignoreit}{#2}} +\_def\_kvx#1#2{\_sdef{_kvx:\_the\_kvdict:#1}##1{#2}} +\_def\_nokvx#1{\_sdef{_nokvx:\_the\_kvdict}##1\_ea\_ignoreit\_fi##2{\_fi#1}} +\_def\_kv#1{\_trycs{\_kvcs#1}{\_kvunknown}} +\_def\_iskv#1#2{#2\_else\_ea\_unless\_fi \_ifcsname\_kvcs#1\_endcsname} +\_def\_kvcs{_kv:\_the\_kvdict:} \_def\_kvunknown{???} -\public \readkv \kv ; +\public \readkv \kvx \nokvx \kv \iskv ; \_endcode @@ -43,7 +56,7 @@ or simply `\myframe {text3}`. You can define `\myframe` as follows: \begtt \def\myframedefaults{% defaults: frame-color=\Black, % color of frame rules - text-color=\Black, % color ot text inside the frame + text-color=\Black, % color of text inside the frame rule-width=0.4pt, % width of rules used in the frame margins=2pt, % space between text inside and rules. } @@ -64,18 +77,54 @@ The last setting wins. Third: the values can be used by the expandable \^`\kv{<key>}` macro. The \^`\kv{<key>}` returns `???` if such key is not declared. -You can use keys without values in the parameters list too, but with -additional care. For example, suppose `draft` option without parameter. -If a user writes `\myframe [..., draft, ...]{text}` then `\myframe` should behave differently. -We have to add `DRAFTv=0,` in `\myframedefault` macro. -Moreover, `\myframe` macro must include preprocessing of `\myframedefault` using -\^`\replstring` which replaces the occurrence of `draft` by `DRAFTv=1`. +You can use keys without values in the parameters list too. +Then you can ask if the key is declared by \^`\iskv``{<key>}\iftrue` +or the key is undeclared by \^`\iskv``{<key>}\iffalse`. +For example, you write to your documentation of your code that +user can set the `draft` option without the value. Then you can do \begtt \optdef\myframe [] #1{... - \ea\addto\ea\myframedefaults\ea{\the\opt}% - \replstring\myframedefaults{draft}{DRAFTv=1}% - \readkv\myframedefaults - ... - \ifnum\kv{DRAFTv}=1 draft mode\else normal mode\fi + \readkv\myframedefaults \readkv{\the\opt}% + \iskv{draft}\iftrue ...draft mode... \else ...final mode... \fi + ...} +\endtt +Maybe, you want to allow not ony `draft` option but `final` option (which is +opposite to `draft`) too and you want to apply the result from the last given +option. Then `\iskv` doesn't work because you can only check if both options +are declared but you don't know what one is given as last. But you can +use \^`\kvx``{<key>}{<code>}` to declare <code> which is processed +immediately when the `<key>` is processed by `\readkv`. For example +\begtt +\newcount\mydraftmode +\kvx{draft}{\mydraftmode=1 } +\kvx{final}{\mydraftmode=0 } +\optdef\myframe [] #1{... + \readkv\myframedefaults \readkv{\the\opt}% + \ifnum\mydraftmode=1 ...draft mode... \else ...final mode... \fi ...} \endtt +The syntax of \^`\kvx` `{<key>}{<code>}` allows to use `#1` inside the code. +It is replaced by the actual `<value>`. Example: `\kvx{opt}{\message{opt is #1}}`, +then `\readkv{opt=HELLO}` prints \"opt is HELLO". + +The \^`\nokvx` `{<code>}` can declare a <code> processed for all <keys> +undeclared by \^`\kvx`. The `#1` and `#2` can be used in the <code>, +`#1` is <key>, `#2` is <value>. If `\nokvx` is unused then nothing is done +for undeclared <key>. Example: `\nokvx{\opwarnig{Unknown option "#1"}}`. + +The default dictionary name (where key-value pairs are processed) is +empty. You can use your specific dictionary by +\^`\kvdict``={<name>}`. Then `\redakv`, `\kv`, `\iskv`, `\kvx` and `\nokvx` +macros use this named dictionary of <key>/<value> pairs. +Package options can be processed when +`\kvdict={pkg:<pkg>}`, example is the `\mathset` macro in +\ulink[https://petr.olsak.net/ftp/olsak/optex/math-doc.pdf]{{\tt math.opm} package}. + +Recommendation: If the value of the key-value pair includes `=` or `,` or +`]`, then use the syntax `<key>={<value>}`. + +\_endinput + +2023-01-13 \kvx parameter added, \nokvx introduced. +2023-01-07 \kvdict, \kvx, \iskv added. +2020-12-21 Released diff --git a/Master/texmf-dist/tex/optex/base/lists.opm b/Master/texmf-dist/tex/optex/base/lists.opm index 189719302dd..57b057d6c8c 100644 --- a/Master/texmf-dist/tex/optex/base/lists.opm +++ b/Master/texmf-dist/tex/optex/base/lists.opm @@ -61,7 +61,7 @@ \_public \begitems \enditems \itemnum ; \_doc ---------------------------- - \`\novspaces` sets \`\listskipamount` to 0pt. + \`\novspaces` sets \^`\listskipamount` to 0pt. \_cod ---------------------------- \_def\_novspaces {\_removelastskip \_listskipamount=0pt \_relax} @@ -71,9 +71,9 @@ Various item marks are saved in `\_item:<letter>` macros. You can re-define then or define more such macros. The \`\style` `<letter>` does \`\_printitem``={\_item:<letter>}`. - More exactly: \^`\begitems` does `\_printitem=`\^`\defaultitem` first, - then \`\style` `<letter>` does \`\_printitem``={\_item:<letter>}` - when it is used and finally, `\_startitem` alias `*` uses `\_printitem`. + More exactly: \^`\begitems` does \^`\_printitem=`\^`\defaultitem` first, + then \^`\style` `<letter>` does \^`\_printitem``={\_item:<letter>}` + when it is used and finally, `\_startitem` alias `*` uses \^`\_printitem`. \_cod ----------------------------- \_def\_style#1{% diff --git a/Master/texmf-dist/tex/optex/base/math-macros.opm b/Master/texmf-dist/tex/optex/base/math-macros.opm index 83d3c5ab513..6e2365c9cc9 100644 --- a/Master/texmf-dist/tex/optex/base/math-macros.opm +++ b/Master/texmf-dist/tex/optex/base/math-macros.opm @@ -368,7 +368,7 @@ \_doc ----------------------------- \`\big`, \`\Big`, \`\bigg`, \`\Bigg`, \`\bigl`, \`\bigm`, \`\bigr`, \`\Bigl`, \`\Bigm`, - \`\Bigr`, \`\biggl`, \`\biggm`, \`\biggr`, \`\Biggl`, \`\Biggm`, \`\Bigg`, \`\Biggr` + \`\Bigr`, \`\biggl`, \`\biggm`, \`\biggr`, \`\Biggl`, \`\Biggm`, \`\Biggr` are based on the \`\_scalebig` macro because we need the dependency on the various sizes of the fonts. \_cod ----------------------------- @@ -703,7 +703,7 @@ \_public\displaylines ; \_doc ----------------------------- - \`\openup`, \`\eqalignno` and `\leqalignno` macros are copied from + \`\openup`, \`\eqalignno` and \`\leqalignno` macros are copied from Plain \TeX/ unchanged. \_cod ----------------------------- diff --git a/Master/texmf-dist/tex/optex/base/more-macros.opm b/Master/texmf-dist/tex/optex/base/more-macros.opm index 418e71b7749..8c622432340 100644 --- a/Master/texmf-dist/tex/optex/base/more-macros.opm +++ b/Master/texmf-dist/tex/optex/base/more-macros.opm @@ -1,6 +1,6 @@ %% This is part of the OpTeX project, see http://petr.olsak.net/optex -\_codedecl \eoldef {OpTeX useful macros <2022-11-24>} % preloaded in format +\_codedecl \eoldef {OpTeX useful macros <2023-01-18>} % preloaded in format \_doc ----------------------------- We define \`\opinput` `{<file name>}` macro which @@ -261,7 +261,7 @@ \_public \cstochar ; \_doc ----------------------------- - You can use expandable \`\bp``{<dimen>}` convertor from + You can use expandable \`\bp``{<dimen>}` converter from \TeX/ `<dimen>` (or from an expression accepted by `\dimexpr` primitive) to a decimal value in big points (used as natural unit in the PDF format). So, you can write, for example: @@ -269,21 +269,32 @@ \pdfliteral{q \_bp{.3\hsize-2mm} \_bp{2mm} m 0 \_bp{-4mm} l S Q} \endtt You can use expandable \`\expr``{<expression>}` for analogical purposes. - It expands to the value of the `<expression>` at expand processor level - with \`\_decdigits` digits after the decimal point. + It expands to the value of the `<expression>` at expand processor level. The `<expression>` can include `+-*/()` and decimal numbers in common syntax. + The math functions (and pi constant) have to be prefixed by `math.`, + because it is processed by Lua interpreter. For + example `\expr{math.pi*math.sqrt(2)}`. + The list of available functions is in + \ulink[https://www.lua.org/manual/5.3/manual.html\#6.7]{Lua manual}. + + You can set the number of decimal digits after decimal point of the + results of `\bp` and `\expr` + by optional syntax `\bp[<digits>]{<dimen>}` and + `\expr[<digits>]{<expression>}`. Default is \`\_decdigits`. The usage of prefixed versions \`\_expr` or \`\_bp` is more recommended because a user can re-define the control sequences `\expr` or `\bp`. \_cod ----------------------------- \_def\_decdigits{3} % digits after decimal point in \_bp and \_expr outputs. -\_def\_pttopb{% - \_directlua{tex.print(string.format('\_pcent.\_decdigits f', +\_def\_pttopb#1{% + \_directlua{tex.print(string.format('\_pcent.#1f', token.scan_dimen()/65781.76))}% pt to bp conversion } -\def\_bp#1{\_ea\_pttopb\_dimexpr#1\_relax} -\def\_expr#1{\_directlua{tex.print(string.format('\_pcent.\_decdigits f',#1))}} +\_def\_bp{\_isnextchar[{\_bpA}{\_bpA[\_decdigits]}} +\_def\_bpA[#1]#2{\_pttopb{#1}\_dimexpr#2\_relax} +\_def\_expr{\_isnextchar[{\_exprA}{\_exprA[\_decdigits]}} +\_def\_exprA[#1]#2{\_directlua{tex.print(string.format('\_pcent.#1f',#2))}} \_public \expr \bp ; @@ -363,6 +374,7 @@ \_endcode % ------------------------------------- +2023-01-18 \bp, \expr have optional syntax for setting dec-digits 2022-11-24 \setpos, \posx, \posy moved from OpTeX trick here 2022-11-22 \docgen writes banner to log 2022-11-20 \docgen reads lines before \_codedecl in order to define pkg. version diff --git a/Master/texmf-dist/tex/optex/base/optex.ini b/Master/texmf-dist/tex/optex/base/optex.ini index 4941ead57c1..3266cf0ab1f 100644 --- a/Master/texmf-dist/tex/optex/base/optex.ini +++ b/Master/texmf-dist/tex/optex/base/optex.ini @@ -21,7 +21,7 @@ % OpTeX version -\def\optexversion{1.09 Dec 2022} +\def\optexversion{1.10 Feb 2023} \def\fmtname{OpTeX} \let\fmtversion=\optexversion diff --git a/Master/texmf-dist/tex/optex/base/others.opm b/Master/texmf-dist/tex/optex/base/others.opm index 98df836f763..cde2f02fa1f 100644 --- a/Master/texmf-dist/tex/optex/base/others.opm +++ b/Master/texmf-dist/tex/optex/base/others.opm @@ -177,9 +177,9 @@ \_else % LuaTeX 1.14 or newer: \_doc ----------------------------- - We set `\partokenneame` to `\_par` in order to keep the name `\par` in - user name space. I.e. a user can say `\def\par{paragraph}` for example - without crash of processing the document. Se section~\ref[prefixed] for + We set `\partokenneame` to `\_par` in order to keep the name `\par` in the + public namespace for end users. I.e.\ a user can say `\def\par{paragraph}` for example + without crash of processing the document. Se section~\ref[namespaces] for more details about the name space concept.\nl Moreover, we set `\partokencontext` to one in order to the `\_par` token is inserted not only at empty lines, but also at the end of `\vbox`, `\vtop` and diff --git a/Master/texmf-dist/tex/optex/base/parameters.opm b/Master/texmf-dist/tex/optex/base/parameters.opm index 499aee8d45c..855969f4de2 100644 --- a/Master/texmf-dist/tex/optex/base/parameters.opm +++ b/Master/texmf-dist/tex/optex/base/parameters.opm @@ -205,6 +205,14 @@ \_public \picwidth \picheight ; \_doc ----------------------------- + \`\kvdict` is dictionary name when \~`\readkv`, \~`\kvx`, \~`\kv`, and \~`\iskv` are + processed. The default is empty. + \_cod ----------------------------- + +\_newtoks \_kvdict +\_public \kvdict ; + + \_doc ----------------------------- The \`\everytt` is the token list used in \^`\begtt`...\^`\endtt` environment and in the verbatim group opened by \^`\verbinput` macro. You can include a @@ -542,12 +550,10 @@ % \_shadow=N \_overlapmargins=N \_hhkern=3pt \_vvkern=3pt} \_newdimen \_roundness \_roundness=5mm % used in \clippingoval macro - \_public \ovalparams \circleparams \roundness ; \_doc ----------------------------- - \OpTeX/ defines \"Standard \OpTeX/ markup language"% - \fnote{Will be developed in 2021.} + \OpTeX/ defines \"Standard \OpTeX/ markup language" which lists selected commands from chapter~1 and gives their behavior when a converter from \OpTeX/ document to HTML or Markdown or \LaTeX/ is used. The structure-oriented commands are selected here, but the commands which diff --git a/Master/texmf-dist/tex/optex/base/prefixed.opm b/Master/texmf-dist/tex/optex/base/prefixed.opm index a599e0ec856..023f3bc4de9 100644 --- a/Master/texmf-dist/tex/optex/base/prefixed.opm +++ b/Master/texmf-dist/tex/optex/base/prefixed.opm @@ -152,44 +152,70 @@ \_endcode %---------------------------------------------------- -\sec[prefixed] Concept of namespaces of control sequences +\sec[basic-code] Basic principles of \OpTeX/ sources -\secc Prefixing internal control sequences +\secc[namespaces] Concept of namespaces of control sequences -All control sequences used in \OpTeX/ are used and defined with `_` prefix. -The user can be sure that when he/she does `\def\foo` then neither internal macros of -\OpTeX/ nor \TeX/ primitives will be damaged. For example -`\def\if{...}` will not damage macros because \OpTeX/'s macros -are using `\_if` instead of `\if`. +\OpTeX/ sets the category code of the \"`_`" character to 11 (letter) +and it is never changed.\fnote +{This is only singular exception form category codes given by plain \TeX.} +So, we can always construct multiletter control sequence names from letters +`A`--`Z`, `a`--`z`, and `_`. The \"letter `_`" works in math mode as a subscript +constructor because it is set as math active character (see section~\ref[math-macros]). -All \TeX/ primitives are initialized with two representative control -sequences: `\word` and `\_word`, for example `\hbox` and `\_hbox`. -The first alternative is reserved for users or such control sequences -can be re-defined by a user. - -\OpTeX/ sets the character `_` as letter, so it can be used in -control sequences. When a control sequence begins with this character -then it means that it is a primitive or it is used in \OpTeX/ macros as -internal. User can redefine such prefixed control sequence only -if he/she explicitly knows what happens. - -We never change catcode of `_`, so internal macros can be -redefined by user without problems if it is desired. We don't need -something like `\makeatletter` from \LaTeX/. - -\OpTeX/ defines all new macros as prefixed. For public usage of such macros, -we need to set their non-prefixed versions. This is done by +We distinguish following namespaces for multiletter control sequences: +\begitems +* Only alphabetical names are in the {\em public namespace}. They are intended + for end users when creating a document. Sometimes it is called {\em user + namespace} too. For example `\hbox`, `\fontfam`, `\MyMacro`. +* Only alphabetical lowercase names prefixed by single \"`_`" are in the + {\em private namespace}. It is used in \OpTeX/ internal macros. + For example `\_hbox`, `\_fontsel`. +* Names in the form `\_<pkg>_<name>` are in the {\em package namespace}, + see section~\ref[pkg-namespace]. For example `\_qr_size`, `\_math_alist`. +* Names starting with two \"`_`" are in the {\em reserved namespace}. They can be + used for internal control sequences in font family files or in similar cases. +* Other names which include \"`_`" but not as the first character can be used + too, but with care, see the end of this section. +\enditems +All \TeX/ primitives are initialized with two control sequences with the +same meaning: {\em prefixed} control sequence +(in private namespace, for example `\_hbox`) +and {\em unprefixed} control sequence (in public namespace, for example `\hbox`). +All \OpTeX/ macros intended for end users are initialized in these two forms +too, for example `\_ref` and `\ref`. + +Users can declare any control sequences in the public namespace without worrying +that \OpTeX/ behavior is changed. This is because \OpTeX/ uses exclusively +prefixed control sequences in its macros. For example, a user can declare +`\def\fi{finito}` and nothing bad happens, if the user doesn't use `\fi` in +its original primitive meaning. You don't have to know all \TeX/ primitives +and \OpTeX/ macros, you can declare control sequences for your use in the +public namespace without limitations and nothing bad will happen. + +You can use control sequences from private or package namespace in +a \"read-only manner" without changing \OpTeX/ behavior too. +On the other hand, if you re-define a control sequence in the private name +space, the \OpTeX/ behavior can be changed. You can do it +but we suppose that you know what you are doing and what \OpTeX/ +behavior is changed. + +All multiletter control sequences declared by \OpTeX/ are defined in the private +namespace first (`\_def\_macro{...}`). If the declared control sequences are +intended for end users too then they are exported to the public namespace +after that. It is done by the \^`\public` macro: \begtt \catcode`\<=13 \public <list of control sequences> ; \endtt - For example \^`\public`` \foo \bar ;` does `\let\foo=\_foo`, `\let\bar=\_bar`. -At the end of each code segment in \OpTeX/, the `\_public` macro is used. You -can see which macros are defined for public usage in that code segment. +There is an exception of the above mentioned principle. Control sequences +which are alternatives to math characters (`\alpha`, `\forall`, `\subset` etc.) +are declared only in public name space if they are not used in any internal +\OpTeX/ macros. -The macro \^`\private` does the reverse job of `\public` with the same syntax. +The macro \^`\private` does the reverse job of \^`\public` with the same syntax. For example `\private \foo \bar ;` does `\let\_foo=\foo`, `\let\_bar=\bar`. This should be used when an unprefixed variant of a control sequence is declared already but we need the prefixed variant too. @@ -199,45 +225,33 @@ In this documentation: if both variants of a control sequence are declared the unprefixed variant. The code typically defines the prefixed variant and then the \^`\public` (or `\_public`) macro is used. -\secc[user-ns] Namespace of control sequences for users - -Users can (re)define or (re)declare any control sequence with a name without any `_`. -This does not make any problem in internal \OpTeX/ macros.\fnote -{The token `\par` is in user name space too from \OpTeX/ 1.04+ and -Lua\TeX/ 1.14, see also the end of section~\ref[others].} - -User can define or declare control sequences with `_` character, for -example `\my_control_sequence`, but with the following exceptions: - -\begitems -* Control sequences which begin with `_` are reserved for \TeX/ primitives, - \OpTeX/ internal macros and packages internal macros. -* Multiletter control sequences in the form - `\<word>_` or `\<word>_<one-letter>`, where - <word> is a sequence of letters, are inaccessible, because they - are interpreted as `\<word>` followed by `_` or as `\<word>` followed by - `_<one-letter>`. This is important for writing math, for example: -\begtt \adef-{_} - \int-a^b ... is interpreted as \int _a^b - \max-M ... is interpreted as \max _M - \alpha-{ij} ... is interpreted as \alpha _{ij} -\endtt - This feature is implemented using Lua code at input processor level, see - the section~\ref[math-macros] for more details. You can deactivate this feature by - \^`\mathsboff`. After this, you can still write - `$`$\int$`_a^b$` (Unicode) or `$\int _a^b$` % $∫_a^b$ (Unicode) or $\int _a^b$ - without problems but `\int``_a^b` yields to undefined control sequence - `\int``_a`. You can activate this feature again by \^`\mathsbon`. The - effect will take shape from next line read from input file. -* Control sequences in the form `\_<pkg>_<word>` is intended for package - writers as internal macros for a package with `<pkg>` identifier, - see section~\ref[pkg-namespace]. -\enditems - The single-letter control sequences like `\%`, `\$`, `\^` etc. are not used in internal macros. Users can redefine them, but (of course) some classical features can be lost (printing percent character by `\%` for example). +It is very tempting to use control sequence names with `_` in order to +distinguish more words in the sequence name. If the first character isn't +`_` then such a name is outside private and package namespaces, so they can +be used for various purposes. For example `\my_control_sequence`. But there +is an exception: control sequences in the form `\<word>_` or `\<word>_<one-letter>`, +where <word> is a sequence of letters, are inaccessible, because they +are interpreted as `\<word>` followed by `_` or as `\<word>` followed by +`_<one-letter>`. This feature is activated because we want to write math +formulae as in plain \TeX, for example: +\begtt + \int_a^b ... is interpreted as \int _a^b + \max_M ... is interpreted as \max _M + \alpha_{ij} ... is interpreted as \alpha _{ij} +\endtt +It is implemented using Lua code at input processor level, see +the section~\ref[math-macros] for more details. You can deactivate this feature by +\^`\mathsboff`. After this, you can still write +`$`$\int$`_a^b$` (Unicode) or `$\int _a^b$` % $∫_a^b$ (Unicode) or $\int _a^b$ +without problems but `\int``_a^b` yields to undefined control sequence +`\int``_a`. You can activate this feature again by \^`\mathsbon`. The +effect will take shape from next line read from input file. + + \secc Macro files syntax Segments of \OpTeX/ macros or external macro packages @@ -272,7 +286,7 @@ put macros for creating your documentation between first pair of \^`\_doc` ... \^`\_cod` used after \^`\_endcode`. These macros should \^`\load[doc]` and must be finished by \^`\bye`. Then you have code+documentation together in a single file and -user can generate the documentation of our package by +user can generate the documentation of your package by \^`\docgen` used at command line: \begtt optex -jobname pkgname-doc '\docgen pkgname' @@ -307,10 +321,10 @@ does `\let\foo = \_<pkg>_foo` for each given sequence when \^`\_namespace{<pkg>}` is declared. Moreover, it prints a warning if `\foo` is defined already. The \^`\_nsprivate` macro does reverse operation to it without warnings. Example: you can define `\def\.macro{...}` and then -set it to the user name space by `\_nspublic \macro;`. +set it to the public namespace by `\_nspublic \macro;`. It could happen that a package writer needs to declare a control sequence -(say `\foo`) directly without setting it in `\_<pkg>_foo` name space +(say `\foo`) directly without setting it in `\_<pkg>_foo` namespace followed by using \^`\_nspublic`. The \^`\newpublic` prefix should be used in this case, for example `\_newpublic\_def\foo` or `\_newpublic\_chardef\foo` or `\_newpublic{\_long\_def}\foo`. The \^`\newpublic``<do>\<sequence>` prints @@ -338,9 +352,9 @@ If you are writing a macro file that is intended to be published for \OpTeX/, then you are greatly welcome. You should follow these rules: \begitems -* Don't use control sequences from the user namespace in the macro +* Don't use control sequences from the public namespace in the macro bodies if there is no explicit and documented reason to do this. -* Don't declare control sequences in the user namespace if there are no +* Don't declare control sequences in the public namespace if there are no explicit and documented reasons to do this. * Use control sequences from \OpTeX/ and primitive namespace in read-only mode, if there is not an explicit and documented reason to @@ -368,11 +382,12 @@ used directly in \OpTeX/ and from other published macros. This extension `.opm` has precedence before `.tex` when the \^`\load` macro is used. -The `qrcode.opm` is the first example of how an external macro file for \OpTeX/ +The `math.opm` is a good example of how an external macro file for \OpTeX/ can look like. \endinput +2023-01-30 doc. about namespaces rewritten 2022-11-25 \_resetnamespace: moved \gdef\_namesp:#1 {} to \_namespace 2022-11-24 \newpublic introduced, \_checkexists with only two parameters. 2022-11-22 \currfile introduced and used in \_codedecl diff --git a/Master/texmf-dist/tex/optex/base/references.opm b/Master/texmf-dist/tex/optex/base/references.opm index 9da2bca30fb..56ad7ad5892 100644 --- a/Master/texmf-dist/tex/optex/base/references.opm +++ b/Master/texmf-dist/tex/optex/base/references.opm @@ -1,6 +1,6 @@ %% This is part of the OpTeX project, see http://petr.olsak.net/optex -\_codedecl \ref {References <2021-04-13>} % preloaded in format +\_codedecl \ref {References <2022-01-22>} % preloaded in format \_doc ---------------------------- \`\_Xpage` `{<gpageno>}{<pageno>}` saves the parameter pair into \`\_currpage`. @@ -121,5 +121,6 @@ See section \ref[ref-file] for more information about `.ref` file concept. \_endinput +2022-01-22 ... extended format for \ref, \pgref 2021-04-13 ... \_slideshook introduced (used by \slides) 2020-03-03 ... released diff --git a/Master/texmf-dist/tex/optex/base/sections.opm b/Master/texmf-dist/tex/optex/base/sections.opm index 7d7a78232bd..7940a47bfac 100644 --- a/Master/texmf-dist/tex/optex/base/sections.opm +++ b/Master/texmf-dist/tex/optex/base/sections.opm @@ -171,7 +171,7 @@ First, we read the optional parameter `[<label>]`, if it exists. The `\chap`, `\sec` and `\secc` macro reads its parameter using \^`\scantoeol`. This causes that they cannot be used inside other macros. - Use \`\_inchap`, \`\_insec`, and \`\_insecc` macros directly in such case. + Use \^`\_inchap`, \^`\_insec`, and \^`\_insecc` macros directly in such case. \_cod ---------------------------- \_optdef\_chap[]{\_trylabel \_scantoeol\_inchap} diff --git a/Master/texmf-dist/tex/optex/base/slides.opm b/Master/texmf-dist/tex/optex/base/slides.opm index 39267064baa..84cf6f5db30 100644 --- a/Master/texmf-dist/tex/optex/base/slides.opm +++ b/Master/texmf-dist/tex/optex/base/slides.opm @@ -277,7 +277,7 @@ \_def\layers{\_layers} \_doc ----------------------------- - We must to redefine \`\fnotenumpages` because the data from `.ref` file + We must to redefine \^`\fnotenumpages` because the data from `.ref` file are less usable for implementing such a feature: the footnote should be in more layers repeatedly. But we can suppose that each page starts by `\pg;` macro, so we can reset the footnote counter by diff --git a/Master/texmf-dist/tex/optex/base/table.opm b/Master/texmf-dist/tex/optex/base/table.opm index 1866c0486d1..a249f1e30a0 100644 --- a/Master/texmf-dist/tex/optex/base/table.opm +++ b/Master/texmf-dist/tex/optex/base/table.opm @@ -1,6 +1,6 @@ %% This is part of the OpTeX project, see http://petr.olsak.net/optex -\_codedecl \table {Basic macros for OpTeX <2022-05-03>} % preloaded in format +\_codedecl \table {Basic macros for OpTeX <2022-12-26>} % preloaded in format \_doc ----------------------------- The result of the \`\table``{<declaration>}{<data>}` macro is inserted into @@ -229,9 +229,9 @@ We don't want vertical line after red A to be in red. \_cod ----------------------------- -\_def\_tabdeclarec{\_the\_tabiteml \_begingroup\_hfil##\_unsskip\_hfil\_endgroup \_the\_tabitemr} -\_def\_tabdeclarel{\_the\_tabiteml \_begingroup ##\_unsskip\_hfil\_endgroup \_the\_tabitemr} -\_def\_tabdeclarer{\_the\_tabiteml \_begingroup\_hfil##\_unsskip\_endgroup \_the\_tabitemr} +\_def\_tabdeclarec{\_the\_tabiteml \_hfil{##}\_unsskip \_hfil \_the\_tabitemr} +\_def\_tabdeclarel{\_the\_tabiteml {##}\_unsskip \_hfil\_the\_tabitemr} +\_def\_tabdeclarer{\_the\_tabiteml \_hfil{##}\_unsskip \_the\_tabitemr} \_doc ----------------------------- The \`\_paramtabdeclarep``{<data>}` is invoked when `p{<data>}` @@ -587,6 +587,7 @@ after the second one. \_endinput +2022-12-26 \tabdeclare: use {##} in order to allow a\over b in table items 2022-05-03 \_let\_tablereplstring\_relax removed and {...} encloses whole \_tableB body 2022-05-02 \_tablereplstrings put in group: bug fix \table in \halign 2022-02-25 {}->\(begin|end)group in \_tabdeclare(l|r|c), bug when \tabitem(l|r)={$} fixed. diff --git a/Master/texmf-dist/tex/optex/base/unimath-codes.opm b/Master/texmf-dist/tex/optex/base/unimath-codes.opm index 418d0d28aa1..66be7487d4d 100644 --- a/Master/texmf-dist/tex/optex/base/unimath-codes.opm +++ b/Master/texmf-dist/tex/optex/base/unimath-codes.opm @@ -1,27 +1,82 @@ %% This is part of the OpTeX project, see http://petr.olsak.net/optex -\_codedecl \_ncharrmA {Uni math codes <2022-11-20>} % preloaded on demand by \loadmath +\_codedecl \_ncharrmA {Uni math codes <2023-01-17>} % preloaded on demand by \loadmath \_doc ----------------------------- - The control sequences for `\alpha`, `\beta` etc are redefined here. - The `\alpha` expands to the character with Unicode `"03B1`, this is a normal - character $α$. You can type it directly in your editor if you know how - to do this. + Unicode math font includes all typical math alphabets together, user needs no + load more \TeX/ math families. These math alphabets are encoded by + different parts of Unicode table. We need auxiliary macros for setting + mathcodes by selected math alphabet. + \nl + \`\_umathrange` `{<from->-<to>}<class><family>\<first>` sets `\Umathcode`s + of the characters in the interval `<from>-<to>` to `\<first>`, + `\<first>+1`, `\<first>+2` + etc., but \`\_umathcharholes` are skipped + (`\_umathcharholes` are parts of the Unicode table not designed for math + alphabets, they cause that the math alphabets are + not continuously spread out in the table; I mean that the + designers were under the influence of drugs when they created + this part of the Unicode table). + The `<from>-<to>` clause includes characters like~`A-Z`. + Note that the `\_umathrange` sets the \`\_classfam` macro as <class> + <family> for later use. \_cod ----------------------------- -\_umathnumB="0391 -\_greekdef \Alpha \Beta \Gamma \Delta \Epsilon \Zeta \Eta \Theta \Iota \Kappa - \Lambda \Mu \Nu \Xi \Omicron \Pi \Rho \varTheta \Sigma \Tau \Upsilon \Phi - \Chi \Psi \Omega \_relax +\_newcount\_umathnumA \_newcount\_umathnumB -\_umathnumB="03B1 -\_greekdef \alpha \beta \gamma \delta \varepsilon \zeta \eta \theta \iota \kappa - \lambda \mu \nu \xi \omicron \pi \rho \varsigma \sigma \tau \upsilon - \varphi \chi \psi \omega \vardelta \epsilon \vartheta \varkappa \phi - \varrho \varpi \_relax +\_def\_umathcorr#1#2{\_ea#1\_ea{\_the#2}} +\_def\_umathprepare#1{\_def\_umathscanholes##1[#1]##2##3\_relax{##2}} +\_def\_umathvalue#1{\_ea\_umathscanholes\_umathcharholes[#1]{#1}\_relax} + +\_def\_umathcharholes{% holes in math alphabets: + [119893]{"210E}[119965]{"212C}[119968]{"2130}[119969]{"2131}% + [119971]{"210B}[119972]{"2110}[119975]{"2112}[119976]{"2133}[119981]{"211B}% + [119994]{"212F}[119996]{"210A}[120004]{"2134}% + [120070]{"212D}[120075]{"210C}[120076]{"2111}[120085]{"211C}[120093]{"2128}% + [120122]{"2102}[120127]{"210D}[120133]{"2115}[120135]{"2119} + [120136]{"211A}[120137]{"211D}[120145]{"2124}% +} +\_def\_umathrange#1#2#3#4{\_umathnumB=#4\_def\_classfam{#2 #3 }\_umathrangeA#1} +\_def\_umathrangeA#1-#2{\_umathnumA=`#1\_relax + \_loop + \_umathcorr\_umathprepare\_umathnumB + \_Umathcode \_umathnumA = \_classfam \_umathcorr\_umathvalue{\_umathnumB} + \_ifnum\_umathnumA<`#2\_relax + \_advance\_umathnumA by1 \_advance\_umathnumB by1 + \_repeat +} \_doc ----------------------------- - The math alphabets are declared here using the + A few math characters have very specific Unicode and must be handled + individually. We can run \`\_umathrangespec``<list of characters>\relax` + just after \^`\_umathrange`. The `\_umathnumB` must be set to the first + destination code. The \^`\_umathrangespec` applies to each character from + the <list of characters> this: + `\Umathcode``<char-code>=\_classfam\_umathnumB` and increments + `\_umathnumB`. If `\_umathnumB=0` then it applies + `\Umathcode``<char-code>=\_classfam <char-code>`. + The \^`\_classfam` and `\_umathnumB` were typically set by previous call + of the \^`\_umathrange` macro. + \_cod ----------------------------- + +\_def\_umathrangespec#1{\_ifx#1\_relax \_else + \_Umathcode `#1=\_classfam \_ifnum\_umathnumB=0 `#1 \_else \_umathnumB\_fi + \_unless\_ifnum\_umathnumB=0 \_advance\_umathnumB by1 \_fi + \_ea\_umathrangespec \_fi +} + + \_doc ----------------------------- + The math alphabets are set by + \`\_rmvariables`, \`\_bfvariables`, \`\_itvariables`, \`\_bivariables`, + \`\_calvariables`, \`\_bcalvariables`, \`\_frakvariables`, + \`\_bfrakvariables`, \`\_bbvariables`,\nl \`\_sansvariables`, + \`\_bsansvariables`, \`\_isansvariables`, \`\_bisansvariables`, + \`\_ttvariables`,\nl \`\_itgreek`, \`\_rmgreek,` \`\_bfgreek`, \`\_bigreek`, + \`\_bsansgreek`, \`\_bisansgreek`,\nl \`\_itGreek`, \`\_rmGreek`, \`\_bfGreek`, + \`\_biGreek`, \`\_bsansGreek`, \`\_bisansGreek`,\nl \`\_rmdigits`, + \`\_bfdigits`, \`\_bbdigits`, \`\_sansdigits`, \`\_bsansdigits`, + \`\_ttdigits`.\nl + They are declared using the \^`\_umathrange {<range>}<class><family><starting-code>` macro. \_cod ----------------------------- @@ -68,30 +123,12 @@ \_protected\_def\_bigreek {\_umathrangegreek71\_greekbia} \_protected\_def\_bsansgreek {\_umathrangegreek71\_greeksna} \_protected\_def\_bisansgreek{\_umathrangegreek71\_greeksia} -\_protected\_def\_itGreek {\_umathrangeGREEK71\_greekitA \_setnablait} -\_protected\_def\_rmGreek {\_umathrangeGREEK71\_greekrmA \_setnablarm} -\_protected\_def\_bfGreek {\_umathrangeGREEK71\_greekbfA \_setnablabf} -\_protected\_def\_biGreek {\_umathrangeGREEK71\_greekbiA \_setnablabi} -\_protected\_def\_bsansGreek {\_umathrangeGREEK71\_greeksnA \_setnablabsans} -\_protected\_def\_bisansGreek{\_umathrangeGREEK71\_greeksiA \_setnablabisans} - - \_doc ----------------------------- - \`\_setnabla` is used in order to `\nabla` behaves like uppercase Greek - letter, similar like `\Delta`. It depends on `\bf`, `\it` etc. selectors. - If you want to deactivate this behavior, use `\def\_setnabla#1 {}`. - \_cod ----------------------------- - -\_def \_setnabla {\_Umathcode"2207 = 7 1} -\_def \_setnablarm {\_setnabla"02207 } -\_def \_setnablabf {\_setnabla"1D6C1 } -\_def \_setnablait {\_setnabla"1D6FB } -\_def \_setnablabi {\_setnabla"1D735 } -\_def \_setnablabsans {\_setnabla"1D76F } -\_def \_setnablabisans {\_setnabla"1D7A9 } - - \_doc ----------------------------- - Digits are configured like math alphabets. - \_cod ----------------------------- +\_protected\_def\_itGreek {\_umathrangeGREEK71\_greekitA} +\_protected\_def\_rmGreek {\_umathrangeGREEK71\_greekrmA} +\_protected\_def\_bfGreek {\_umathrangeGREEK71\_greekbfA} +\_protected\_def\_biGreek {\_umathrangeGREEK71\_greekbiA} +\_protected\_def\_bsansGreek {\_umathrangeGREEK71\_greeksnA} +\_protected\_def\_bisansGreek{\_umathrangeGREEK71\_greeksiA} \_chardef\_digitrmO=`0 \_chardef\_digitbfO="1D7CE @@ -108,6 +145,59 @@ \_protected\_def\_ttdigits {\_umathrange{0-9}71\_digitttO} \_doc ----------------------------- + The control sequences for `\alpha`, `\beta`, etc.\ are redefined here. + The `\alpha` will expand to the character with Unicode `"03B1`, this is a normal + character $α$. You can type it directly in your editor if you know how + to do this. These sequences are declared by + `\_greekdef``<list of sequences>\relax`. + \_cod ----------------------------- + +\_def\_greekdef#1{\_ifx#1\_relax + \_else + \_edef#1{\_Uchar\_umathnumB}% + \_advance\_umathnumB by 1 + \_ea\_greekdef \_fi +} +\_umathnumB="0391 +\_greekdef \Alpha \Beta \Gamma \Delta \Epsilon \Zeta \Eta \Theta \Iota \Kappa + \Lambda \Mu \Nu \Xi \Omicron \Pi \Rho \varTheta \Sigma \Tau \Upsilon \Phi + \Chi \Psi \Omega \_relax + +\_umathnumB="03B1 +\_greekdef \alpha \beta \gamma \delta \varepsilon \zeta \eta \theta \iota \kappa + \lambda \mu \nu \xi \omicron \pi \rho \varsigma \sigma \tau \upsilon + \varphi \chi \psi \omega \_relax + + \_doc ----------------------------- + The \`\_umathrangeGREEK``<class><family><first>` and + \`\_umathrangegreek``<class><family><first>` macros + for setting math codes of Greek characters are defined here. They use \^`\_umathrange` + for general codes but the exceptions must be handled by the + \^`\_umathrangespec` macro. + The exceptions are seven Greek characters: + $\epsilon, \vartheta, \varkappa, \phi, \varrho, \varpi, \nabla$. + The first six of these characters should behave as lowercase Greek letters + and the last one `\nabla` is uppercase Greek letter. + \_cod ----------------------------- + +\_def\epsilon{^^^^03f5} \_def\vartheta{^^^^03d1} \_def\varkappa{^^^^03f0} +\_def\phi{^^^^03d5} \_def\varrho{^^^^03f1} \_def\varpi{^^^^03d6} +\_def \nabla{^^^^2207} + +\_def\_umathrangeGREEK#1#2#3{\_umathrange{^^^^0391-^^^^03a9}#1#2#3% \Alpha-\Omega + \_resetnabla % you can do \let\_resetnabla=\relax if you don't want to change \nabla shape +} +\_def\_resetnabla {% + \_ifnum\_umathnumB<950 \_umathnumB=0 \_else \_advance\_umathnumB by1 \_fi + \_umathrangespec ^^^^2207\_relax % \nabla +} +\_def\_umathrangegreek#1#2#3{% + \_umathrange{^^^^03b1-^^^^03c9}#1#2#3% \alpha-\omega + \_ifnum#3=\_greekrma \_umathnumB=0 \_else \_advance\_umathnumB by2 \_fi + \_umathrangespec ^^^^03f5^^^^03d1^^^^03f0^^^^03d5^^^^03f1^^^^03d6\_relax % \epsilon-\varpi +} + + \_doc ----------------------------- The math alphabets \`\cal`, \`\bbchar`, \`\frak`, \`\script` are re-defined here. The \`\_marm`, \`\_mabf`, \`\_mait`, \`\_mabi`, \`\_matt` used in \^`\rm`, \^`\bf`, \^`\it`, \^`\bi` are re-defined too.\nl @@ -145,7 +235,7 @@ Each Unicode slot carries information about math type. This is saved in the file `MathClass-15.txt` which is copied to `mathclass.opm` The file has the following format: - {\vitt{mathclass.opm}\verbinput (70-85) mathclass.opm } + {\vitt{mathclass.opm}\verbinput (70-85) mathclass.opm }% We have to read this information and convert it to the `\Umathcode`s. \_cod ----------------------------- @@ -170,34 +260,62 @@ \_doc ----------------------------- Each math symbol has its declaration in the file `unicode-math-table.tex` which is copied to `unimath-table.opm`. The file has the following format: - {\vitt{unimath-table.opm}\verbinput (36-41) unimath-table.opm } - We have to read this information and set given control sequences to - the relevant Unicode characters using `\chardef`. We don't use `\mathchardef` - for them because the want to manage the matcodes (class, family, slot) - only at single place: at Unicode characters. Control sequeces declared here - are only pointers to these Unicode characters. Exceptions are delimiters and - math accents.\nl - If the character is delimiter then we declare \_d:<sequence> to be the - `\chardef` equivalent of the character and `\let<sequence>=<character>` - because `\left`, `\right` doesn't like `\chardef` equivalent of the - character although it has its own delcode. + {\vitt{unimath-table.opm}\verbinput (36-41) unimath-table.opm }% + We have to read this information and set given control sequences as macros + which expand to the given Unicode character. This solution enables to use + such control sequences in PDF outlines where they expand to the appropriate + Unicode character. + We don't use `\mathchardef`, we set the mathcodes (class, family, slot) + only at single place: for Unicode math characters. For example for we + define `\times`: + \begtt + \def\times{^^d7} \Umathcode "D7 = 2 1 "D7 + \endtt + Because math codes of Greek upright letters vary depending on + \^`\_itgreek`, \^`\_bfgreek`, + etc.\ macros, we need to keep the access directly to these characters. + We define `\mupalpha`, `\mupbeta`, ..., `\mupomega` macros as a code from + PUA (Private Use Area) of Unicode table and set mathcode of these + codes to the real upright alpha, beta, ..., omega. \_cod ----------------------------- \_begingroup % \input unimath-table.opm (it is a copy of unicode-math-table.tex): + \_umathnumB="F800 % pointer to the Private User Area \_def\UnicodeMathSymbol #1#2#3#4{% - \_chardef#2=#1 % control sequence is only pointer to Unicode character + \_edef#2{\_Uchar #1}% control sequence is a macro which expands to the Unicode character \_ifnum#1=\_Umathcodenum#1 \_Umathcode#1=0 1 #1 \_fi % it isn't set by mathclass.opm - \_ifx#3\_mathopen \_setdelimiter#2\_fi - \_ifx#3\_mathclose \_setdelimiter#2\_fi - \_ifx#3\mathfence \_setdelimiter#2\_fi \_ifx#3\_mathaccent \_protected\_def#2{\_Umathaccent fixed 7 1 #1 }\_fi + \_ifnum#1>"390 \_ifnum#1<"3F6 + \_edef#2{\_Uchar\_umathnumB}% \mupAlpha, \mupBeta, \mupalpha, \mupbeta, ... + \_Umathcode\_umathnumB=0 1 #1 + \_advance\_umathnumB by1 + \_fi\_fi % \muGreek, \mugreek symbols } \_def\mathfence{F}% - \_def\_setdelimiter#1{\_expanded{\_let\_cs{_d:\_csstring#1}=#1\_let#1=\Uchar#1}} \_globaldefs=1 \_input unimath-table.opm \_endgroup \_doc ----------------------------- + The macro `\int` expands to an <int-character>. We save the `\mathcode` + of the <int-character> to `\_int:<int-character>` using `\Umathchardef` and + declare <int-character> as math-active and define it + as `\_int:<int-character> \_nolimits`. Moreover, we define `\intop` as + `\_int:<int-character>` (it is the itegral with limits like in plain \TeX). + We do this with other int-like operators listed below too. + \_cod ----------------------------- + +\_def\_intwithnolimits#1{\_ifx#1\_relax \_else + \_ea\_Umathcharnumdef\_csname _int:#1\_endcsname=\_Umathcodenum\_ea`#1 % + \_ea\_def \_csname\_csstring#1op\_ea\_endcsname\_ea{\_csname _int:#1\_endcsname}% + \_bgroup \_lccode`\~=\_ea`#1 \_lowercase{\_egroup + \_ea\_def\_ea~\_ea{\_csname _int:#1\_endcsname\_nolimits}\_mathcode`~="8000 }% + \_ea \_intwithnolimits \_fi +} +\_intwithnolimits \int \iint \iiint \oint \oiint \oiiint + \intclockwise \varointclockwise \ointctrclockwise \sumint \iiiint \intbar \intBar \fint + \pointint \sqint \intlarhk \intx \intcap \intcup \upint \lowint \_relax + + \_doc ----------------------------- Many special characters must be declared with care... \_cod ----------------------------- @@ -227,29 +345,8 @@ \_protected\_def \_cuberoot {\_Uradical 1 "0221B } \_protected\_def \_fourthroot {\_Uradical 1 "0221C } -\_def \nabla {^^^^2207} % \nabla behaves as uppercase Gereek letter, see \_setnabla - \_public \sqrt \cuberoot \fourthroot ; - \_doc ----------------------------- - We save the `\mathcode` of `\int` to `\_intop` using `\Umathchardef` and - declare Unicode character `\int` as math-active and define it - as `\_intop\_nolimits`. We define `\intop` as `\_intop` for users - (intergral with normal limits). - We do this with other int-like operators listed below too. - \_cod ----------------------------- - -\_def\_intwithnolimits#1{\_ifx#1\_relax \_else - \_ea\_Umathcharnumdef\_csname _\_csstring#1op\_endcsname=\_Umathcodenum#1% - \_ea\_def \_csname\_csstring#1op\_ea\_endcsname\_ea{\_csname _\_csstring#1op\_endcsname}% - \_bgroup \_lccode`\~=#1 \_lowercase{\_egroup - \_ea\_def\_ea~\_ea{\_csname _\_csstring#1op\_endcsname\_nolimits}\_mathcode`~="8000 }% - \_ea \_intwithnolimits \_fi -} -\_intwithnolimits \int \iint \iiint \oint \oiint \oiiint - \intclockwise \varointclockwise \ointctrclockwise \sumint \iiiint \intbar \intBar \fint - \pointint \sqint \intlarhk \intx \intcap \intcup \upint \lowint \_relax - \_protected\_def \_overbrace #1{\_mathop {\_Umathaccent 7 1 "023DE{#1}}\_limits} \_protected\_def \_underbrace #1{\_mathop {\_Umathaccent bottom 7 1 "023DF{#1}}\_limits} \_protected\_def \_overparen #1{\_mathop {\_Umathaccent 7 1 "023DC{#1}}\_limits} @@ -366,6 +463,8 @@ \_let \upvartheta=\mupvartheta \_let \upphi=\mupphi \_let \upvarpi=\mupvarpi +\_let \varTheta=\mupvarTheta +\_let \vardelta=\delta \_doc ----------------------------- The \`\not` macro is redefined here. If the `\_not!<char>` is defined @@ -450,10 +549,9 @@ Example of using additional math font is in section 5.3 in the \ulink[http://petr.olsak.net/ftp/olsak/optex/optex-math.pdf]{\tt optex-math.pdf} documentation - -You can combine more Unicode math fonts in single formula simply -by the `\addUmathfont` macro, see -\ulink[http://petr.olsak.net/optex/optex-tricks.html#addumathfont]{\OpTeX/ trick 0030}. +More examples are in the +\ulink[http://petr.olsak.net/optex/optex-tricks.html]{OpTeX tricks} and in the +\ulink[https://petr.olsak.net/ftp/olsak/optex/math-doc.pdf]{math.opm} package. See \url{http://tex.stackexchange.com/questions/308749} for technical details about Unicode-math. @@ -461,6 +559,11 @@ for technical details about Unicode-math. \_endinput History: +2023-01-17 \int operators re-implemented +2023-01-15 \mupalpha, \mupbeta etc. have codes from PUA +2023-01-15 math control sequences are macros, they expand to math characters +2023-01-14 \epsilon, \vartheta, \varkappa, \phi, \varrho, \varpi, ... bug fix +2023-01-13 \mupalhpha, \mupbeta, ... bug fix 2022-11-20 \mathfence's get delimiter code too 2022-11-18 Delimiters re-implemented 2022-11-17 \Umathchardef replaced by \chardef diff --git a/Master/texmf-dist/tex/optex/base/unimath-macros.opm b/Master/texmf-dist/tex/optex/base/unimath-macros.opm index 96f87a6a9b3..d4cd9e5540a 100644 --- a/Master/texmf-dist/tex/optex/base/unimath-macros.opm +++ b/Master/texmf-dist/tex/optex/base/unimath-macros.opm @@ -1,6 +1,6 @@ %% This is part of the OpTeX project, see http://petr.olsak.net/optex -\_codedecl \loadmath {Unicode Math fonts <2022-12-01>} % preloaded in format +\_codedecl \loadmath {Unicode Math fonts <2023-01-17>} % preloaded in format \_doc ----------------------------- \`\loadmath` `{<Unicode-math font>}` loads the given font. It does: @@ -143,66 +143,6 @@ \_def\_mparams{} \_doc ----------------------------- - Unicode math font includes all typical math alphabets together, user needs not to - load more \TeX/ math families. These math alphabets are encoded by - different parts of Unicode table. We need auxiliary macros for setting - mathcodes by selected math alphabet. - \nl - \`\_umathrange` `{<from->-<to>}<class><family>\<first>` sets `\Umathcode`s - of the characters in the interval `<from>-<to>` to `\<first>`, - `\<first>+1`, `\<first>+2` - etc., but \`\_umathcharholes` are skipped - (`\_umathcharholes` are parts of the Unicode table not designed for math - alphabets, they cause that the math alphabets are - not continuously spread out in the table; I mean that the - designers were under the influence of drugs when they created - this part of the Unicode table). - The `<from>-<to>` clause includes characters like~`A-Z`. - \nl - \`\_umahrangegreek` `\<first>` is the same as - `\_umathrange {<alpha>-<omega>}\<first>`. - \nl - \`\_umahrangeGREEK` `\<first>` is the same as - `\_umathrange {<Alpha>-<Omega>}\<first>`. - \nl - \`\_greekdef` `<control sequences> \_relax` defines each control sequence - as a normal character with codes `\_umathnumB`, `\_umathnumB+1`, - `\_umathnumB+2` etc. It is used for redefinig the contol sequences for - math Greek `\alpha`, `\beta`, `\gamma` etc. - \_cod ----------------------------- - -\_newcount\_umathnumA \_newcount\_umathnumB - -\_def\_umathcorr#1#2{\_ea#1\_ea{\_the#2}} -\_def\_umathprepare#1{\_def\_umathscanholes##1[#1]##2##3\_relax{##2}} -\_def\_umathvalue#1{\_ea\_umathscanholes\_umathcharholes[#1]{#1}\_relax} - -\_def\_umathcharholes{% holes in math alphabets: - [119893]{"210E}[119965]{"212C}[119968]{"2130}[119969]{"2131}% - [119971]{"210B}[119972]{"2110}[119975]{"2112}[119976]{"2133}[119981]{"211B}% - [119994]{"212F}[119996]{"210A}[120004]{"2134}% - [120070]{"212D}[120075]{"210C}[120076]{"2111}[120085]{"211C}[120093]{"2128}% - [120122]{"2102}[120127]{"210D}[120133]{"2115}[120135]{"2119} - [120136]{"211A}[120137]{"211D}[120145]{"2124}% -} -\_def\_umathrange#1#2#3#4{\_umathnumB=#4\_def\_tmp{#2 #3 }\_umathrangeA#1} -\_def\_umathrangeA#1-#2{\_umathnumA=`#1\_relax - \_loop - \_umathcorr\_umathprepare\_umathnumB - \_Umathcode \_umathnumA = \_tmp \_umathcorr\_umathvalue{\_umathnumB} - \_ifnum\_umathnumA<`#2\_relax - \_advance\_umathnumA by1 \_advance\_umathnumB by1 - \_repeat -} -\_def\_umathrangeGREEK{\_umathrange{^^^^0391-^^^^03a9}} -\_def\_umathrangegreek{\_umathrange{^^^^03b1-^^^^03d6}} -\_def\_greekdef#1{\_ifx#1\_relax \_else - \_begingroup \_lccode`X=\_umathnumB \_lowercase{\_endgroup \_def#1{X}}% - \_advance\_umathnumB by 1 - \_ea\_greekdef \_fi -} - - \_doc ----------------------------- \`\addUmathfont` `<fam> {[<normal-font>]}{<ffeatures>} {[<bold-font>]}{<ffeatures>} {<factor>}` allocates new <fam> using \^`\newfam` and adds loading this font to the \~`\normalmath` and \~`\boldmath` macros. Note that allocationos using @@ -230,16 +170,34 @@ } \_doc ----------------------------- + The math characters can be given directly (by their Unicode) or by a macro + like `\doteq`, `\times`, etc. These macros simply expand to the math character + with its Unicode. And this math character has its `\Umathcode` given by + <class>, <family>, <slot-number>. Sometimes, we may want to get these + quantities from the given Unicode math character by our macros. It is + possible by \`\themathcodeclass``<math-char>`, + \`\themathcodefam``<math-char>` and \`\themathcodechar``<math-char>` macros. + The parameter <math-char> is a math character or it is a macro like `\doteq`, `\times`. + Moreower, \`\thedelcodefam``<math-char>` and \`\thedelcodechar``<math-char>` + return delcode quaitities of givem math character. + \_cod ----------------------------- + +\_def\_getmathcode#1#2{\_directlua{tex.print(tex.get#2code(token.scan_int())[#1])}} +\_def\_themathcodeclass #1{\_getmathcode 1{math}\_ea`#1 } +\_def\_themathcodefam #1{\_getmathcode 2{math}\_ea`#1 } +\_def\_themathcodechar #1{\_getmathcode 3{math}\_ea`#1 } +\_def\_thedelcodefam #1{\_getmathcode 1{del}\_ea`#1 } +\_def\_thedelcodechar #1{\_getmathcode 2{del}\_ea`#1 } + +\_public \themathcodeclass \themathcodefam \themathcodechar \thedelcodefam \thedelcodechar ; + + \_doc ----------------------------- \`\mathchars` `<fam> {<list of sequences>}` saves <fam> to \`\_mafam` and runs for each sequence from the <list of sequences> - the relevant code settings. - The `\directlua` chunk prints the 8-digits hexadecimal code of the - sequence followed by the sequence itself. The digts are scanned by \`\_mathcharsB` - and new `\Umathcode` is declared.\nl - If there exist \_d:<sequence> (i.e.\ it is delimiter) then `\Udelcode` is - redeclared too. Finally, in case of `\int`-like operators the - `\_intop` sequence is redeclared by `\Umathchardef`. Note that the used - primitives have the syntax: + the relevant code settings using `\Umathcode` primitive. + In case of `\int`-like operators the <math class>=8 and we only + re-declare `\_int:<int-character>` as an operator with the new \^`\_mafam`. + Note that the used primitives have the syntax: \begtt \catcode`<=13 \Umathchardef <sequence> = <math class> <math family> <slot number> \Umathcode <code> = <math class> <math family> <slot number> @@ -249,20 +207,13 @@ \_def\_mathchars {\_afterassignment\_mathcharsA \_chardef\_mafam=} \_def\_mathcharsA #1{\_foreach #1\_do{% - \_ifcsname _d:\_csstring##1\_endcsname \_ea \_mathcharsD \_csname _d:\_csstring##1\_endcsname - \_else \_mathcharsC ##1\_fi -}} -\_def\_mathcharsC #1{\_ea\_mathcharsB - \_directlua{tex.print(string.format("\_pcent08X", \_the\_Umathcode#1))}#1% -} -\_def\_mathcharsB #1#2#3#4#5#6#7#8#9{% #9 is given \math-sequence - \_ifcsname _\_csstring#9op\_endcsname - \_ea \_Umathchardef \_csname _\_csstring#9op\_endcsname=1 \_mafam #9\_relax + \_chardef\_tmp=\_themathcodeclass##1\_relax + \_ifnum\_tmp=8 % \int, \iint, \oint, etc. + \_ea\_Umathchardef \_csname _int:##1\_endcsname =1 \_mafam \_ea`##1 \_else - \_Umathcode "#4#5#6#7#8=\_numexpr"#3/2\_relax \_mafam "#4#5#6#7#8 + \_Umathcode \_ea`##1=\_tmp \_mafam \_themathcodechar##1 \_fi -} -\_def\_mathcharsD #1{\_mathcharsC #1\_relax \_Udelcode #1=\_mafam #1\_relax} +}} \_doc ----------------------------- \`\mathcodes` `<fam> {<list of pairs>}` sets mathcodes of given @@ -276,10 +227,10 @@ \_def\_mathcodes{\_afterassignment\_mathcodesA\_chardef\_mafam=} \_def\_mathcodesA#1{% \_foreach #1\_do ##1##2{% - \_ea\_foreach\_expanded{##2}\_do{\_Umathcode `####1=##1\_mafam`####1}% + \_ea\_foreach\_expanded{##2}\_do{\_Umathcode `####1=##1\_mafam \_ea`####1}% }% } -\_def\_Urange #1-#2{\_fornum `#1..`#2\_do{\_Uchar##1 }} +\_def\_Urange #1-#2{\_fornum \_ea`#1..\_ea`#2\_do{\_Uchar##1 }} \_public \addUmathfont \mathchars \mathcodes \Urange ; @@ -351,7 +302,8 @@ in the <list-of-pairs> is `<class-number><character>` (separated by optional space) or `<class-number>{<list-of-characters>}`. The <list-of-characters> includes declared characters or \^`\Urange` `<from>-<to>` which is equal to the list of characters beginning <from> and ending <to>, for example -`\Urange a-d` is equal to `abcd`. +`\Urange a-d` is equal to `abcd`. The characters can be given directly or +by the math sequences like `\times`, `\doteq` too. The \^`\mathcodes` macro declares mathcode of given characters internally by \begtt \catcode`<=13 @@ -385,6 +337,9 @@ the section~\ref[math-macros]. \_endinput +2023-01-17 \mathchars: \int operators re-implemented +2023-01-15 \_def\_umathrange moved to unimath-codes.opm +2023.01-15 \themathcodeclass etc. introduced 2022-12-01 reading number by \_loadumathfamily more robust 2022-11-18 \mathchars improved, \Udelcodes are set too, \addUmathfont uses \ahead 2022-11-17 \Umathchardef replaced by \chardef diff --git a/Master/texmf-dist/tex/optex/pkg/math.opm b/Master/texmf-dist/tex/optex/pkg/math.opm index 5b0f29dd2f9..50853b013a2 100644 --- a/Master/texmf-dist/tex/optex/pkg/math.opm +++ b/Master/texmf-dist/tex/optex/pkg/math.opm @@ -3,11 +3,36 @@ % This file can serve as an template for other package files % See end of the file for more information -\_def\_math_version {0.02, 2022-11-26} -\_codedecl \replacemissingchars {Doing math more comfortable <\_math_version>} +\_def\_math_version {0.08, 2023-01-28} +\_codedecl \replacemissingchars {Doing math more comfortably <\_math_version>} \_namespace{math} \_doc + The `math` package provides options, they can be declared using + the \`\mathset``{<options>}` macro. For example `\mathset {vert, dots}`. + If you create your own package with options, provide a similar + `\<pkg>set` macro. The \`\.kv` macro is similar to \OpTeX's `\kv`, but + with specific `pkg:math` dictionary. + \_cod + +\_def\.mathset #1{% + \_edef\.restorekvdict{\_kvdict{\_the\_kvdict}}% + \_kvdict{pkg:math}% + \_nokvx {\_opwarning{\_the\_kvdict: unknown option "##1", ignored}}% + \_kvx {vert} {\.smartvert}% sets | as math active, to do better |x| or ||x|| + \_kvx {dots} {\.smartdots}% \dots behaves like \ldots or \cdots + \_kvx {bfserif} {\.bfserif}% \bf, \bi select fonts with serifs + \_kvx {rmchars} {\.rmchars{##1}}% does \.rmchars{<list>} + \_kvx {vargreek} {\.vargreek{##1}}% does \.vargreek{<list>} + \_kvx {text} {\.dotext{##1}}% does \.dotext{<list>} + \_readkv{#1}% + \.restorekvdict +} +\_def\.kv #1{\_trycs{_kv:pkg:math:#1}{\_kvunknown}}% for accessing values given by \mathset + +\_nspublic \mathset ; + + \_doc \`\bigp`, \`\Bigp`, \`\biggp`, \`\Biggp`, \`\autop`, \`\normalp` are inspired from \tricklink[bigp]{0094} \_cod @@ -22,11 +47,12 @@ \_isequal .{#1}\_iffalse #1\_fi \_let\.bigleft=#2\_let\.bigright=#3\_nospacefuturelet\.next\.fparamA} \_def\.fparamA{% - \_ifx\.next(\.afterrelax{\.fparamB()}\_fi - \_ifx\.next[\.afterrelax{\.fparamB[]}\_fi - \_ifx\.next\{\.afterrelax{\.fparamB\{\}}\_fi - \_ifx\.next\_bgroup \_def\.lparen{\{}\_def\.rparen{\}}\.afterrelax{\.fparamC}\_fi - \_relax + \_casesof \.next + ( {\.fparamB()}% + [ {\.fparamB[]}% + \{ {\.fparamB\{\}}% + \_bgroup {\_def\.lparen{\{}\_def\.rparen{\}}\.fparamC}% + \_finc {}% } \_def\.fparamB#1#2{% \_def\.lparen{#1}\_def\.rparen{#2}% @@ -34,16 +60,14 @@ \.next } \_def\.fparamC#1{% - \_ifx\.bigleft\_left \_mathopen{}\_fi + \_ifx\.bigleft\_left \_mathopen{}\_bgroup\_fi \.bigleft\.lparen{#1}\.bigright\.rparen - \_ifx\.bigright\_right \_mathclose{}\_fi + \_ifx\.bigright\_right \_egroup\_fi } -\_def\.afterrelax#1#2\_relax{\_fi#1} - \_nspublic \bigp \Bigp \biggp \Biggp \autop \normalp ; \_doc - We need macro \`\.ensurebalanced` for balancing nested parentheses from + We need macro \`\.ensurebalanced``<open-b><close-b><macro>` for balancing nested parentheses from \tricklink[balancing]{0043}. We use `trick` namespace for these macros. \_cod @@ -97,7 +121,7 @@ \_nspublic \smartdots ; \_doc - \`\smartvert` sets `|` as math-active charcter and declares it + \`\smartvert` sets `|` as math-active character and declares it equal to `\.autovert` macro. This macro checks two variants: there is single `|` or there is double `||`. It runs \`\.autovertA` or \`\.autoVertA`. These macros find the closing `|` or `||` and use @@ -105,7 +129,7 @@ is declared here if a user want to use a single vertical bar. \_cod -\_newpublic \_mathchardef \_singlevert=\_mathcode`| +\_newpublic\_mathchardef \singlevert=\_mathcode`| \_def\.autovert {\_isnextchar|{\.autoVertA}{\.autovertA}} \_def\.autovertA #1|{\_mathopen{}\_mathclose{\_left|#1\_right|}} \_def\.autoVertA|#1||{\_mathopen{}\_mathclose{\_left‖#1\_right‖}} @@ -117,37 +141,68 @@ \_doc The control sequences \`\N`, \`\Z`, \`\Q`, \`\R`, \`\C` \`\sgn`, \`\argmin`, \`\argmax`, \`\grad`, \`\rank`, \`\tr`, \`\diag`, \`\Span`, - \`\Rng`, \`\Null`, \`\Ker`, \`\Res`, \`\tg`, \`\arctg`, + \`\Rng`, \`\Null`, \`\Ker`, \`\Res`, \`\tg`, \`\cotg`, \`\arctg`, \`\arccotg`, \`\frac`, \`\dfrac`, \`\tfrac`, \`\.` are defined directly in the user space by \o`\_newpublic`. + The \`\.pdef` is a shortcut for `\protected\def`. \_cod -\_newpublic\_def \N {{\_bbchar N}} -\_newpublic\_def \Z {{\_bbchar Z}} -\_newpublic\_def \Q {{\_bbchar Q}} -\_newpublic\_def \R {{\_bbchar R}} -\_newpublic\_def \C {{\_bbchar C}} - -\_newpublic\_def \sgn {\_mathop{\_rm sgn}\_nolimits} -\_newpublic\_def \argmin {\_mathop{\_rm argmin}} -\_newpublic\_def \argmax {\_mathop{\_rm argmax}} -\_newpublic\_def \grad {\_mathop{\_rm grad}\_nolimits} -\_newpublic\_def \rank {\_mathop{\_rm rank}\_nolimits} -\_newpublic\_def \tr {\_mathop{\_rm tr}\_nolimits} -\_newpublic\_def \diag {\_mathop{\_rm diag}\_nolimits} -\_newpublic\_def \Span {\_mathop{\_rm Span}\_nolimits} -\_newpublic\_def \Rng {\_mathop{\_rm Rng}\_nolimits} -\_newpublic\_def \Null {\_mathop{\_rm Null}\_nolimits} -\_newpublic\_def \Ker {\_mathop{\_rm Ker}\_nolimits} -\_newpublic\_def \Res {\_mathop{\_rm Res}\_nolimits} -\_newpublic\_def \tg {\_mathop{\_rm tg}\_nolimits} -\_newpublic\_def \arctg {\_mathop{\_rm arctg}\_nolimits} - -\_newpublic\_def \frac #1#2{{{#1}\_over#2}} -\_newpublic\_def \dfrac #1#2{{\_displaystyle{{#1}\_over#2}}} -\_newpublic\_def \tfrac #1#2{{\_textstyle{{#1}\_over#2}}} - -\_newpublic\_def \.#1{{\_bf#1}} +\_def\.pdef{\_protected\_def} + +\_newpublic\.pdef \N {{\_bbchar N}} +\_newpublic\.pdef \Z {{\_bbchar Z}} +\_newpublic\.pdef \Q {{\_bbchar Q}} +\_newpublic\.pdef \R {{\_bbchar R}} +\_newpublic\.pdef \C {{\_bbchar C}} + +\_newpublic\.pdef \sgn {\_mathop{\_rm sgn}\_nolimits} +\_newpublic\.pdef \argmin {\_mathop{\_rm argmin}} +\_newpublic\.pdef \argmax {\_mathop{\_rm argmax}} +\_newpublic\.pdef \grad {\_mathop{\_rm grad}\_nolimits} +\_newpublic\.pdef \rank {\_mathop{\_rm rank}\_nolimits} +\_newpublic\.pdef \tr {\_mathop{\_rm tr}\_nolimits} +\_newpublic\.pdef \diag {\_mathop{\_rm diag}\_nolimits} +\_newpublic\.pdef \Span {\_mathop{\_rm Span}\_nolimits} +\_newpublic\.pdef \Rng {\_mathop{\_rm Rng}\_nolimits} +\_newpublic\.pdef \Null {\_mathop{\_rm Null}\_nolimits} +\_newpublic\.pdef \Ker {\_mathop{\_rm Ker}\_nolimits} +\_newpublic\.pdef \Res {\_mathop{\_rm Res}\_nolimits} +\_newpublic\.pdef \tg {\_mathop{\_rm tg}\_nolimits} +\_newpublic\.pdef \cotg {\_mathop{\_rm cotg}\_nolimits} +\_newpublic\.pdef \arctg {\_mathop{\_rm arctg}\_nolimits} +\_newpublic\.pdef \arccotg {\_mathop{\_rm arccotg}\_nolimits} + +\_newpublic\.pdef \frac #1#2{{{#1}\_over#2}} +\_newpublic\.pdef \dfrac #1#2{{\_displaystyle{{#1}\_over#2}}} +\_newpublic\.pdef \tfrac #1#2{{\_textstyle{{#1}\_over#2}}} + +\_newpublic\.pdef \.#1{{\_bf#1}} + + \_doc + \`\eqsystem``{<equations>}` saves its parameter to `\.tmpb` + and does a collection of `\_replstring`s. It replaces all spaces by `&` + (but ignores the optional first and last space), it removes spaces before `\cr`, + it precedes `\mathord` before all `-` + (but not if the minus is alone in the column) and runs `\halign`. + The \n`\baselineskip` is enlarged by \O`\openup`\`\eqskip`. + Each item adds 0.5\`\eqsep` around it and \`\eqfil` to the left side and + `\hfil` to the right side. + \_cod + +\_protected \_optdef\.eqsystem[]#1{\_vcenter{% + \_def\.tmpb{\.bb#1\.bb}\_replstring\.tmpb{ }{&}% + \_replstring\.tmpb{\.bb&}{}\_replstring\.tmpb{&\.bb}{}\_replstring\.tmpb{&\cr}{\cr}% + \_replstring\.tmpb{-}{\_mathord-}\_replstring\.tmpb{&\_mathord-&}{&-&}% + \_let ~=\_relax + \_the\_opt \_relax \_openup\.eqskip + \_halign{&\_the\.eqfil\_kern.5\.eqsep$\_displaystyle{{}##{}}$\_kern.5\.eqsep\_hfil\_cr + \.tmpb\_crcr}% +}} +\_let\.bb=\_empty +\_newdimen\.eqskip +\_newdimen\.eqsep +\_newtoks\.eqfil \.eqfil={\_hfill} +\_nspublic \eqsystem \eqskip \eqsep \eqfil ; \_doc The \`\toright` and \`\toleft` macros are based on the @@ -168,7 +223,7 @@ \_doc The \`\subeqmark` works because the internal \O`\_thednum` is re-defined. The \`\.dnumpost` is added here. If you want to use another format - for \O`\_thednum` then you have to add the \`\.dnumpost` to it too. + for \O`\_thednum` then you have to add the \^`\.dnumpost` to it too. \_cod \_def \_thednum {(\_the\_dnum \.dnumpost)} @@ -178,12 +233,43 @@ \_nspublic \subeqmark ; \_doc + \`\bfserif` re-defines internal \OpTeX/ \O`\_mabf` and \O`\_mabi` macros. + \_cod + +\_def\bfserif{% + \_protected\_def\_mabf {\_inmath{\_bfvariables\_bfgreek\_bfGreek\_bfdigits}}% + \_protected\_def\_mabi {\_inmath{\_bivariables\_bigreek\_bfGreek\_bfdigits}}% +} + + \_doc + \`\rmchars``{<list>}` is implemented using \O`\foreach`. The list is + expanded first because we want to expand control sequences like `\alpha` + to a real character $\_rmgreek \alpha$.\nl + \`\vargreek``{<list>}` is implemented using \O`\foreach`. The + parameter is not expanded because we want to keep control sequences like + `\alpha` unchanged. + \_cod + +\_def\.rmchars#1{\_ea\_foreach \_expanded{#1}\_do{\_ifx,##1\_else\.rmchar##1\_fi}} +\_def\.rmchar#1{\_Umathcode`#1=0 1 `#1 } + +\_def\.vargreek#1{\_foreach#1\_do{\_ifx,##1\_else \.vargreekchar##1\_fi}} +\_def\.vargreekchar#1{% + \_ifcsname var\_csstring#1\_endcsname \_slet{\_csstring#1}{var\_csstring#1}% + \_else \_opwarning{\_string\vargreek: the \_bslash var\_csstring#1\_space doesn't exists}% + \_fi +} +\_nspublic \rmchars \vargreek ; + + \_doc \`\textvariables`, \`\textdigits`, \`\textmoremath` initialize new two families 5, 6 using `\.textmathini` and sets `\mathcode`s of given characters to these families. Moreover, `\textvariables` adds `\fam` register setting to `\rm` and `\it` selectors and re-set Greek variables to use only math font (because we - are not sure if Greek letters are in the current text fonts). + are not sure if Greek letters are in the current text fonts).\nl + \`\.dotext``{<list of words>}` runs `\.text<word>` for each <word> in the list. + It is used when the option `text={<list of words>}` is used. \_cod \_def\.textmathini{% @@ -204,8 +290,8 @@ \_addto\_marm {\_fam5 }\_addto\_mait{\_fam6 }% \_protected\_def\_itgreek {\_umathrangegreek01\_greekita}% \_protected\_def\_rmgreek {\_umathrangegreek01\_greekrma}% - \_protected\_def\_itGreek {\_umathrangeGREEK01\_greekitA \_setnablait} - \_protected\_def\_rmGreek {\_umathrangeGREEK01\_greekrmA \_setnablarm} + \_protected\_def\_itGreek {\_umathrangeGREEK01\_greekitA} + \_protected\_def\_rmGreek {\_umathrangeGREEK01\_greekrmA} \_itgreek \_rmGreek } \_def\.textdigits {\.textmathini \_mathcodes 5 {7{\_Urange 0-9}}} @@ -213,6 +299,9 @@ \_mathcodes 5 {5{!?} 2{*+-} 3{=<>} 6{,:;} 0{./|} 4{([\{} 5{\})]}}% \_Umathcode `- = 2 5 "2212 % hyphen behaves like minus in math mode } +\_def\.dotext#1{\_foreach #1 \_do + ##1 {\_trycs{_math_text##1}{\_opwarning{text option: "##1" unknown}}}} + \_nspublic \textvariables \textdigits \textmoremath ; \_doc @@ -226,7 +315,7 @@ replaced again if a new `\replacemissingchars` is used. \_cod -\_def\.rlist{} +\_def\.rlist{\sqrt\cuberoot\fourthroot} % they cannot be replaced by \mathchars \_def\.replacemissingchars#1{% \_def\.alist{}\_def\.clist{} \_def\UnicodeMathSymbol##1##2##3##4{% @@ -242,9 +331,9 @@ } \_input unimath-table.opm \_wlog{^^J\_string\replacemissingchars: From \_string\fam=\_string#1 is printed now:^^J% - CHARACTERS: \.clist^^JACCENTS: \.alist^^J}% - \_ea\_mathchars \_expanded{\_noexpand#1{\.clist}}% - \_edef\.rlist{\.rlist\.clist\.alist}% + CHARACTERS: \_unexpanded\_ea{\.clist}^^JACCENTS: \_unexpanded\_ea{\.alist}^^J}% + \_def\.tmp{\_mathchars #1}\_ea\.tmp\_ea{\.clist}% + \_ea\_addto \_ea\.rlist \_ea{\.clist}\_ea\_addto \_ea\.rlist \_ea{\.alist}% \_def\.alist{}\_def\.clist{}\_let\UnicodeMathSymbol=\_undefined } \_nspublic \replacemissingchars ; @@ -258,20 +347,28 @@ \_def\.scriptspaces #1#2#3#4{% \_Umathordrelspacing\_scriptstyle=\.orzeromu{#1}\_relax \_Umathrelordspacing\_scriptstyle=\.orzeromu{#1}\_relax + \_Umathrelopspacing \_scriptstyle=\.orzeromu{#1}\_relax \_Umathordrelspacing\_crampedscriptstyle=\.orzeromu{#1}\_relax \_Umathrelordspacing\_crampedscriptstyle=\.orzeromu{#1}\_relax + \_Umathrelopspacing \_crampedscriptstyle=\.orzeromu{#1}\_relax \_Umathordbinspacing\_scriptstyle=\.orzeromu{#2}\_relax \_Umathbinordspacing\_scriptstyle=\.orzeromu{#2}\_relax + \_Umathbinopspacing \_scriptstyle=\.orzeromu{#2}\_relax \_Umathordbinspacing\_crampedscriptstyle=\.orzeromu{#2}\_relax \_Umathbinordspacing\_crampedscriptstyle=\.orzeromu{#2}\_relax + \_Umathbinopspacing \_crampedscriptstyle=\.orzeromu{#2}\_relax \_Umathordrelspacing\_scriptscriptstyle=\.orzeromu{#3}\_relax \_Umathrelordspacing\_scriptscriptstyle=\.orzeromu{#3}\_relax + \_Umathrelopspacing \_scriptscriptstyle=\.orzeromu{#3}\_relax \_Umathordrelspacing\_crampedscriptscriptstyle=\.orzeromu{#3}\_relax \_Umathrelordspacing\_crampedscriptscriptstyle=\.orzeromu{#3}\_relax + \_Umathrelopspacing \_crampedscriptscriptstyle=\.orzeromu{#3}\_relax \_Umathordbinspacing\_scriptscriptstyle=\.orzeromu{#4}\_relax \_Umathbinordspacing\_scriptscriptstyle=\.orzeromu{#4}\_relax + \_Umathbinopspacing \_scriptscriptstyle=\.orzeromu{#4}\_relax \_Umathordbinspacing\_crampedscriptscriptstyle=\.orzeromu{#4}\_relax \_Umathbinordspacing\_crampedscriptscriptstyle=\.orzeromu{#4}\_relax + \_Umathbinopspacing \_crampedscriptscriptstyle=\.orzeromu{#4}\_relax } \_def\.orzeromu#1{\_ifx^#1^0mu\_else#1\_fi} @@ -294,9 +391,13 @@ The following macros are defined in this package: \~`\smartvert` declares \"`|`" for better spacing. * There are many common math macros for sets or for operators, for example \~`\R` or \~`\sgn`. +* \~`\eqsystem` enables to write systems of equations comfortably, * \~`\toright`, \~`\toleft` puts the \o`\eqmark` to desired position, \~`\subeqmark` prints the given suffix as a part of the equation mark. * \~`\scriptspaces` sets more spaces around rel, bin in script and scripscript styles. +* \~`\bfserif` sets `\bf` and `\bi` for math typesetting as for bold-serif, bold-italic-serif. +* \~`\rmchars` sets selected characters printed as `\rm`, + \~`\vargreek` sets Greek leters to their variants. * \~`\textvariables`, \~`\textdigits`, \~`\textmoremath` enables characters from used text font in math mode (variables, digits, more characters). @@ -304,6 +405,21 @@ The following macros are defined in this package: for printing them from additional math font. \enditems +Six options are provided by the `math` package. You can set them by +\^`\mathset``{<options>}` after `\load[math]`, for example +`\mathset{dots, vert, vargreek={\epsilon,\rho}}`. The options are: +\begitems +* `dots` sets more inteligent `\dots`, the same as \~`\smartdots`. +* `vert` sets more inteligent `|`, the same as \~`\smartvert`. +* `bfserif` sets bold-serif, bold-italic-serif, the same as \~`\bfserif`. +* `rmchars={<list>}` sets `\rm` for selected characters, the same as \~`\rmchars`, + see section~\ref[rmchars]. +* `vargreek={<list>}` sets variants for Greek letetters, the same as \~`\vargreek`, + see section~\ref[rmchars]. +* `text={<list>}` sets \~`\textvariables`, \~`\textdigits`, or \~`\textmoremath`, + see section~\ref[textvars]. +\enditems + This package is not definitive. I plan to add more features in new versions if needed. Moreover, this package gives an example for package writers how to write their own packages, see section~\ref[pkgtemplate]. @@ -387,27 +503,67 @@ $$ } $$ + \sec Basic and typical macros for sets, functions etc. These typical macros are defined in `math.opm`: \^`\N` for $\N$, \^`\Z` for $\Z$, \^`\Q` for $\Q$, \^`\R` for $\R$, \^`\C` for $\C$, \^`\sgn`, \^`\argmin`, \^`\argmax`, \^`\grad`, \^`\rank`, \^`\tr`, \^`\diag`, \^`\Span`, \^`\Rng`, -\^`\Null`, \^`\Ker`, \^`\Res`, \^`\tg`, \^`\arctg`. +\^`\Null`, \^`\Ker`, \^`\Res`, \^`\tg`, \^`\cotg`, \^`\arctg`, \^`\arccotg`. I hate the \^`\frac`, \^`\dfrac` and \^`\tfrac` macros defined in \LaTeX/ but someone may want to use them. This package defines them. But I note: usage of `$1\over2$` for $1\over2$ is much more understandable than \LaTeX's `$\frac12$`. -The vectors and matrices are ususally printed by `{\bf A}{\bf x}`. +The vectors and matrices are usually printed by `{\bf A}{\bf x}`. The package provides a shortcut `\.<letter>` to do the same, so user can write `\.A\.x` for multiplication of a matrix $\.A$ by a vector $\.x$. We strictly don't recommend usage of `\.`, `\v`, `\=`, etc.\ for accents, so `math.opm` can define `\.` differently than the classical meaning \"dotaccent". + +\sec System of equations printed by `\eqsystem` + +The \^`\eqsystem``{<equations>}` enables to write systems of equations more +comfortably. The equations are separated by `\cr` and the aligned columns +are separated by space. For example: +\begtt +$$ + \eqsystem{ x + y - 2z = 10 \cr + 2x - 7y + z = 13 \cr + -x + y ~ ~ = -5 } +$$ +\endtt +prints +$$ + \eqsystem{ x + y - 2z = 10 \cr + 2x - 7y + z = 13 \cr + -x + y ~ ~ = -5 } +$$ +Note that empty columns have to be filled by `~` mark. +There are columns for variables (possibly multiplied by a constant) and for +binary operators `+` and `-` or relations `=`, `>` etc. or constants. Each column +is aligned to right. The number of columns is unlimited (we have 7 columns in +the example above). All given equations are packed to the `\vcenter` box. + +The spaces between lines are enlarged by the value of \^`\eqskip` +and the horizontal spaces between columns are enlaged by \^`\eqsep`. +Both registers are set to 0\,pt by default. + +The \^`\eqfil` register is \"left filler" applied to each item in the \^`\eqsystem` columns. +Its default is `\eqfil={\hfill}`. The right filler is hardwired and it is `\hfil`. +This makes columns aligned to right by default. For example, when you set +`\eqfil={\hfil}` then you have columns centered. + +The \^`\eqsystem` macro allows optional parameter which is processed inside +group before printing equations. You can do local settings here, for example +`\eqsystem[\eqskip=2pt \eqsep=5pt]{...}`. + + \sec Equation marks in atypical cases -We want to put equation marks `\eqmark` in more lines in display mode when we +We may want to put equation marks `\eqmark` in more lines in display mode when we are using macros not designed for such case. For example in the lines of the `\cases` macro: @@ -425,7 +581,7 @@ The \^`\toright`\o`\eqmark` is used here. Analogically, The position of these marks are correct after second or more \TeX/ run because \TeX/ needs to read data from its previous run in this case. -Sometime we want to declare a bunch of equations with the same numeric +Sometimes we want to declare a bunch of equations with the same numeric equation marks but with different suffixes, for example (1.1a), (1.1b). We provide the macro \^`\subeqmark``<suffix>` here. If `<suffix>` is `a` or `A` then \^`\subeqmark` starts a new bunch of @@ -435,12 +591,10 @@ You can put `[<label>]` after `<suffix>` for referencing purposes. Example: \begtt -$$\adef~{\kern.5em } - \eqalignno{ - x + 2y + 3z &= 600 & \subeqmark a \cr - 12x + ~y - 3z &= -7 & \subeqmark b[label] \cr - 4x - ~y + 5z &= ~5 & \subeqmark c \cr - } +$$ \eqsystem[\eqskip=3pt]{ + x + 2y + 3z = 600 \toright{\subeqmark a}\cr + 12x + y - 3z = -7 \toright{\subeqmark b[label]}\cr + 4x - y + 5z = 5 \toright{\subeqmark c}\cr } $$ The equation~\ref[label] has negative right side. Moreover, it applies $$ @@ -448,11 +602,10 @@ $$ $$ \endtt prints -$$\adef~{\kern.5em } - \eqalignno{ - x + 2y + 3z &= 600 & \subeqmark a \cr - 12x + ~y - 3z &= -7 & \subeqmark b[label] \cr - 4x - ~y + 5z &= ~5 & \subeqmark c \cr +$$ \eqsystem[\eqskip=3pt]{ + x + 2y + 3z = 600 \toright{\subeqmark a}\cr + 12x + y - 3z = -7 \toright{\subeqmark b[label]}\cr + 4x - y + 5z = 5 \toright{\subeqmark c}\cr } $$ The equation~\ref[label] has negative right side. Moreover, it applies @@ -484,7 +637,57 @@ $$ $$ It looks better, doesn't it? -\sec Variables and digits from currently used text font +\sec `\bf` and `\bi` can do shapes with serifs + +\OpTeX/ sets `\bf` and `\bi` math selectors as sans serif, because this +follows the old traditional math typesetting of vectors and matrices. +But Knuth's \TeX/ has another default behavior:`\bf` and `\bi` select serifed +shaped. So, many people consider it as a standard. You can declare \^`\bfserif` if +you want serifed `\bf` and `\bi` math letters. + +\sec[rmchars] Selected upright letters and variants for Greek letters + +Some mathematicians claim that the letters $e$, $i$ and $\pi$ in meaning +\"a constant" should be printed in upright form. \TeX/ prints all variables in +math italic, but this package enables to set exceptions for some letters. +For example after \^`\rmchars``{e, i, \pi}`, all occurrences of these three letters +in math mode will be set in upright shape. If you set this, then the +well-known math identity `$e^{i\pi}=-1$` looks like this: +$$ + {\rm e}^{\rm i\muppi} = -1, \qquad \hbox{compare with:}\quad e^{i\pi} = -1. +$$ +The syntax is \^`\rmchars``{<list>}`, where <list> is a list of characters +separated by (optional) commas. The character is `a` to `z` or `A` to `Z` or +`\alpha` to `\omega`. + +If you set a character by `\rmchars` globally and you want to print it in italic +locally then use `\mit`, for example `{\mit e}` prints $e$. + +Several Greek letters have their variant shape: +`\epsilon`~$\epsilon$, `\varepsilon`~$\varepsilon$, +`\sigma`~$\sigma$, `\varsigma`~$\varsigma$, +`\phi`~$\phi$, `\varphi`~$\varphi$, +`\theta`~$\theta$, `\vartheta`~$\vartheta$, +`\pi`~$\pi$, `\varpi`~$\varpi$, +`\kappa`~$\kappa$, `\varkappa`~$\varkappa$, +`\rho`~$\rho$, `\varrho`~$\varrho$, +`\Theta`~$\Theta$, `\varTheta`~$\varTheta$. +Maybe, there is a tradition of usage variant shapes instead of standard ones +in your mathematics field. Then you can use +\^`\vargreek``{<list>}`, where <list> includes the list of no-var control +sequences for these letters (separated by optional comma). +For example `\vargreek{\epsilon \phi \rho}` causes that `\epsilon` is +printed as $\varepsilon$, `\phi` as $\varphi$ and `\rho` as $\varrho$. + +If you want to declare a Greek letter by both `\vargreek` and `\rmchars`, +use `\rmchars` first. + +The package provides two options `rmchars` and `vargreek`. The equation +sign must follow and then the `{<list>}` with syntax mentioned above. For example +`\mathset{vargreek={\epsilon,\rho}}`. + + +\sec[textvars] Variables and digits from currently used text font When Unicode math font is loaded then all variables and digits are printed from it in math mode. If you are using text fonts with another visual @@ -507,6 +710,12 @@ are use in the context \n`\left`, \n`\right`. These parentheses must be printed from math font always because text font is unable to create bigger versions of them. +The package provides the option `text={<list of words>}`, each <word> from the +<list> can be `digits` or `variables` or `moremath`. It runs corresponding macro(s) +described above. For example `\mathset{text=digits variables}` is equal to the +declaration of `\textdigits` `\textvariables`. + + \sec Replacing all missing math characters from another font If we load an additional math font by \o`\addUmathfont`, for example: @@ -541,7 +750,7 @@ This section has nothing common with the subject of this package but this packag can serve as inspiration for another package writers. It should be a template for another `<pkg>.opm` files. We emphasize several principles here. The basic information can be found in -\ulink[https://petr.olsak.net/ftp/olsak/optex/optex-doc.pdf\#ref:prefixed] +\ulink[https://petr.olsak.net/ftp/olsak/optex/optex-doc.pdf\#ref:basic-code] {section 2.2} of the \OpTeX/ manual. Try to run\fnote{Run it three times because Table of contents and Index are created.} \begtt @@ -573,7 +782,7 @@ The `\_<pkg>_version` macro should be declared here. The macro should expand to version number followed by version date. User can check the package version simply by expanding this macro after the package is loaded. And we want to have this data only at single place of the file. -You may check the log file if the text given by `\_codedecl` isn't too long +You may check the log file if the text given by \o`\_codedecl` isn't too long and isn't broken to more lines. Keeping single line is better because users can `grep @:` on log file in order to get information of all loaded packages and their version numbers. @@ -586,20 +795,25 @@ transformed to `\_<pkg>_foo` and by \o`\_endcode` which does \n`\endinput` when the macros are load. Final part of the file after \o`\_endcode` can include more detailed documentation. +If your package requires other packages then insert +\o`\load``[<package1>,<package2>]` after \o`\_codedecl` and before the the +\o`\_namespace` command. Each package uses its own namespace, so it is +important to load these packages before your \o`\_namespace` is opened. + If you have any idea of creating a macro package, you probably start with -experimental macros in user name space. It means that there are +experimental macros in the public namespace. It means that there are `\def\mymacro` etc. Once such a code is working, you can include it to the macro package introduced by \o`\_namespace``{<pkg>}`. You have to go through your code carefully sequence per sequence and insert `_` or `.` in front of -their name. The \"`_`" have to be used if the sequence is a primitive or -\OpTeX/ macro and the \"`.`" if it is your macro. So, the code fragment +their names. The \"`_`" prefix have to be used if the sequence is a primitive or +an \OpTeX/ macro and the \"`.`" prefix if it is your macro. So, the code fragment `\def\mymacro` have to be rewritten to `\_def\.mymacro`. If the macro -`\mymacro` is intended for usage in the user space, then append -`\_nspublic \mymacro ;` too. +`\mymacro` is intended for end users, then export it to the +public name space after it is defined by the \o`\_nspublic` `\mymacro ;` command. -Sometimes you may want to define a macro only for user space. Then -use prefix \O`\_newpublic` before your declaration, see declaration of - \^`\sgn` in this package as an exampe. The reason is: if +Sometimes you may want to define a macro only in public namespace. Then +use prefix \o`\_newpublic` before your declaration, see declaration of + \^`\sgn` in this package as an example. The reason is: if a user has defined such a macro already then the warning is printed. The user can read this warning and declare the macro after `\load[<pkg>]` in this case. @@ -616,9 +830,9 @@ The user can read this warning and declare the macro after \def\n`#1`{\exlink#1{\tnurl\#cs:}} \outlines 0 - \tit Macros for doing math more comfortable + \tit Macros for doing math more comfortably \hfill Version: \_math_version \par - \centerline{\it Petr Olšák\/\fnotemark1, 2022} + \centerline{\it Petr Olšák\/\fnotemark1, 2022, 2023} \fnotetext{\url{https://petr.olsak.net}} \notoc\nonum\sec Table of contents @@ -635,5 +849,15 @@ The user can read this warning and declare the macro after \endinput +0.08 2023-01-28: \eqsystem introduced, \eqfil added. +0.07 2023-01-23: \sgn etc. defined as \protected\def. + 2023-01-15: \replacemissingchars: bug fixed +0.06, 2023-01-14: \rmchars, \vargreek, \bfserif introduced +0.05, 2023-01-07: \mathset introduced +0.04, 2022-12-26: \casesof used in \.fparamA + \singlevert declared instead \_singlevert (bug fix) +0.03, 2022-12-19: \cotg, \arccotg defined, + \autop: \mathclose{} replaced by \bgroup...\egroup, + \scriptspaces: Rel-Op, Bin-Op spacing added. 0.02, 2022-11-26: \smartvert introduced 0.01, 2022-11-25: released |