diff options
Diffstat (limited to 'Master/texmf-dist/tex/luatex/optex/if-macros.opm')
-rw-r--r-- | Master/texmf-dist/tex/luatex/optex/if-macros.opm | 112 |
1 files changed, 76 insertions, 36 deletions
diff --git a/Master/texmf-dist/tex/luatex/optex/if-macros.opm b/Master/texmf-dist/tex/luatex/optex/if-macros.opm index 5f3f4d91cf0..ea2f84ee41d 100644 --- a/Master/texmf-dist/tex/luatex/optex/if-macros.opm +++ b/Master/texmf-dist/tex/luatex/optex/if-macros.opm @@ -2,7 +2,7 @@ \_codedecl \newif {Special if-macros, is-macros and loops <2020-01-23>} -% \newif like in plain\TeX/: +%> \newif \_def\_newif #1{\_ea\_newifA \_string #1\_relax#1} \_ea\_def \_ea\_newifA \_string\if #1\_relax#2{% @@ -17,7 +17,7 @@ \_let#2=\_iffalse } -% \loop like in plain\TeX/: +%> \loop \_def \_loop #1\_repeat{\_def\_body{#1}\_iterate} \_def \loop #1\repeat{\_def\_body{#1}\_iterate} @@ -25,7 +25,14 @@ \_let \repeat=\_fi \_def \_iterate {\_body \_ea \_iterate \_fi} -% \isempty{text}\iftrue, \isempty{text}\iffalse: +%> \isnextchar <char>{exec if true}{exec if false} + +\_long\_def\_isnextchar#1#2#3{\_begingroup\_toks0={\_endgroup#2}\_toks1={\_endgroup#3}% + \_let\_tmp=#1\_futurelet\_next\_isnextcharA +} +\_def\_isnextcharA{\_the\_toks\_ifx\_tmp\_next0\_else1\_fi\_space} + +%> \isempty{text}\iftrue, \isempty{text}\iffalse: \_def \_isempty #1#2{\_ea\_ifx\_ea\_relax\_detokenize{#1}\_relax \_else \_ea\_unless \_fi #2} @@ -33,52 +40,46 @@ \_ea\_unless \_fi #2} \_def \_istoksempty #1{\_ea\_isempty\_ea{\_the#1}} -% \isinlist\list{text}\iftrue, \isinlist\list{text}\false: - -\_long\_def\_isinlist#1#2{\_begingroup - \_long\_def\_tmp##1#2##2\_end/_{\_endgroup\_isnoempty{##2}}% - \_ea\_tmp#1\_endlistsep#2\_end/_% -} - -% \isequal{text}{text}\iftrue ... +%> \isequal{text}{text}\iftrue ... \_def\_isequal#1#2#3{\_directlua{% - if "\_luaescapestring{#1}"=="\_luaescapestring{#2}" then else tex.print("\_nbb unless") end}#3} + if "\_luaescapestring{\_detokenize{#1}}"=="\_luaescapestring{\_detokenize{#2}}" + then else tex.print("\_nbb unless") end}#3} -% \ismacro\macro{text}\iftrue ... +%> \ismacro\macro{text}\iftrue ... \_def\_ismacro#1{\_ea\_isequal\_ea{#1}} -% \isnextchar <char>{exec if true}{exec if false} +%> \isdefined{csname}\iftrue -\_long\_def\_isnextchar#1#2#3{\_begingroup\_toks0={\_endgroup#2}\_toks1={\_endgroup#3}% - \_let\_tmp=#1\_futurelet\_next\_isnextcharA +\_def\_isdefined #1#2{\_ifcsname #1\_endcsname \_else \_ea\_unless \_fi #2} + +%> \isinlist\list{text}\iftrue ... + +\_long\_def\_isinlist#1#2{\_begingroup + \_long\_def\_tmp##1#2##2\_end/_{\_endgroup\_isnoempty{##2}}% + \_ea\_tmp#1\_endlistsep#2\_end/_% } -\_def\_isnextcharA{\_the\_toks\_ifx\_tmp\_next0\_else1\_fi\_space} -% \isfile{name}\iftrue +%> \isfile{name}\iftrue ... \_newread \_testin \_def\_isfile #1{% - \_openin\_testin =#1 + \_openin\_testin ={#1}\_relax \_ifeof\_testin \_ea\_unless \_else \_closein\_testin \_fi } -% \removespaces text with spaces {} -> textwithspaces - -\_def\_removespaces #1 {\_isempty{#1}\_iffalse #1\_ea\_removespaces\_fi} - - \_public - \newif \isempty \istoksempty \isinlist \isnextchar - \isfile \ismacro \isequal \removespaces ; + \newif \isnextchar \isempty \isequal \ismacro \isdefined \isinlist \isfile ; \_endcode %--------------------------------------------------------- -The `\newif` macro works like in plain\TeX. It means that +\%> \newif + +The `\newif` macro works like in plain \TeX. It means that after `\newif\ifxxx` you can use `\xxxtrue` or `\xxxfalse` to set the boolean value and use `\ifxxx true\else false\fi` to test this value. The defalut value is false. @@ -86,21 +87,60 @@ to test this value. The defalut value is false. The macro `\_newifi` enables to declare `\_ifxxx` and to use `\_xxxtrue` and `\_xxxfalse`. This means that it is usable for _prefixed macros. +\%> \loop + The `\loop <codeA> \ifsomething <codeB> \repeat` loops `<codeA> <codeB>` until `\ifsomething` is false. Then `<codeB>` is not executed and loop is -finished. This works like in plain\TeX. +finished. This works like in plain \TeX, but implementation is soewhat +better (you can use `\else` clause after the `\ifsomething`). -The macro `\isempty{<text>}\iftrue <codeA>\else <codeB>\fi` executes <codeA> -if <text> is empty and <codeB> if it is nonempty. You can use -`\isempty{<text>}\iffalse <codeB>\else <codeA>\fi` too. This macro is -expandable. +There are public version `\loop...\repeat` and private version +`\_loop...\_repeat`. You canot mix both versions in one loop. -The macro `\isinlist\list{<text>}\iftrue` acts like `\iftrue` if the -`<text>` is included the macro body of `\list`. Else it acts like -`\ifflase`. You can write `\isinlist\list{<text>}\iffalse` to reverse the -boolean value of this condition. THe macro is not expandable. +\%> \isnextchar The macro `\isnextchar <char>{<codeA>}{<codeB>}` executes `<codeA>` if next character is equal to <char>. Else the `<codeB>` is executed. The macro is not expandable. +\%> \isempty + +The macro `\isempty{<text>}\iftrue <codeA>\else <codeB>\fi` executes <codeA> +if <text> is empty and <codeB> if it is non-empty. You can use +`\isempty{<text>}\iffalse <codeB>\else <codeA>\fi` too. This macro is +expandable. + +There are a collection of macros with commnon syntax: +`\issomething<params>\iftrue` or `\issomething<params>\iffalse`. +The `\iftrue` or `\iffalse` is a part of this syntax because we need to keep +skippable nested `\if` conditions. + +We read this `\iftrue` or `\iffalse` into unseparated parameter and repeat +it because we need to remove an optional space before this command. + +\%> \isequal + +`\isequal{<textA>}{<textB>}\iftrue` is true if the <textA> and <textB> are +equal, only from strings point of view, category codes are ignored. +The macro is expandable. + +\%> \ismacro + +`\ismacro\macro{text}\iftrue` is true if macro is defined as {<text>}. +Category codes are ignored in this testing. The macro is expandable. + +\%> \isdefined + +`\isdefined{<csname>}\iftrue` is true if `\<csname>` is defined. + +\%> \isinlist + +`\isinlist\list{<text>}\iftrue` is true if the +`<text>` is included the macro body of the `\list`. +The catogory code are relevant here. THe macro is not expandable. + +\%> \isfile + +`\isfile{<filename>}\iftrue` is true if the file <filename> exists and are +readable by \TeX. + |