Connecting multiple arguments
A key-value interface seems the better choice:
\documentclass{article}
\usepackage{xparse,siunitx}
\ExplSyntaxOn
\NewDocumentCommand{\var}{m}
{
\begin{flushleft}
\borg_var:n {#1}
\end{flushleft}
}
\keys_define:nn { borg/var }
{
pressure .tl_set:N = \l_borg_var_pressure_tl,
flow .tl_set:N = \l_borg_var_flow_tl,
revolutions .tl_set:N = \l_borg_var_revolutions_tl,
pressure .initial:n = { missing value for pressure },
flow .initial:n = { missing value for pressure },
revolutions .initial:n = { missing value for pressure },
}
\cs_new_protected:Npn \borg_var:n #1
{
\keys_set:nn { borg/var } { #1 }
Pressure ~ \tl_use:N \l_borg_var_pressure_tl \\
Flow ~ \tl_use:N \l_borg_var_flow_tl \\
Revolutions ~ \tl_use:N \l_borg_var_revolutions_tl
}
\ExplSyntaxOn
\begin{document}
\var{
pressure = \SI{100}{bar},
flow = \SI{25}{L/min},
revolutions= \SI{2000}{rpm}
}
\end{document}
The initial values could be changed into warning or even error messages, so as to ensure the values are all given.
Many refinements are possible, for instance if you need only the value and the units are fixed they could be printed automatically and allow for a syntax such as
\var{
pressure = 100,
flow = 25,
revolutions = 2000
}
Just incorporate the calls to \SI
in the macros with
\cs_new_protected:Npn \borg_var:n #1
{
\keys_set:nn { borg/var } { #1 }
Pressure ~ \SI{\l_borg_var_pressure_tl}{bar} \\
Flow ~ \SI{\l_borg_var_flow_tl}{L/min} \\
Revolutions ~ \SI{\l_borg_var_revolutions_tl}{rpm}
}
instead of the code above.
Maybe an easier way?
\def\variable#1,#2,#3;#4,#5,#6;{#1\ #4\\ #2\ #5\\ #3\ #6\\}
with usage
\variable Pressure, Flow, Revolutions;100 Bar, 25 L/min, 2000 rpm;
Here ,'s
and ;'s
separate arguments.