LuaLatex:创建具有多个目录的 tabularx

LuaLatex:创建具有多个目录的 tabularx

我正在使用 LuaLatex 创建表格,但只有当整个表格在单个表格内创建时它才有效directlua

为什么前者有效而后者无效?

这项工作

\directlua{
    tex.print("\\begin{tabularx}{\\linewidth}{XX}")
    tex.print("a&b \\\\")
    tex.print("\\end{tabularx}")
}

这不

\directlua{
    tex.print("\\begin{tabularx}{\\linewidth}{XX}")
    tex.print("a&b \\\\")
}
\directlua{
    tex.print("\\end{tabularx}")
}

错误消息

Runaway argument?

‪./main.tex, 7‬
{XX} a&b \\ \directlua { tex.print("\\end{tabularx}") } 
! File ended while scanning use of \TX@get@body.
<inserted text> 
\par 
l.7     \input{data/Attributes.tex}
                                 
I suspect you have forgotten a `}', causing me
to read past where you wanted me to stop.
I'll try to recover; but if the error is serious,
you'd better type `E' or `X' now and fix your file.
```

答案1

tabularx提前读取 find\end{tabularx}以保存表体以供多次试验,但尚未完成。如果没有 lua,您会看到相同的结果,但是

\def\xxx{\end{tabularx}} \begin{tabularx}{\textwidth}...  \xxx

因此,您可以使用多个\directlua但保留 Lua 端的字符串,直到准备好\end

在此处输入图片描述

\documentclass{article}

\usepackage{tabularx}

\begin{document}

\begin{center}

\directlua{
    nextbegin="\\begin{tabularx}{\\linewidth}{XX}"
    nextbody="a&b \\\\"
}
\directlua{
    tex.print(nextbegin)
    tex.print(nextbody)
    tex.print("\\end{tabularx}")
}

  
\end{center}

\end{document}

相关内容