2

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}
Phelype Oleinik
72.5k20 gold badges165 silver badges241 bronze badges
asked Feb 28, 2020 at 0:56

1 Answer 1

5

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}
answered Feb 28, 2020 at 1:07
2
  • 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. Commented Feb 28, 2020 at 11:33
  • @AleksandrKozlovskiy The N means a single token as argument, so things like \l_tmpa_bool, a, 1, $, which are all single tokens can be used in an N argument. The expl3 package and LaTeX3 programming guide says about N: "Single token (unlike n, 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 for N (and V)-type arguments. Commented Feb 28, 2020 at 12:30

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.