Я пытаюсь создать LaTeX -macro, который в основном делает разные вещи в зависимости от того, сколько аргументов передано ему.Latex newcommand переменное число аргументов
В основном его функция будет:
\MyMacro{4}
% Processes the argument and returns a set number of objects depending on the number
\MyMacro{4}{3}
% Processes the arguments in a slightly different way, including adding the numbers together
\MyMacro{4}{3}{6}
% Same thing as before, but the result is again processed slightly differently as before
\MyMacro{4}{3}{6}{2}{1}
% The maximum number of arguments the macro needs to handle is 5
Я попытался осуществить следующее решение TeX из примера я нашел в Интернете до 2 атрибутов, но это не нравится.
\makeatletter
% Save first argument as \tempA
\def\MyMacro#1{\def\tempA{#1}\futurelet\next\[email protected]}
% Check for second argument
\def\[email protected]{\ifx\next\bgroup\expandafter\[email protected]\else\expandafter\[email protected]\fi}
% Check for third argument
\def\[email protected]{\ifx\next\bgroup\expandafter\[email protected]\else\expandafter\[email protected]\fi}
% Check for fourth argument
\def\[email protected]{\ifx\next\bgroup\expandafter\[email protected]\else\expandafter\[email protected]\fi}
\def\[email protected]{\section*{\tempA\ is the only argument}}
\def\[email protected]#1{\section*{\tempA\ is the first and #1 is the second argument}}
\def\[email protected]#1#2{\section*{\tempA\ is the first and #1 is the second argument with #2 being the third}}
\def\[email protected]#1#2#3{\section*{\tempA\ is the first and #1 is the second argument, #2 is the third and #3 is the fourth}}
\makeatother
Он работает на 1 или 4, но в 2-3 аргументов, это дает мне «Пункт закончилась до \ MyMacro @ четыре была завершена.»
Мое понимание основного TeX очень минимальное, поэтому я также по достоинству оценил решение LaTeX, используя \ newcommand, если это возможно.
Спасибо!
Спасибо за ответ, хотя я уже обошел проблему в моем проекте с более простой функциональностью, которая также проще реализовать в API. Я воспользовался вашей ссылкой, хотя я могу взглянуть на нее, если позже столкнуться с подобной проблемой. –