Browse Source

MRTif: added MRTifFexp

master
Jonathan Spratte 1 year ago
parent
commit
ac038ad7d6
4 changed files with 90 additions and 4 deletions
  1. BIN
      Doc/doc_MRTbundle.pdf
  2. 1
    1
      Doc/preamble/doc_macros.tex
  3. 36
    1
      Doc/tex/doc_MRTif.tex
  4. 53
    2
      MRTif/MRTif.sty

BIN
Doc/doc_MRTbundle.pdf View File


+ 1
- 1
Doc/preamble/doc_macros.tex View File

@@ -13,7 +13,7 @@
13 13
     \texttt{\expandafter\eatspace\string\ \detokenize{#1}}%
14 14
   }%<<<
15 15
 \def\cs@PDFString#1{(macro #1)}
16
-\protected\def\meta#1{\texttt{$\langle$\textit{\meta@a{#1}}$\rangle$}}
16
+\protected\def\meta#1{\texttt{$\langle${\itshape\meta@a{#1}}\kern.05em$\rangle$}}
17 17
 \ExplSyntaxOn
18 18
 \newcommand\meta@a[1]%>>>
19 19
   {

+ 36
- 1
Doc/tex/doc_MRTif.tex View File

@@ -21,7 +21,7 @@ undefined control sequence
21 21
 If you ever see this in your log or console output, please contact me as stated
22 22
 in \autoref{sec:bugs} and include a minimal example producing this behaviour in
23 23
 your contacting. Please do the same if you get any other undefined control
24
-sequence errors containing \texttt{MRTif} in the control sequences' name.
24
+sequence errors containing \texttt{MRTif} in the control sequence's name.
25 25
 
26 26
 \section{Macros}
27 27
 \begin{describemacroTF}[G,N,GN]{MRTifEmpty}[\marg{arg}]
@@ -134,6 +134,41 @@ sequence errors containing \texttt{MRTif} in the control sequences' name.
134 134
   version needs four.
135 135
 \end{describemacro}
136 136
 
137
+\begin{describemacro}{MRTifFexp,MRTifFexpI,MRTifFexpII}%
138
+  [\marg{MRTif test}\meta{branches}]
139
+  These macros take an arbitrary expandable test and expand it in exactly two
140
+  steps of expansion. \cs{MRTifFexp} can be applied to any test, while
141
+  \cs{MRTifFexpI} is meant to be used for tests having only one -- a true or a
142
+  false -- branch and \cs{MRTifFexpII} is meant to be used for tests having two
143
+  branches. \meta{MRTif test} doesn't necessarily have to be a test provided by
144
+  \pkg{MRTif} but can be any fully expandable test. Inside of \meta{MRTif test}
145
+  all the arguments necessary for the test should be contained but not the true
146
+  or false branch. An example:\\[\smallskipamount]
147
+  \mbox{}\hfill\begin{tabular}{@{}l@{}}
148
+    \verb|\MRTifFexp{\MRTifEmptyF{abc}}{false}|          \\
149
+    \verb|\MRTifFexp{\MRTifEmptyTF{abc}}{true}{false}|   \\
150
+    \verb|\MRTifFexpI{\MRTifEmptyF{abc}}{false}|         \\
151
+    \verb|\MRTifFexpII{\MRTifEmptyTF{abc}}{true}{false}| \\
152
+  \end{tabular}\hfill\mbox{}%
153
+  \\[\smallskipamount]
154
+  all expand to |false| after exactly two steps of expansion. \cs{MRTifFexpI}
155
+  and \cs{MRTifFexpII} are more than thrice as fast as \cs{MRTifFexp} and of
156
+  course each test takes longer with these added than without.%
157
+  \footnote
158
+    {%
159
+      Benchmarking done with \hologo{pdfTeX}, version 3.14159265-2.6-1.40.19
160
+      (\TeX\ Live 2018), on an Intel\textregistered\ Core\texttrademark\
161
+      \mbox{i5-2540M} with \cs{MRTifEmptyT} and \cs{MRTifEmptyTF} utilizing the
162
+      \pkg{l3benchmark} package. To give some numbers: 2~\cs{MRTifFexpI} and
163
+      2~\cs{MRTifFexpII} added roughly \SI{1.2}{\micro\second} to the compile
164
+      time of \SI{1.8}{\micro\second} for 2~\cs{MRTifEmptyT} and
165
+      2~\cs{MRTifEmptyTF} tests, each once empty and once not with empty
166
+      branches, while 4~\cs{MRTifFexp} added \SI{4.2}{\micro\second}.%
167
+    }
168
+  The advantage is the control
169
+  over the needed expansion steps.
170
+\end{describemacro}
171
+
137 172
 \section{Dependencies}
138 173
 \pkg{MRTif} loads the \pkg{pdftexcmds} package to make the \hologo{pdfTeX}
139 174
 primitive \cs{pdfstrcmp} available as \cs{pdf@strcmp} for \hologo{LuaTeX}.

+ 53
- 2
MRTif/MRTif.sty View File

@@ -1,5 +1,5 @@
1
-\newcommand*\MRTif@version{0.0.4}
2
-\newcommand*\MRTif@date{2018-11-12}
1
+\newcommand*\MRTif@version{0.0.5}
2
+\newcommand*\MRTif@date{2019-01-08}
3 3
 
4 4
 \NeedsTeXFormat{LaTeX2e}
5 5
 
@@ -636,5 +636,56 @@
636 636
   }% <<<
637 637
 % <<<
638 638
 
639
+% MRTifFexp >>>
640
+\newcommand\MRTif@endfexp@gobble[1]{ }
641
+\newcommand\MRTif@endfexp@firstofone[1]{ #1}
642
+\newcommand\MRTif@endfexp@firstoftwo[2]{ #1}
643
+\newcommand\MRTif@endfexp@secondoftwo[2]{ #2}
644
+\newcommand\MRTifFexp[1]% >>>
645
+  {%
646
+    \romannumeral-`\0\expandafter\MRTifFexp@a
647
+    \romannumeral-`\0#1{\MRTifFexp@b} \MRTifFexp@c
648
+  }% <<<
649
+\newcommand\MRTifFexp@a[1]% >>>
650
+  {%
651
+    \ifx\MRTifFexp@c#1%
652
+      \MRTif@fiAa
653
+    \else
654
+      \MRTif@fiBb
655
+    \fi
656
+    {%
657
+      \MRTif@endfexp@gobble
658
+    }
659
+    {%
660
+      #1%
661
+    }
662
+  }% <<<
663
+\newcommand\MRTifFexp@b[1]% >>>
664
+  {%
665
+    \ifx\MRTifFexp@c#1%
666
+      \MRTif@fiAa
667
+    \else
668
+      \MRTif@fiBb
669
+    \fi
670
+    { % space ending the inner \romannumeral
671
+      \MRTif@endfexp@firstofone
672
+    }
673
+    { % space ending the inner \romannumeral
674
+      \MRTif@endfexp@firstoftwo{#1}%
675
+    }%
676
+  }% <<<
677
+\newcommand\MRTifFexp@c% >>>
678
+  { % space ending the inner \romannumeral
679
+    \MRTif@endfexp@secondoftwo
680
+  }% <<<
681
+\newcommand\MRTifFexpII[1]% >>>
682
+  {%
683
+    \romannumeral-`\0#1\MRTif@endfexp@firstoftwo\MRTif@endfexp@secondoftwo
684
+  }% <<<
685
+\newcommand\MRTifFexpI[1]% >>>
686
+  {%
687
+    \romannumeral-`\0#1\MRTif@endfexp@secondoftwo\MRTif@endfexp@gobble
688
+  }% <<<
689
+% <<<
639 690
 \endinput
640 691
 % vim: fdm=marker foldmarker=>>>,<<< ft=tex

Loading…
Cancel
Save