I have two codes for evaluating number. First of it for evaluating floating point number:
\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn
\NewDocumentCommand{\evaluate}{m}
{ \fp_set:Nn \l_myvar_fp {#1}
\fp_eval:n { \l_myvar_fp }
}
\ExplSyntaxOff
\begin{document}
\evaluate{2+3}
\end{document}
It is well done and I get correct answer.
Then of it for evaluating integer number:
\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn
\NewDocumentCommand{\evaluate}{m}
{ \int_set:Nn \l_myvar_int {#1}
\int_eval:n { \l_myvar_int }
}
\ExplSyntaxOff
\begin{document}
\evaluate{2+3}
\end{document}
In the second example I just change fp
to int
, but I get an error in the second case:
Undefined control sequence
But if I directly use \int_eval:n
without using an intermediate variable \l_myvar_int
it is well done.
\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn
\NewDocumentCommand{\evaluate}{m}
{ \int_eval:n { #1 }
}
\ExplSyntaxOff
\begin{document}
\evaluate{2+3}
\end{document}
Only after definition variable via \int_new:N \l_myvar_int
it is successfully compiled.
Why in first case code well done without definition of a new variable, but it the second case does not?
\int_set:Nn
does not define the variable, whereas\fp_set:Nn
does – user31729 May 28 '17 at 18:05\int_set:Nn
does not define, but\fp_set:Nn
does. Well, this is not obvious and confusing. – sergiokapone May 28 '17 at 18:09\<thing>_eval:n
directly or set a variable then\<thing>_use:N
it. – Joseph Wright♦ May 28 '17 at 18:25\<thing>_eval:n
directly. But when I introduced an intermediate variable I got an error and ask here. Is the\<thing>_use:N
a synonym of\<thing>_eval:N
in my case? – sergiokapone May 28 '17 at 18:36