\edef
Lua 루프가 포함된 'ed(확장) 매크로를 어떻게 가질 수 있나요 tex.sprint
? tex.sprint
비슷한 매크로가 또 있으면 오류가 발생합니다 \blindtext[<n>]
. 루아 루프에서 Hello world!
사용하는 것처럼 매크로가 아닌 문자열을 인쇄해도 오류가 발생하지 않습니다 . 매크로 정의를 tex.sprint
확장하지 않고(사용하지 않음) 대신 사용하는 경우에도 오류가 발생하지 않습니다 . 왜 이렇게이다?\edef
\newcommand
\newcommand
아래는 , 를 먼저 사용한 코드입니다 \edef
. 먼저 코드를 있는 그대로 실행하고, 두 번째 실행에서는 \edef
버전의 주석 처리를 제거하여 오류를 확인합니다.
! Use of \\blindtext doesn't match its definition.
\kernel@ifnextchar ...rved@d =#1\def \reserved@a {
#2}\def \reserved@b {#3}\f...
l.26 \directlua{dofile("blindtextloop.lua")}
%
?
% lualatex edefloop.tex
\documentclass[notitlepage,letterpaper]{article}
\usepackage[english]{babel}
\usepackage{blindtext}
\begin{document}
% Note: This will write file blindtextloop.lua in you current directory
\begin{filecontents*}{blindtextloop.lua}
for i=0,3 do
tex.sprint(" \\blindtext[1] \\par")
end
\end{filecontents*}
% Unexpanded blindtext
\newcommand{\myblindtext}{%
\directlua{dofile("blindtextloop.lua")}%
}%
Expanding next:
\myblindtext
%% Uncomment following lines in second run to see the error:
% %Expanded blindtext
% \edef\myblindtextexpanded{%
% \directlua{dofile("blindtextloop.lua")}%
% }%
% Already expanded:
% \myblindtextexpanded
\end{document}
답변1
edef에서 Lua 루프를 확장할 수 있지만 \blindtext
이 경우에는 매크로를 확장할 필요가 없지만 터미널 출력에 표시된 대로 다음
\myblindtextexpanded
과 같이 정의됩니다.
macro:-> \blindtext [1] \par \blindtext [1] \par \blindtext [1] \par \blindtext
[1] \par
따라서 루프는 의 반복 호출로 풀렸습니다 \blindtext
.
% lualatex edefloop.tex
\documentclass[notitlepage,letterpaper]{article}
\usepackage[english]{babel}
\usepackage{blindtext}
\begin{document}
% Note: This will write file blindtextloop.lua in you current directory
\begin{filecontents*}{blindtextloop.lua}
for i=0,3 do
tex.sprint(" \\noexpand\\blindtext[1] \\par")
end
\end{filecontents*}
% Unexpanded blindtext
\newcommand{\myblindtext}{%
\directlua{dofile("blindtextloop.lua")}%
}%
Expanding next:
\myblindtext
%% Uncomment following lines in second run to see the error:
%Expanded blindtext
\edef\myblindtextexpanded{%
\directlua{dofile("blindtextloop.lua")}%
}%
% Already expanded:
\typeout{\meaning\myblindtextexpanded}
\myblindtextexpanded
\end{document}