
私は LuaLatex を初めて使用しており、簡単なマクロを記述しようとしています。
ただし、バックスラッシュを含む文字列 ( など) を lua に送信すると\R^n
、コードは期待どおりに動作しません。
たとえば、私の lua コードは次のとおりです。
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}
functions.lua には上記の関数が含まれています。
答え1
LuaTeXは\edef
内部で - のような展開を行います\directlua
(ただし後者はそれ自体展開可能です)。これを回避するには、e-TeXプリミティブを使用します。\unexpanded
\DeclareDocumentCommand \F{D<>{}O{}}{%
\directlua{
fourier(
"\luatexluaescapestring{\unexpanded{#1}}",
"\luatexluaescapestring{\unexpanded{#2}}"
)
}
}