I have a lua function to withch I want to pass some extra optional latex code (basycally a macro with a parameter, macro can change, parameter too). I have to double backslash the name of the macro, I understand why, but I hope there is a tricky way to avoid this "unnatural" double backslash (latex view side speaking) ?

enter image description here





% How to avoid this following double \\ ?
% if possible ...


bob.lua file :

t = {}
sem = 1
t[1] = "31 Août" -- the Semaine function calculates this values
t[2] = "5 Sept"
t[3] = "A"

function Semaine (option)
tex.print ("\\rule[.5em]{0pt}{1em}\\colorbox{gray!30!white}{"
..sem.." -- "
..t[1].." -- "..t[2].."}\\par")
  • You could write \TP{\MyC{ça marche !!} instead of \TP[\\MyC{ça marche !!}]... – Mico Aug 6 '15 at 14:48
  • Works in my to simple example. See my update. – Tarass Aug 6 '15 at 15:07

The problem is


At least it prevents, that #1 is expanded too early. But #1 is user contributed content, which might contain anything, including quotes, which would break the intended Lua syntax. Therefore LuaTeX provides \luaescapestring, which can be used as \luatexluaescapestring in LuaLaTeX. It automatically quotes the special characters to get a safe Lua string:


Then \MyC is kept as macro and \\ remains the command for a new line.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.