LaTeX3: 인수(토큰, 별, 장식)를 다른 명령으로 전달하는 우아한 방법

LaTeX3: 인수(토큰, 별, 장식)를 다른 명령으로 전달하는 우아한 방법

LaTeX3 명령을 우아하게 정의하고 해당 인수(특히 별표, 토큰, 장식)를 다른 명령에 전달하는 데 어려움을 겪고 있습니다. 나는 그것을 사용하거나 유사하게 작동시킬 수 있을 것이라고 생각 \expandonce하지만 더 나은 해결책이 있다고 생각합니다.

MWE:

\documentclass[]{article}

\NewDocumentCommand{\mycommand}{st't-t.e_O{}m}{%
  I am a command called \IfBooleanT{#1}{with a star, }\IfBooleanT{#2}{with a prime, }\IfBooleanT{#3}{with a dash, }\IfBooleanT{#4}{with a dot, }\IfNoValueTF{#5}{}{with an underscore (#5), } with the optional argument ``#6'' and with the mandatory argument ``#7''.
}

%% This fails:
% \NewDocumentCommand{\mynewcommand}{st't-t.e_O{}m}{%
%   \mycommand\IfBooleanT{#1}{*}\IfBooleanT{#2}{'}\IfBooleanT{#3}{.}\IfBooleanT{#4}{_{#4}}[foo#5]{#6}%
% }

%% This fails:
% \NewDocumentCommand{\mynewcommand}{st't-t.e_O{}m}{%
%   \mycommand#1#2#3#4[foo#5]{#6}%
% }

\begin{document}
\mycommand'_{below text}[I am optional]{yes}

How to define a new command so that mynewcommand behave like mycommand except that it prepends a string like "foo" in front of the optional argument?

% \mynewcommand*'-._{below text}[I am optional]{yes}


\end{document}

답변1

이것이 당신이 원하는 것입니까? 에서 인수 #3(argument s-) 를 간과하신 것 같아서 \mynewcommand임의로 추가했습니다.

\documentclass[]{article}

\NewDocumentCommand{\mycommand}{st't-t.e_O{}m}{%
  I am a command called \IfBooleanT{#1}{with a star, }\IfBooleanT{#2}{with a prime, }\IfBooleanT{#3}{with a dash, }\IfBooleanT{#4}{with a dot, }\IfValueT{#5}{with an underscore (#5), } with the optional argument ``#6'' and with the mandatory argument ``#7''.
}

% This works:
 \NewDocumentCommand{\mynewcommand}{st't-t.e_O{}m}{%
   \expandafter\mycommand\expanded{\IfBooleanT{#1}{*}\IfBooleanT{#2}{'}\IfBooleanT{#3}{-}\IfBooleanT{#4}{.}\IfValueT{#5}{\unexpanded{_{#5}}}\unexpanded{[foo#6]{#7}}}%
 }

%% This fails:
% \NewDocumentCommand{\mynewcommand}{st't-t.e_O{}m}{%
%   \mycommand#1#2#3#4[foo#5]{#6}%
% }

\begin{document}
\mycommand'_{below text}[I am optional]{yes}

How to define a new command so that mynewcommand behave like mycommand except that it prepends a string like "foo" in front of the optional argument?

\mynewcommand*'-._{below text}[I am optional]{yes}


\end{document}

여기에 이미지 설명을 입력하세요

답변2

하지 않다. 그것은 무엇 \NewDocumentCommand을 위한 것이 아닙니다 .

어쨌든 먼저 다음의 인수를 수정하세요 \mynewcommand. 목록이 꺼져 있습니다.

\documentclass[]{article}

\NewDocumentCommand{\mycommand}{st't-t.e_O{}m}{%
  I am a command called
  \IfBooleanT{#1}{with a star, }%
  \IfBooleanT{#2}{with a prime, }%
  \IfBooleanT{#3}{with a dash, }%
  \IfBooleanT{#4}{with a dot, }%
  \IfValueT{#5}{with an underscore (#5), }
  with the optional argument ``#6'' and with the mandatory argument ``#7''.
}

\NewDocumentCommand{\mynewcommand}{st't-t.e{_}O{}m}{%
  \expanded{%
    \mycommand
    \IfBooleanT{#1}{*}%
    \IfBooleanT{#2}{'}%
    \IfBooleanT{#3}{-}%
    \IfBooleanT{#4}{.}
    \IfValueT{#5}{_{\unexpanded{#5}}}%
    [foo\unexpanded{#6}]%
    {\unexpanded{#7}}%
  }%
}


\begin{document}
\mycommand'_{below text}[I am optional]{yes}

How to define a new command so that mynewcommand behave like mycommand except that it prepends a string like "foo" in front of the optional argument?

\mynewcommand*'-._{below text}[I am optional]{yes}

\end{document}

여기에 이미지 설명을 입력하세요

관련 정보