Calling non-\long macro as \long
You can not turn off the error check however plain (and latex) have \endgraf
which is \let
(rather than \def
) to the primitive \par
and is there for exactly this reason so you can use
\short{a\endgraf b}
the only other alternative would be to define a \long
version of the command, which is trivial if copying the source is a possibility, but can be tricky if just the macro is available, especially if it has delimited arguments. If etex is available, basically you can use \scantokens
to re-parse a \long\def
that can be constructed from the output from \meaning\short
.
If you have a simple macro, say with two undelimited arguments, it's possible to patch it for becoming \long
without e-TeX:
\def\foo#1#2{#1-#2}
\begingroup\toks0=\expandafter{\foo{#1}{#2}}
\edef\x{\endgroup\long\def\noexpand\foo##1##2{\the\toks0 }}\x
\foo{a\par b}{c\par d}
{\tt\meaning\foo}
(see https://tex.stackexchange.com/a/39980/4427 for an explanation of the trick).
If the macro has delimited arguments or you don't want to bother knowing how many arguments it takes, \scantokens
is your friend, but requires an e-TeX enabled engine, such as pdfTeX, XeTeX or LuaTeX.
\def\makelong#1{%
\expandafter\getparts\meaning#1\relax
\domakelong#1%
}
\begingroup
\catcode`M=12 \catcode`A=12 \catcode`C=12 \catcode`R=12 \catcode`O=12
\lowercase{\endgroup\def\getparts#1MACRO:#2->#3\relax}{%
\def\prefixes{#1}%
\def\parameters{#2}%
\def\replacement{#3}%
}
\def\domakelong#1{%
\edef\temp{\long\prefixes\def\noexpand#1\parameters{\replacement}}%
\scantokens\expandafter{\temp}%
}
\protected\def\short#1{==#1==}
\def\nonlong#1+#2-{(#1)--(#2)}
\makelong\short
\makelong\nonlong
\short{a\par b}
\nonlong X\par Y+Z\par W-
{\tt\meaning\short}
{\tt\meaning\nonlong}
\bye
If you are using LuaTeX then you can set \suppresslongerror
to a positive value. For example
\def\short#1{#1}
\suppresslongerror=1
\short{a
b}
\suppresslongerror=0
or
\long\def\forcelong#1{\suppresslongerror=1 #1\suppresslongerror=0 }
\forcelong{\short{a
b}}