I am trying to create a script which expands some easy to read and write commands into more full-blown math formulas which uses variables so that it first prints its names and then on a new line, it would print its values. For instance:
So, instead of writing:
a_{car}=\frac{v_car}{t_car}, a_{car}=\frac{\SI{20}{metre\per\second}}{\SI{20}{seconds}}, I would just write \matte{acar=\frac{vcar}{tcar}, and it would expand to that first line.
On a different question here on tex.stackexchange, I got a very good general answer to how to accomplish this, but I need some help adjusting it to my own code. The general answer is located here. I'll include that code here:
\documentclass{article}
\usepackage{xparse,l3regex,siunitx}
\ExplSyntaxOn
\prop_new:N \g_runart_variables_prop
\tl_new:N \l__runart_variables_matte_tl
\tl_new:N \l__runart_variables_item_tl
\NewDocumentCommand{\definevariable}{mm}
{ % #1 is the name, #2 is the formatting
\prop_gput:Nnn \g_runart_variables_prop { #1 } { #2 }
}
\NewDocumentCommand{\removevariable}{m}
{ % #1 is the name
\prop_gremove:Nn \g_runart_variables_prop { #1 }
}
\NewDocumentCommand{\matte}{m}
{ % #1 is the expression to output
\tl_set:Nn \l__runart_variables_matte_tl { #1 }
\prop_map_inline:Nn \g_runart_variables_prop
{
\tl_set:Nn \l__runart_variables_item_tl { ##2 }
\regex_replace_all:nnN
{ ##1 }
{ \u{l__runart_variables_item_tl} }
\l__runart_variables_matte_tl
}
\tl_use:N \l__runart_variables_matte_tl
}
\cs_new_protected:Nn \runart_variable_use:n
{
\prop_item:Nn \g_runart_variables_prop { #1 }
}
\ExplSyntaxOff
\definevariable{a_car}{\SI{20}{\metre\per\second}}
\definevariable{v_car}{\SI{40}{\metre}}
\definevariable{t_car}{\SI{2}{\second}}
\begin{document}
\[
\matte{
a_car=\frac{v_car}{t_car}
}
\]
\end{document}
This works great on it's own, but In my document I use a different method for defining variables, like this:
\NewDocumentCommand{\varSet}{definevariable}
% #1 : name, like a_car
% #2 : value, like 20
% #3 : unit, like \metre, this is for siunitx
% #4 : printed name, like \Omega_{R1}
% #5 : optional sisetup for this var only, like color=red
{
\prop_gclear_new:c { g_giacomo_var_#1_prop }
\prop_gput:cnx { g_giacomo_var_#1_prop } { value } { #2 }
\prop_gput:cnn { g_giacomo_var_#1_prop } { unit } { #3 }
\prop_gput:cnn { g_giacomo_var_#1_prop } { name } { #4 }
\IfNoValueTF { #5 } {
\prop_gput:cnn { g_giacomo_var_#1_prop } { sisetup } {blank}
} {
\prop_gput:cnn { g_giacomo_var_#1_prop } { sisetup } { #5 }
}
}
It would be really great if it would be possible to adjust the answer I got to my setup.
