I'm trying to create something more like the command \SI{number}{units}
of siunitx package but I have some trouble. Reading the PythonTex documentation this problem doesn't exist.
Starting with the answer /#49745
\begin{sagesilent}
def SIsage(number,units=0):
if units==0:
if number in ZZ or number.parent()==QQ:
return r"\SI{"+ str(number) + "}"
else:
return r"\SI{"+ str(float(number)) + "}"
else:
if number in ZZ or number.parent()==QQ:
return r"\SI{"+ str(number) + "}" +"{"+ units + "}"
else:
return r"\SI{"+ str(float(number)) + "}" +"{"+ units + "}"
\end{sagesilent}
\sagestr{SIsage(2442,"\kilo\metre\squared")}
\sagestr{SIsage(2442)}
and it works except when using \newton
witch it become "ewton" problably cause to \n
After this I want to create a new custom LaTeX command that replace \SI{}{}
but I have some trouble with non-default arguments. I didn't understand how them work. I want be able to use both of \SI{number}{units}
that \SI{number}
without units. Probably the best choise is to create two different commands(?)
\newcommand{\SIsage_units}[1]{,"#1"}
\newcommand{\SIsage_number}[1]{\sagestr{SIsage(#1}}
\newcommand{\SISAGE}[2]{\SIsage_number{#2}\SIsage_units{#1})} #doesn't work
The command I want:
\SISAGE{21}{\kilo\metre\squared}
\SISAGE{26}{}
So my problems are:
- how to avoid
\n
- how to set an unic custom command
\SISAGE
Thanks everybody