Debian Codegraph @

texmf-dist/tex/generic/eoldef/eoldef.tex

raw
1 % eoldef.tex, version 1.1
2
3 % Copyright (C) 2025 plante
4 % This file is released under the LaTeX Project Public License (LPPL) 1.3c.
5
6 % eoldef: define commands which absorb the whole source line as arguments.
7
8 % Usage: \eoldef <control sequence> <parameter text> { <replacement text> }
9 % defines a control sequence whose argument is delimited by the end of a
10 % source code line.
11
12 % For instance, \eoldef\test#1:#2{} and
13 % \test abc:def
14 % will give #1 = abc, #2 = def.
15
16 % \eolgdef is the \global variant to \eoldef.
17
18 % Like \verb|...|, \eoldef'd commands may generally not be used as part of
19 % another command's argument as it changes catcodes.
20 % However, if you must use it in environments where catcodes are frozen, you
21 % may follow the command with a braced argument, eg. \test{#1:#2} using the
22 % previous example.
23
24 % This package may be used in LaTeX by `\usepackage{eoldef}`, or in plain TeX
25 % and other formats by `\input{eoldef}`.
26
27
28
29 \ifdefined\eoldef
30 \expandafter\endinput
31 \fi
32 \edef\next{\catcode`\noexpand\@=\the\catcode`\@\space}
33 \catcode`\@=11
34
35 \protected\def\eoldef#1#2#{%
36 \protected\edef#1{%
37 \noexpand\eolarg \csname eoldef@\string#1\endcsname
38 }%
39 \long \expandafter\def \csname eoldef@\string#1\endcsname#2\@nil
40 }
41 \protected\def\eolgdef#1#2#{%
42 \protected\xdef#1{%
43 \noexpand\eolarg \csname eoldef@\string#1\endcsname
44 }%
45 \long \expandafter\gdef \csname eoldef@\string#1\endcsname#2\@nil
46 }
47
48 \protected\def\eolarg#1{%
49 \let\eolarg@command= #1%
50 \ifnum \iffalse{\fi `}=\z@ \fi
51 \begingroup
52 \catcode`\ =\thr@@
53 \futurelet\eolarg@temp\eolargA
54 }
55 \def\eolargA{%
56 \expandafter\endgroup
57 \ifcat\bgroup \noexpand\eolarg@temp
58 \expandafter\eolargB
59 \else
60 \expandafter\eolargC
61 \fi
62 }
63 \def\eolargB#1{%
64 \ifnum`{=\z@ }\fi
65 \eolarg@command#1\@nil
66 }
67 \def\eolargC{%
68 \begingroup
69 \endlinechar=`\^^M
70 \catcode`\^^M=12
71 \futurelet\eolarg@temp\eolargD
72 }
73 \begingroup
74 \lccode`+=`\^^M
75 \lccode`$=`\ %
76 \lowercase{
77 \endgroup
78 \def\eolargD{%
79 \ifx\eolarg@temp$%
80 \expandafter\eolargE
81 \else
82 \expandafter\eolargF
83 \fi
84 }
85 \def\eolargE${\eolargF}
86 \def\eolargF#1+{%
87 \endgroup
88 \ifnum`{=\z@ }\fi
89 \eolarg@command#1\@nil
90 }
91 }
92
93 \next
94
95 \endinput