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