下一個代碼給出錯誤: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}