# Lualatex function producing trailing characters

This function was working in the production system and I'm not aware of changing anything (MikTeX did some package updates which may have had an effect).

A very much stripped down MWE is

\documentclass{article}

\directlua{
function underscore(s)
s = tostring(s+2080)
tex.print(s)
end
}

\DeclareRobustCommand{\Binl}[1]{\directlua{underscore([[#1]])}}%

\begin{document}

Use M\Binl{1} or M\Binl{2}

\end{document}


I used to get M_1 and M_2 with proper subscripts, but now the correct unicode characters U+2081 and U+2082 are being generated but have acquired a trailing ".0" as can be seen in the output. N.B. I've omitted prepending "\char\"" to s before passing the string back.

Output :

Use M2081.0 or M2082.0


That's due to the change from lua 5.2 to lua 5.3.

You can force the number to be an integer e.g. with math.floor:

\documentclass{article}

\directlua{
function underscore(s)
s = tostring(math.floor(s+2080))
tex.print(s)
end
}

\DeclareRobustCommand{\Binl}[1]{\directlua{underscore([[#1]])}}%

\begin{document}

Use M\Binl{1} or M\Binl{2}

\end{document}


• Thanks @Ulrike Fischer. That fixed it. Jun 4 '19 at 18:33
s = tostring(math.floor(s+2080))

• Thanks Red-Cloud. Millisecs behind Ulrike. Jun 4 '19 at 18:34