lua循环中下划线(_)的问题

lua循环中下划线(_)的问题

下一个代码给出错误:Missing $ inserted.这是因为其中一个键是c_a。如何修改循环以使用c_a

% !TEX TS-program = lualatex
\documentclass{article}
\usepackage{luacode}

\begin{document}
\parindent = 0pt
\begin{luacode}
tp=tex.print
z = {}

ap = "a'"
bp = "b'"

z.a = {5,2}
z.b = {3,-2}
z.c_a = {3,2}
z[ap] = {99,0}
z.bp = {66,55}

tex.print("The stored coordinates are : "..'\\\\')
-- z.c_a = nil
for k,v in pairs(z) do
   tp(k) tp(tostring(" represents :")) tp(tostring("(" .. v[1]..","..v[2]..")"))
   tex.print('\\\\')
end     
\end{luacode}
\end{document}

答案1

与 Lua 没什么关系,你需要\verb|c_a|或类似的下划线

在此处输入图片描述

\documentclass{article}
\usepackage{luacode}

\begin{document}
\parindent = 0pt
\begin{luacode}
tp=tex.print
z = {}

ap = "a'"
bp = "b'"  -- not used

z.a = {5,2}
z.b = {3,-2}
z.c_a = {3,2}
z[ap] = {99,0}
z.bp = {66,55}

tex.print("The stored coordinates are : "..'\\\\')
-- z.c_a = nil
for k,v in pairs(z) do
   tp("\\verb|" .. k .."|") tp(" represents :") tp("(" .. v[1]..","..v[2]..")")
   tex.print('\\\\')
end     
\end{luacode}
\end{document}

相关内容