summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/xoptarg/xoptarg.sty
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
committerNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
commite0c6872cf40896c7be36b11dcc744620f10adf1d (patch)
tree60335e10d2f4354b0674ec22d7b53f0f8abee672 /macros/latex/contrib/xoptarg/xoptarg.sty
Initial commit
Diffstat (limited to 'macros/latex/contrib/xoptarg/xoptarg.sty')
-rw-r--r--macros/latex/contrib/xoptarg/xoptarg.sty225
1 files changed, 225 insertions, 0 deletions
diff --git a/macros/latex/contrib/xoptarg/xoptarg.sty b/macros/latex/contrib/xoptarg/xoptarg.sty
new file mode 100644
index 0000000000..d76cfe9f47
--- /dev/null
+++ b/macros/latex/contrib/xoptarg/xoptarg.sty
@@ -0,0 +1,225 @@
+% $Date: 2007-04-22 12:22:27 +0200 (Sun, 22 Apr 2007) $
+% $Revision: 39 $
+\def \filedate {2007/04/22}
+\def \fileversion {v1.0}
+\NeedsTeXFormat{LaTeX2e}
+\ProvidesPackage{xoptarg}%
+ [\filedate \space \fileversion \space Expandable optional-argument macros (JN)]
+
+\ifx \eTeXversion \@undefined
+ \PackageWarning{xoptarg}{%
+ This package works best with e-TeX\MessageBreak
+ for its \protect\protected \space feature%
+ }%
+ \let \XOA@protected = \relax
+\else
+ \let \XOA@protected = \protected
+\fi
+
+\RequirePackage{newcommand}
+
+%% \newcommand*{\xnewcommand}{%
+%% \@ifstar {\XOA@xnewcommand[\def]}%
+%% {\@testopt{\XOA@xnewcommand}{\long \def}}%
+%% }
+
+\newcommand*{\xnewcommand}{\@star@or@long \XOA@xnewcommand}
+
+\newcommand*{\XOA@xnewcommand}{}
+\newcommand*{\XOA@@xnewcommand}{}
+\newcommand*{\XOA@@@xnewcommand}{}
+\newcommand*{\XOA@@@@xnewcommand}{}
+\newcommand*{\XOA@@@@ynewcommand}{}
+\newcommand*{\XOA@@@ynewcommand}{}
+
+% [<prefix-def>] {<command>}
+%% \long \def \XOA@xnewcommand [#1]#2{%
+%% \@testopt {\XOA@@xnewcommand{#1}{#2}}{0}%
+%% }
+
+% {<command>}
+\long \def \XOA@xnewcommand #1{\@testopt {\XOA@@xnewcommand{#1}}{0}}
+
+% {<prefix-def>} {<command>} [<arg-num>]
+%% \long \def \XOA@@xnewcommand #1#2[#3]{%
+%% \ifnum #3>0
+%% \expandafter \@firstoftwo
+%% \else
+%% \expandafter \@secondoftwo
+%% \fi
+%% {\XOA@@@xnewcommand{#1}{#2}{#3}}% Possibly with optional
+%% {\XOA@@@ynewcommand{#1}{#2}}% Certainly without optional
+%% }
+
+% {<command>} [<arg-num>]
+\long \def \XOA@@xnewcommand #1[#2]{%
+ \ifnum #2>0
+ \expandafter \@firstoftwo
+ \else
+ \expandafter \@secondoftwo
+ \fi
+ {\XOA@@@xnewcommand{#1}{#2}}% Possibly with optional
+ {\XOA@@@ynewcommand{#1}}% Certainly without optional
+}
+
+
+% {<prefix-def>} {<command>} {<arg-num>}
+%% \long \def \XOA@@@xnewcommand #1#2#3{%
+%% \@ifnextchar [%]
+%% {\XOA@@@@xnewcommand{#1}{#2}{#3}}% With optional
+%% {\XOA@@@@ynewcommand{#1}{#2}{#3}}% Without optional
+%% }
+
+% {<command>} {<arg-num>}
+\long \def \XOA@@@xnewcommand #1#2{%
+ \@ifnextchar [%]
+ {\XOA@@@@xnewcommand{#1}{#2}}% With optional
+ {\XOA@@@@ynewcommand{#1}{#2}}% Without optional
+}
+
+% {<prefix-def>} {<command>} {<arg-num>} [<default>] {<definition>}
+%% \long \def \XOA@@@@xnewcommand #1#2#3[#4]#5{%
+%% \ifnum #3<2
+%% \PackageWarning{xoptarg}{%
+%% Without at least one mandatory argument {...}\MessageBreak
+%% I cannot make the macro \protect#2\space expandible.\MessageBreak
+%% I will make it robust instead%
+%% }%
+%% \def \@tempa ##1{%
+%% \in@{\protected}{#1}%
+%% \unless \ifin@
+%% \XOA@protected
+%% \fi
+%% #1#2{\@testopt {##1}{#4}}%
+%% \def \@tempa {#1##1}%
+%% \def \@tempb ####1#3####2\@nil {####1#3}%
+%% \expandafter \@tempa \@tempb [####1]%
+%% ####2####3####4####5####6####7####8####9\@nil
+%% }%
+%% \count@ = \escapechar
+%% \escapechar = -1
+%% \expandafter \@tempa \csname \string #2 \endcsname {#5}%
+%% \escapechar = \count@
+%% \else
+%% \def \@tempa ##1{%
+%% #1#2####1####{%
+%% \XOA@ifempty{####1}%
+%% {##1[{#4}]}%
+%% {%
+%% \XOA@ifbeginswithspace{####1}%
+%% {\XOA@removespace \foo ####1}%
+%% {\XOA@ifbracket {##1[}{##1[{#4}]}####1}%]
+%% }%
+%% }%
+%% \def \@tempa {#1##1}%
+%% \def \@tempb ####1#3####2\@nil {####1#3}%
+%% \expandafter \@tempa \@tempb [####1]%
+%% ####2####3####4####5####6####7####8####9\@nil
+%% }%
+%% \count@ = \escapechar
+%% \escapechar = -1
+%% \expandafter \@tempa \csname \string #2 \endcsname {#5}%
+%% \escapechar = \count@
+%% \fi
+%% }
+
+% {<command>} {<arg-num>} [<default>] {<definition>}
+\long \def \XOA@@@@xnewcommand #1#2[#3]#4{%
+ \ifnum #2<2
+ \PackageWarning{xoptarg}{%
+ Without at least one mandatory argument {...}\MessageBreak
+ I cannot make the macro \protect#1\space expandible.\MessageBreak
+ I will make it robust instead%
+ }%
+ \def \@tempa ##1{%
+ \expandafter \in@ \expandafter \protected \expandafter {\l@ngrel@x}%
+ \unless \ifin@
+ \XOA@protected
+ \fi
+ \l@ngrel@x \def #1{\@testopt {##1}{#3}}%
+ \def \@tempa {\l@ngrel@x \def ##1}%
+ \def \@tempb ####1#2####2\@nil {####1#2}%
+ \expandafter \@tempa \@tempb [####1]%
+ ####2####3####4####5####6####7####8####9\@nil
+ }%
+ \count@ = \escapechar
+ \escapechar = -1
+ \expandafter \@tempa \csname \string #1 \endcsname {#4}%
+ \escapechar = \count@
+ \else
+ \def \@tempa ##1{%
+ \l@ngrel@x \def #1####1####{%
+ \XOA@ifempty{####1}%
+ {##1[{#3}]}%
+ {%
+ \XOA@ifbeginswithspace{####1}%
+ {\XOA@removespace \foo ####1}%
+ {\XOA@ifbracket {##1[}{##1[{#3}]}####1}%]
+ }%
+ }%
+ \def \@tempa {\l@ngrel@x \def ##1}%
+ \def \@tempb ####1#2####2\@nil {####1#2}%
+ \expandafter \@tempa \@tempb [####1]%
+ ####2####3####4####5####6####7####8####9\@nil
+ }%
+ \count@ = \escapechar
+ \escapechar = -1
+ \expandafter \@tempa \csname \string #1 \endcsname {#4}%
+ \escapechar = \count@
+ \fi
+}
+
+% {<prefix-def>} {<command>} {<arg-num>} {<definition>}
+%% \long \def \XOA@@@@ynewcommand #1#2#3#4{%
+%% \def \@tempa {#1#2}%
+%% \def \@tempb ##1#3##2\@nil {##1#3}%
+%% \expandafter \@tempa \@tempb ##1##2##3##4##5##6##7##8##9\@nil {#4}%
+%% }
+
+% {<command>} {<arg-num>} {<definition>}
+\long \def \XOA@@@@ynewcommand #1#2#3{%
+ \def \@tempa {\l@ngrel@x \def #1}%
+ \def \@tempb ##1#2##2\@nil {##1#2}%
+ \expandafter \@tempa \@tempb ##1##2##3##4##5##6##7##8##9\@nil {#3}%
+}
+
+% {<prefix-def>} {<command>} {<definition>}
+%% \long \def \XOA@@@ynewcommand #1#2#3{#1#2{#3}}
+
+% {<command>} {<definition>}
+\long \def \XOA@@@ynewcommand #1#2{\l@ngrel@x \def #1{#2}}
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+\newcommand*{\XOA@ifbeginswithspace}[1]{%
+ \XOA@@ifbeginswithspace #1 \@nil
+}
+
+\newcommand*{\XOA@@ifbeginswithspace}{}
+\def \XOA@@ifbeginswithspace #1 #2\@nil {%
+ \XOA@ifempty{#1}%
+ {\@firstoftwo}%
+ {\@secondoftwo}%
+}
+
+\newcommand*{\XOA@removespace}{}
+\def \XOA@removespace #1 {#1}
+
+\newcommand*{\XOA@ifbracket}[3]{%
+ \ifx [#3%
+ \expandafter \@firstoftwo
+ \else
+ \expandafter \@secondoftwo
+ \fi
+ {#1}{#2#3}%
+}
+
+\newcommand*{\XOA@ifempty}[1]{%
+ \ifx \relax #1\relax
+ \expandafter \@firstoftwo
+ \else
+ \expandafter \@secondoftwo
+ \fi
+}
+
+\empty