In this MWE, \Nba
is not created.
How to have it ?
Edit
Remplacing \newcommand
by \gdef
makes \Nba
exist but gives fantaisist value ? Any idea ?
\documentclass[10pt,a4paper,french]{article}
\usepackage{tikz,xstring}
\pgfmathsetseed{\number\pdfrandomseed}
\newcommand{\Range}[2]{%
\xdef\NbMin{#1}%
\xdef\NbMax{#2}%
}
\newcommand{\Numbers}[1]{%
\foreach \i in {#1} {%
%
\StrGobbleLeft{\i}{1}[\Decimal]
\StrLeft{\i}{1}[\Letter]
%
\IfStrEq{\Decimal}{}{%
% integer in the range
\pgfmathparse{int(\NbMin+random()*(\NbMax-\NbMin))}%
}{%
% décimal in the range
\pgfmathparse{%
round((\NbMin+random()*(\NbMax-\NbMin))*10^\Decimal)/10^\Decimal}%
} % \pgfmathprintnumber -- problème d'arrondi
\Letter\ -- \pgfmathprintnumber{\pgfmathresult}%
\expandafter\newcommand\csname Nb\Letter\endcsname{%
\pgfmathprintnumber{\pgfmathresult}}
}
}
\begin{document}
\Range{-10}{10}
\Numbers{a1,b,c3}
% \Nba
\end{document}
\Nba
isn't known in the loop already – user31729 Jul 14 '15 at 20:15\Nba
, the loop has to create it. – Tarass Jul 14 '15 at 20:16\Nba
or\Nbb
etc. macros aren't defined already, so it's hopeless to expect, they would be visible outside – user31729 Jul 14 '15 at 20:20