Line break in macro with > 9 parameters

I have a transition system where the transition requires many arguments to describe it. It ends up looking like this:

A \xlongrightarrow[a_1; b_1; c_1]{a_2; b_2; c_2} B


So naturally I have a macro that looks like:

\newcommand{\step}[8]{#1 \xlongrightarrow[#3; #4; #5]{#6; #7; #8} #2}


and I can use it like \step{A}{B}{a_1}{b_1}{c_1}{a_2}{b_2}{c_2}

The good thing is that when the rendered output gets too long, I can squeeze in a \\ somewhere in the usage of the macro like step{A}{\\B}{a_1}{b_1}{c_1}{a_2}{b_2}{c_2} meaning that I get the expansion that I want:

A \xlongrightarrow[a_1; b_1; c_1]{a_2; b_2; c_2} \\B


Now, however, I need exactly 10 arguments, and I do something like:

\documentclass{article}

\usepackage{extarrows} % defines \xlongrightarrow

\newcommand{\step}[9]{
\def\tempa{#1}%
\def\tempb{#2}%
\def\tempc{#3}%
\def\tempd{#4}%
\def\tempe{#5}%
\def\tempf{#6}%
\def\tempg{#7}%
\def\temph{#8}%
\def\tempi{#9}%
\stepcont
}
\newcommand{\stepcont}[1]{\tempa \xlongrightarrow[\tempc; \tempd; \tempe; \tempf]{\tempg; \temph; \tempi; #1} \tempb}

\begin{document}

$\step{A}{B}{a_1}{b_1}{c_1}{a_2}{b_2}{c_2}$

\end{document}


which is amazing, but now I can no longer add \\ in front of the arguments to force a line break.

So finally my question: Is there a way where I can have more than 9 arguments to a macro, and still allow line breaks in the macro?

• I'm uncertain about where's the advantage in using nine arguments instead of the more natural \step{A}{B}{a_1;b_1;c_1}{a_2;b_2;c_2} – egreg Mar 24 '18 at 14:04
• why do you want so many arguments, which makes the source very hard to read (hard to see which is the 6th and which the 7th argument), why not \newcommand{\step}[8]{#1 \xlongrightarrow[#2]{#3} #4} and use ;as in \step{zz}{a;b;c}{x;y;z} ? – David Carlisle Mar 24 '18 at 14:04
• oh no, I agreed with @egreg :( – David Carlisle Mar 24 '18 at 14:05
• Good point! I would like LaTeX to tell me if I missed an parameter to the transition, which I won't see if I have several parameters in one argument. – Mathias Vorreiter Pedersen Mar 24 '18 at 14:11
• @MathiasVorreiterPedersen latex won't help with that. if you only do 6 parameters instead of 9 \step{1}[2}{3}{4}{5}{6} next thing then you get not error it just gobbles n, e, x as the last three arguments. – David Carlisle Mar 24 '18 at 14:14

I guess that a macro that checks the number of requested items is what you need. Here the default is 3, but it can be whatever is the normal requested number.

\documentclass{article}
\usepackage{xparse}
\usepackage{amsmath}

\ExplSyntaxOn
\NewDocumentCommand{\step}{O{3}mmmm}
{
#2 % source
\mvp_step:nnn { #1 } { #4 } { #5 }
#3 % target
}

\seq_new:N \l__mvp_step_top_seq
\seq_new:N \l__mvp_step_bot_seq

\cs_new_protected:Nn \mvp_step:nnn
{
\seq_set_split:Nnn \l__mvp_step_top_seq { ; } { #2 }
\seq_set_split:Nnn \l__mvp_step_bot_seq { ; } { #3 }
\int_compare:nNnF { \seq_count:N \l__mvp_step_top_seq } = { #1 }
{
\msg_error:nnxxx { mvp } { step }
{ above }
{ \seq_count:N \l__mvp_step_top_seq }
{ #1 }
}
\int_compare:nNnF { \seq_count:N \l__mvp_step_bot_seq } = { #1 }
{
\msg_error:nnxxx { mvp } { step }
{ below }
{ \seq_count:N \l__mvp_step_bot_seq }
{ #1 }
}
\xrightarrow
[\seq_use:Nn \l__mvp_step_bot_seq {;\,}]
{\seq_use:Nn \l__mvp_step_top_seq {;\,}}
}

\msg_new:nnnn { mvp } { step }
{
Bad ~ number ~ of ~ items
}
{
You ~ have ~ #2 ~ items ~ #1 ~ the ~ arrow ~ instead ~ of ~ #3
}
\ExplSyntaxOff

\begin{document}

$\step{A}{B}{a_1;b_1;c_1}{a_2;b_2;c_2}$

$\step[4]{A}{B}{a_1;b_1;c_1;d_1}{a_2;b_2;c_2;d_2}$

$\step[4]{A}{B}{a_1;b_1;c_1;d_1}{a_2;b_2;c_2}$ %%% error

\end{document}


Here's the output on the console:

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! mvp error: "step"
!
!
! See the mvp documentation for further information.
!
! For immediate help type H <return>.
!...............................................

l.54 $\step[4]{A}{B}{a_1;b_1;c_1;d_1}{a_2;b_2;c_2}$ %%% error
? h
|'''''''''''''''''''''''''''''''''''''''''''''''
| You have 3 items below the arrow instead of 4
|...............................................


• Ah, that's a cool idea! I think I'll start applying this trick in more places. – Mathias Vorreiter Pedersen Mar 24 '18 at 15:32