I want to generate boolean variables (for example \a1_bool, \a2_bool etc., which depends of value of a variable). But when I generate it, I get an error:
! Missing number, treated as zero.
<to be read again>
}
l.7 ...xist:NTF{\l__b_\int_eval:N{\g__a_int}_bool}
?
\documentclass{article}
\usepackage{expl3}
\pagestyle{empty}
\ExplSyntaxOn
\int_gzero_new:N{\g__a_int}
\bool_if_exist:NTF{\l__b_\int_eval:N{\g__a_int}_bool}{\message{variable exists}}{\bool_new:N{\l__b_\int_eval:N{\g__a_int}_bool}}
\ExplSyntaxOff
\begin{document}
\end{document}
1 Answer 1
You are using the wrong variant. An N argument expects only a single (usually unbraced) argument, so this is correct:
\bool_if_exist:NTF \l_tmpa_bool { true } { false }
while this is wrong:
\bool_if_exist:NTF { l_tmpa_bool } { true } { false } % WRONG!
because the first (N) argument you passed to \bool_if_exist:NTF is a list of 11 character tokens (l _ t m p a _ b o o l).
You want the c variant here, to generate a "control sequence name" out of the argument tokens:
% ↓
\bool_if_exist:cTF { l_tmpa_bool } { true } { false }
The same goes for \bool_new:c, instead of \bool_new:N. Also, \int_eval:N does not exist. The function you want here is \int_use:N:
\documentclass{article}
\usepackage{expl3}
\ExplSyntaxOn
\int_gzero_new:N \g__kozlovskiy_a_int
\bool_if_exist:cTF { l__kozlovskiy_b_ \int_use:N \g__kozlovskiy_a_int _bool }
{ \iow_term:n { variable~exists } }
{ \bool_new:c { l__kozlovskiy_b_ \int_use:N \g__kozlovskiy_a_int _bool } }
\ExplSyntaxOff
\begin{document}
\end{document}
-
Thank you very much for your help. Now,i hope,it's ok,but i want to understood differents betwen N and n. Why the N argument i can't surround by {},because as i here,according the latex rules it better after command use {} for each argument of this command.Aleksandr Kozlovskiy– Aleksandr Kozlovskiy2020年02月28日 11:33:44 +00:00Commented Feb 28, 2020 at 11:33
-
@AleksandrKozlovskiy The
Nmeans a single token as argument, so things like\l_tmpa_bool,a,1,$, which are all single tokens can be used in anNargument. Theexpl3package and LaTeX3 programming guide says aboutN: "Single token (unliken, the argument must not be surrounded by braces)". Yes, as you said it will work with braces because that's how TeX will grab an argument, but the guideline is to not use braces forN(andV)-type arguments.Phelype Oleinik– Phelype Oleinik2020年02月28日 12:30:57 +00:00Commented Feb 28, 2020 at 12:30