latex-lineno / lineno

lineno – Line numbers on paragraphs
Other
11 stars 2 forks source link

Incompatibility between lineno and \directlua #11

Closed fpantigny closed 6 months ago

fpantigny commented 6 months ago

When I try to compile the following MWE with LuaLaTeX, I have an error : invalid escape sequence near '"\p'

\documentclass{article}
\usepackage{lineno}

\begin{document}

\directlua{tex.print("\\LaTeX")}

\end{document}

When lineno is not loaded, I have the expected output.

I think that the reason is that \\ is not protected when lineno has been loaded. If I add \robustify\\ (with \robustify of etoolbox) it works.

kwwette commented 6 months ago

I don't think this is specific to lineno.

\directlua expands its argument in TeX before feeding to Lua, so the \\ is being interpreted as a TeX command, rather than an escaped \. Any package that modifies \\ in any way (including lineno) is probably going to break this usage.

Instead you probably want to write \directlua{tex.print("\textbackslash LaTeX")} to get a literal backslash passed to Lua.