[luatex] \luaescapestring and # tokens
Joseph Wright
joseph.wright at morningstar2.co.uk
Mon Jun 2 08:24:31 CEST 2014
Hello all,
The usual approach to emulating \pdfstrcmp in LuaTeX involves escaping
input using \luaescapestring and then doing a Lua-based comparison,
something like:
\catcode`\@=11 %
\ifdefined\directlua
\directlua{%
function strcmp (A, B)
if A == B then
tex.write ("0")
elseif A < B then
tex.write ("-1")
else
tex.write ("1")
end
end
}%
\long\def\pdf at strcmp#1#2{%
\directlua{%
strcmp ("\luaescapestring{#1}", "\luaescapestring{#2}")
}%
}%
\else
\ifdefined\pdfstrcmp
\let\pdf at strcmp\pdfstrcmp
\else
\let\pdf at strcmp\strcmp
\fi
\fi
\message{Value is: \pdf at strcmp{#}{\detokenize{#}}}
\bye
However, as is shown by the demo, this may fail to give the same result
as for the 'real' primitive if # tokens (more generally, catcode 6
tokens). The reason is \luaescapestring doesn't double # tokens.
\message{"\luaescapestring{#}" "\detokenize{#}"}
Is this deliberate, and if so is there a reliable way of emulating
\pdfstrcmp in it's entirety?
--
Joseph Wright
More information about the luatex
mailing list