수학 매크로 및 결과를 표로 표시
내가 만든 일부 매크로에 대한 문서를 작성 중입니다. (아마도 매크로에 대한 주석이있을 것임을 알고 있지만 그게 제가 요청하는 내용이 아닙니다.) 이상적으로는 각 행에 매크로 자체, 결과 및 주석이 나열된 일종의 표를 만들고 싶습니다. . 다음은 내가 현재하고있는 일과하고 싶은 일을 보여주는 MWE입니다.
\documentclass{article}
\usepackage[margin=1in]{geometry}
\usepackage{xparse}
\usepackage{lmodern}
\usepackage{listings}
\usepackage[most]{tcolorbox}
\DeclareTCBListing{macrobox}{s G{} }{IfBooleanTF={#1}{}{listing side text},title=#2,
listing options={style=tcblatex,commentstyle=\color{red!70!black}}
}
% Funny macro - don't worry about this part
\NewDocumentCommand{\TnidxRoot}{m m m m m m m}{%
{#1}_{1} #2 %
\IfBooleanF{#5}{{#1}_{2} #2} %
\IfBooleanTF{#6}{ %
{#1}_{3} % 3D
\IfBooleanT{#7}{#2 {#1}_{4} } % 4D
}{ %
\IfBooleanTF{#3}{\cdots}{\dots} #2 {#1}_{#4} %
}%
}
% Funny macro - don't worry about this part
\NewDocumentCommand{\Tnsz}{s s t! G{n} O{d}}{%
\TnidxRoot{#4}{\times}{\BooleanTrue}{#5}{#3}{#1}{#2}%
}
\begin{document}
What I currently do is this:
\begin{macrobox}{Size commands}
$\Tnsz$ \\ % Default
$\Tnsz!$ \\ % Compact, no 2nd index
$\Tnsz{m}$ % Change main letter
\end{macrobox}
But I'd like a nice macro to generate rows of the following table, where the macro for row 1 might be something like \verb|\ExampleRow{\Tnsz}{Default}|.
\begin{tabular}{|l|l|l|}
\hline
\LaTeX\ Command & Result & Description \\ \hline
\verb|\Tnsz| & $\Tnsz$ & Default \\ \hline
\verb|\Tnsz!| & $\Tnsz!$ & Compact, no second index \\ \hline
\verb|\Tnsz{m}| & $\Tnsz{m}$ & Change main letter \\ \hline
\end{tabular}
\end{document}

답변
Ulrich의 제안과 크게 다르지 않지만 코딩이 더 간단합니다. 매크로에는 수학 모드에서 인쇄 할 재료에 대한 *-변형이 있습니다.
\documentclass{article}
\usepackage{amsmath}
\usepackage{booktabs}
%\usepackage{xparse} % uncomment if using LaTeX prior to 2020-10-01
\ExplSyntaxOn
\NewDocumentCommand{\ExampleRow}{svm}
{
\texttt{#2} &
\IfBooleanT{#1}{$} \tl_rescan:nn { } { #2 } \IfBooleanT{#1}{$} &
#3 \\
}
\ExplSyntaxOff
\begin{document}
\begin{tabular}{lll}
\toprule
\ExampleRow{\fbox{a}}{Make a framed box}
\ExampleRow{\framebox[2cm][l]{a}}{Make a framed box}
\ExampleRow*{\sin}{Sine function}
\ExampleRow*{\xrightarrow{f}}{Extendable arrow}
\ExampleRow*{\xrightarrow[g]{}}{Extendable arrow}
\bottomrule
\end{tabular}
\end{document}

첫 번째 인수는 그대로 흡수되지만 두 번째 열 (가능하면 $
문자 사이)에 사용하기 위해 다시 검색됩니다 .
나는 egreg의 예를 부가 별표 인수 및-다음 내 예를 편집 한 :
함께 \ExampleRow*{...
코드가 수학 모드에서 실행됩니다.
로 \ExampleRow{...
코드 만 수학 모드에서 실행되는 코드 자체는 수학 모드로 전환하기위한 지침이 포함 된 경우.
egreg 달리, 내가 사용하지 않는 \tl_rescan:nn
,하지만 여전히 사용 \scantokens
사용하는 경우 때문에 \scantokens
, 같은 것들을 \verb|...|
그대로 또한 모드, 작업로 전환하는가. 와 \tl_rescan:nn
같은 일들이 작동하지 않습니다.
사이의 미묘하지만 중요한 차이 \scantokens
와이 \tl_rescan:nn
질문에 처리되는
사이에 필수 / 결정적인 차이점은 무엇 \ scantokens / \ tex_scantokens : D 및 \ tl_rescan : 윈?
그리고
expl3-token-list-variable의 내용을 다른 "함수"에 인수로 어떻게 전달할 수 있습니까?
xparse가 사용 중이므로 아마도 \ExampleRow
- v (verbatim) 유형의 인수 읽기,
\verbatim@font
코딩을 보여주기 위해 실제로 인쇄하십시오.- 결과를 표시 하기 위해
\scantokens
, 중첩$
및 후행%
(\scantokens
삽입\endlinechar
...)으로 피드하십시오 .
\documentclass{article}
\usepackage[margin=1in]{geometry}
\usepackage{xparse}
\usepackage{lmodern}
\usepackage{listings}
\usepackage[most]{tcolorbox}
\DeclareTCBListing{macrobox}{s G{} }{IfBooleanTF={#1}{}{listing side text},title=#2,
listing options={style=tcblatex,commentstyle=\color{red!70!black}}
}
% Funny macro - don't worry about this part
\NewDocumentCommand{\TnidxRoot}{m m m m m m m}{%
{#1}_{1} #2 %
\IfBooleanF{#5}{{#1}_{2} #2} %
\IfBooleanTF{#6}{ %
{#1}_{3} % 3D
\IfBooleanT{#7}{#2 {#1}_{4} } % 4D
}{ %
\IfBooleanTF{#3}{\cdots}{\dots} #2 {#1}_{#4} %
}%
}
% Funny macro - don't worry about this part
\NewDocumentCommand{\Tnsz}{s s t! G{n} O{d}}{%
\TnidxRoot{#4}{\times}{\BooleanTrue}{#5}{#3}{#1}{#2}%
}
%--------------------------------------------------------------------------
% This is what I would probably do:
%--------------------------------------------------------------------------
\begingroup
\makeatletter
% Let's use ^^A instead of %.
% Make % other so it can be "fed" to \scantokens to handle \scantokens'
% insertion of \endlinechar;
\catcode`\^^A=14\relax
\catcode`\%=12\relax
\@firstofone{^^A
\endgroup
\NewDocumentCommand\ExampleRow{svm}{^^A
{\verbatim@font#2}&^^A
{\IfBooleanT{#1}{$}\scantokens{#2%}\IfBooleanT{#1}{$}}&^^A {#3}\\\hline^^A }^^A }% %-------------------------------------------------------------------------- \begin{document} What I currently do is this: \begin{macrobox}{Size commands} $\Tnsz$ \\ % Default $\Tnsz!$ \\ % Compact, no 2nd index $\Tnsz{m}$ % Change main letter \end{macrobox} But I'd like a nice macro to generate rows of the following table, where the macro for row 1 might be something like \verb|\ExampleRow{\Tnsz}{Default}|. \begin{tabular}{|l|l|l|} \hline \LaTeX\ Command & Result & Description \\ \hline \verb|\Tnsz| & $\Tnsz$ & Default \\ \hline \verb|\Tnsz!| & $\Tnsz!$ & Compact, no second index \\ \hline \verb|\Tnsz{m}| & $\Tnsz{m}$ & Change main letter \\ \hline
\verb+\verb|verbatim stuff|+ & \verb|verbatim stuff| & verbatim material \\ \hline
\end{tabular}
\bigskip
Here it is:
\bigskip
\begin{tabular}{|l|l|l|}
\hline
\LaTeX\ Command & Result & Description \\ \hline
\ExampleRow*{\Tnsz}{Default}%
\ExampleRow*{\Tnsz!}{Compact, no second index}%
\ExampleRow*{\Tnsz{m}}{Change main letter}%
\ExampleRow{\verb|verbatim stuff|}{verbatim material}%
\end{tabular}
\end{document}

아마도 다음과 같은 것일까 요? (이번에는 매크로 이름 뒤에 추가 공백이 없음)
\makeatletter
\newcommand\strings[1]{\@tfor\sss:=#1\do{\expandafter\string\sss}}
\makeatother
\newcommand\ExampleRow[2]{\texttt{\strings{#1}} & $#1$ & #2 \\}

\documentclass{article}
\makeatletter
\newcommand\strings[1]{\@tfor\sss:=#1\do{\expandafter\string\sss}}
\makeatother
\newcommand\ExampleRow[2]{\texttt{\strings{#1}} & $#1$ & #2 \\}
\begin{document}
\begin{tabular}{lll}
\ExampleRow{\times!\times}{binary product}
\ExampleRow{\prod}{generic product}
\end{tabular}
\end{document}
이전 솔루션 (매크로 이름 뒤에 공백이 있음)
어쩌면 뭔가
\newcommand\ExampleRow[2]{\texttt{\detokenize{#1}} & $#1$ & #2 \\}
당신의 목적에 충분합니까?
\documentclass{article}
\newcommand\ExampleRow[2]{\texttt{\detokenize{#1}} & $#1$ & #2 \\}
\begin{document}
\begin{tabular}{lll}
\ExampleRow{\times}{binary product}
\ExampleRow{\prod}{generic product}
\end{tabular}
\end{document}
