
저는 Latex3 초보자입니다. 테스트 MWE는 다음과 같습니다.
\documentclass{article}
\usepackage{amsmath}
\usepackage{xparse} % loads expl3
\begin{document}
\ExplSyntaxOn
\cs_set:Npn \my_mod:nn #1#2 {
% store #1//#2 in \l_tmpa_int
\int_set:Nn \l_tmpa_int { \int_div_truncate:nn {#1}{#2} }
% compute (#1)-\l_tmpa_int*(#2)
% make sure to surround operands with parentheses
% so that when #1 is an expression (e.g. 3-2)
% the order of arithmetic will not change
\int_eval:n { (#1) - \l_tmpa_int * (#2) }
}
% define LaTeX interface
\newcommand{\mymod}[2]{
\my_mod:nn {#1} {#2}
}
\ExplSyntaxOff
\mymod{5}{3}\mymod{6}{3}\mymod{7}{1+2}%201
\end{document}
그리고 이 단계에서는 잘 작동하고 있습니다. 예상대로 "201"이 인쇄됩니다.
다음에는 안에 무엇이 들어있는지 살펴보았습니다.\my_mod
, 함수에 대해 더 잘 이해할 수 있었습니다.라텍스3. 나는 썼다:
\documentclass{article}
\usepackage{amsmath}
\usepackage{xparse} % loads expl3
\begin{document}
\ExplSyntaxOn
\cs_set:Npn \my_mod:nn #1#2 {
% store #1//#2 in \l_tmpa_int
\int_set:Nn \l_tmpa_int { \int_div_truncate:nn {#1}{#2} }
% compute (#1)-\l_tmpa_int*(#2)
% make sure to surround operands with parentheses
% so that when #1 is an expression (e.g. 3-2)
% the order of arithmetic will not change
\int_eval:n { (#1) - \l_tmpa_int * (#2) }
}
\newcommand{\showw}[2]{
\cs_show:c \my_mod
}
% define LaTeX interface
\newcommand{\mymod}[2]{
\my_mod:nn {#1} {#2}
}
\ExplSyntaxOff
\mymod{5}{3}
\mymod{6}{3}
\mymod{7}{1+2}%201
\showw{3}{7}
\end{document}
그리고 이 단계에서 TexStudio는 항복을 컴파일하지 못했습니다.정의되지 않은 제어 순서. \showw{3}{7}오류. \cs_show:c
으로 기능을 변경했을 때 동일한 오류가 발생했다는 점을 언급해야 합니다 \cs_show:N
.
\cs_show
어떻게 하면 기능을 올바르게 사용할 수 있나요 ?
답변1
\cs_show:N
다음 제어 시퀀스의 정의만 기록하고 "작동"을 표시하지 않습니다.
또한 TeX에 관한 한 \my_mod:nn
및 는 어떤 방식으로도 관련이 없습니다. \my_mod
전자를 정의하지만 후자는 정의하지 않으며 이를 표시하면 "정의되지 않음"이 생성됩니다.
를 사용하여 실제로 작동하는 모습을 볼 수 있습니다 unravel
.
\documentclass{article}
\usepackage{unravel}
\ExplSyntaxOn
\cs_set:Npn \my_mod:nn #1#2 {
% store #1//#2 in \l_tmpa_int
\int_set:Nn \l_tmpa_int { \int_div_truncate:nn {#1}{#2} }
% compute (#1)-\l_tmpa_int*(#2)
% make sure to surround operands with parentheses
% so that when #1 is an expression (e.g. 3-2)
% the order of arithmetic will not change
\int_eval:n { (#1) - \l_tmpa_int * (#2) }
}
\newcommand{\mymod}[2]{
\my_mod:nn {#1} {#2}
}
\ExplSyntaxOff
\begin{document}
\hbox{\unravel{\mymod{5}{3}}}
%\mymod{6}{3}
%\mymod{7}{1+2}%201
\end{document}
이는 TeX가 결과를 조판하려고 할 때 발생 \hbox
하는 가짜 효과를 피하기 위한 것입니다 . \everypar
63개의 단계가 표시되며 그 중 몇 개만 보여드리겠습니다.
======== Welcome to the unravel package ========
"<|" denotes the output to TeX's stomach.
"||" denotes tokens waiting to be used.
"|>" denotes tokens that we will act on.
Press <enter> to continue; 'h' <enter> for help.
||
|> \mymod {5}{3}
[===== Step 1 =====] \mymod = \long macro:#1#2->\my_mod:nn {#1}{#2}
||
|> \my_mod:nn {5}{3}
[===== Step 2 =====] \my_mod:nn = \long macro:#1#2->\int_set:Nn \l_t...
||
|> \int_set:Nn \l_tmpa_int {\int_div_truncate:nn {5}{3}}\int_eval:n
|> {(5)-\l_tmpa_int *(3)}
[===== Step 3 =====] \int_set:Nn = \protected\long macro:#1#2->#1=\_...
||
|> \l_tmpa_int =\__int_eval:w \int_div_truncate:nn {5}{3}\__int_eval_end:
|> \int_eval:n {(5)-\l_tmpa_int *(3)}
[...steps omitted...]
[===== Step 63 =====] )
|| \tex_the:D
|| \__int_eval:w (5)-1*(3)
|> \__int_eval_end:
[===== Step 64 =====] \tex_the:D =>2
||
|> 2
[===== Step 65 =====] 2
<| 2
||
|>
[===== End =====]
배우는 중이므로 몇 가지 조언을 드립니다. 당신이 할당을 하기 때문에 함수는 \my_mod:nn
이어야 합니다 . protected
하지만 다음과 같이 하면 피할 수 있습니다.
\cs_new:Npn \my_mod:nn #1 #2
{
\int_eval:n { (#1) - \int_div_truncate:nn {#1}{#2} * (#2) }
}