I am trying to write a LaTeX3 conditional using \prg_new_conditional:Nnn from the expl3 package. Since the code in the conditional needs to make assignments to some variables, I would like to use grouping in order to do those assgnments locally. However, the following MWE fails to compile:
\documentclass{article}
\usepackage{expl3}
\begin{document}
\ExplSyntaxOn
\prg_new_conditional:Nnn \foo: { p }
{
\group_begin:
% Do some stuff.
\group_end:
\prg_return_true:
}
\bool_if:nTF { \foo_p: } { true } { false }
\ExplSyntaxOff
\end{document}
The following errors show up several times:
! Missing number, treated as zero.
<to be read again>
\group_begin:
l.11 \bool_if:nTF { \foo_p: }
{ true } { false }
A number should have been here; I inserted `0'.
(If you can't figure out why I needed to see a number,
look up `weird error' in the index to The TeXbook.)
! Missing \endcsname inserted.
<to be read again>
\group_begin:
l.11 \bool_if:nTF { \foo_p: }
{ true } { false }
The control sequence marked <to be read again> should
not appear between \csname and \endcsname.
When I remove \group_begin: and \group_end:, then everything works as expected. So what is going on here? Why can't I use grouping within the definition of \foo_p:?
\group_begin:isn't. So, no grouping nor assignments. – egreg May 11 '15 at 07:56\def\z{123}\count0=\zas\zexpands to 123, but you can not go\def\z{{123}}\count0=\zas then\zexpands to{123}which isn't a legal number. Same here the\group_begin:stops the argument being interpreted as true or false. – David Carlisle May 11 '15 at 08:23\prg_new_protected_conditional:Nnn… which explicitly bans thepbranch. So, it's not possible. – Manuel May 11 '15 at 12:20