%20%D0%B4%D1%80%D1%83%D0%B3%D0%BE%D0%B9%20%D0%BA%D0%BE%D0%BC%D0%B0%D0%BD%D0%B4%D0%B5.png)
Мне сложно элегантно определить команду LaTeX3 и переслать ее аргументы (в частности, звезды, токены, украшения) другой команде. Думаю, я смогу заставить это работать с помощью \expandonce
или похожего, но, думаю, есть лучшее решение.
МВЭ:
\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
(аргумент 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}