
저는 LuaLatex를 처음 접했고 간단한 매크로를 작성하려고 합니다.
그러나 백슬래시(예: )가 포함된 문자열을 lua에 보내면 \R^n
코드가 예상대로 작동하지 않습니다.
예를 들어 내 루아 코드는 다음과 같습니다.
function fourier(group, f)
output = '\\mathcal{F}_{'..group..'}'
if f ~= '' then
output = output..'\\left\\{ {'..f..'} \\right\\}'
end
tex.sprint(output)
end
내가 정의하려는 매크로는 다음과 같습니다.
\DeclareDocumentCommand \F{D<>{}O{}}{%
\directlua{
fourier("\luatexluaescapestring{#1}", "\luatexluaescapestring{#2}")
}
}
그러나 을 입력하면 \[ \F<\R^n>[f] \]
PDF에 다음과 같은 내용이 표시됩니다 \mathrm{F}_{@bgroup\R}^n {f}
.
누군가 나를 도와줄 수 있나요?
편집: 전체 코드:
\documentclass{report}
\usepackage{amsmath, amsthm, amssymb, amsfonts}
\usepackage{xparse}
\title{Title}
\author{bkn}
\newcommand{\R}{\mathbb{R}}
\directlua{dofile("functions.lua")}
\DeclareDocumentCommand \F{D<>{}O{}}{%
\directlua{
fourier("\luatexluaescapestring{#1}", "\luatexluaescapestring{#2}")
}
}
\begin{document}
$\F<a>[f]$ % This works
$\F<\mathbb{R}^n>[f]$ % This doesn't
\end{document}
function.lua에는 위의 함수가 포함되어 있습니다.
답변1
LuaTeX는 \edef
내부에서 -like 확장을 수행합니다 \directlua
(후자는 자체적으로 확장 가능하지만). 이를 방지하려면 e-TeX 기본 요소를 사용할 수 있습니다.\unexpanded
\DeclareDocumentCommand \F{D<>{}O{}}{%
\directlua{
fourier(
"\luatexluaescapestring{\unexpanded{#1}}",
"\luatexluaescapestring{\unexpanded{#2}}"
)
}
}