blefloch / latex-unravel

Watching TeX digest tokens
24 stars 1 forks source link

Runaway arg recovery for non-\long macro receiving \par #7

Open blefloch opened 8 years ago

blefloch commented 8 years ago

The error recovery for non-\long macros which have simple arguments (#1#2#3...) when they receive \par is different in unravel than in TeX.

\RequirePackage{unravel}
\def\test#1{}
\unravel{\test\par}

internally finds the argument \par, braces it, then expands \test{\par}. TeX complains that there is a runaway argument, and drops everything until the \par. That leaves a brace that has no reason to be there.

blefloch commented 6 years ago

Setting the (internal) "speedup macros" boolean to false fixes the problem. One issue is that \@@_macro_call_quick_loop:NNN calls \@@_input_gpop_item:NF and loses track of whether the argument was braced or not. Otherwise we could look for the string \par in the argument and fall back to \@@_macro_call_safe: in such cases.

blefloch commented 7 months ago

Actually the problem is more dire than I had understood. With \def\test#1{}, expanding \test{{{{{\par}}}}} leads to a Runaway error and leaves five closing braces in the input stream. The only way I see to deal with this on the unravel side would be to have a method that splits a gtl variable at the first \par. (See feature request https://github.com/blefloch/latex-gtl/issues/4.) Then throw away the part before \par, complaining about a Runaway argument, and keep everything after, which most likely leads to other TeX errors detected by unravel.