Tikz `ifeven` triggering error
Clash Royale CLAN TAG#URR8PPP
up vote
2
down vote
favorite
Why the following sample fails to compile in pdflatex when ifeven
is used?
It fails with many errors in line 34 (where the last closing brackets are). The errors are like: Undefined control sequence. }
, Extra }, or forgoten endgroup.}
, Extra else.}
, Extra fi }
.
documentclass[tikz]standalone
newcommandstencilptreg[4]node[circle,fill,draw,inner sep=1.5pt,label=below:#4,#1] at (#2) (#3)
newcommandstencilptstg[4]node[circle,fill,white,draw=black,inner sep=1.5pt,label=below:#4,#1] at (#2) (#3)
begindocument
begintikzpicture[x=2cm,y=2cm]
pgfmathsetmacroN5;
pgfmathsetmacroM3;
pgfmathsetmacroNN(N*2); % Number of points in staggered grid
pgfmathsetmacroMM(M*2); % Number of points in staggered grid
foreach j [evaluate=j as q using int(j/2)] in 0,1,...,MM
ifoddj
draw [black!50,thin] (0,j) node[red,left] $n=fracj2$ -- (N,j);
else
draw [black!50,thin] (0,j) node[red,left] $n=q$ -- (N,j);
fi
foreach i [evaluate=i as p using (i/2)] in 0,1,...,NN
ifoddi
ifoddj
stencilptstgp,jx-i-j$p$;
fi
else
%ifevenj
pgfmathsetmacropint(p);
stencilptregp,jx-i-j$p$;
%fi
fi
endtikzpicture
enddocument
conditionals
add a comment |Â
up vote
2
down vote
favorite
Why the following sample fails to compile in pdflatex when ifeven
is used?
It fails with many errors in line 34 (where the last closing brackets are). The errors are like: Undefined control sequence. }
, Extra }, or forgoten endgroup.}
, Extra else.}
, Extra fi }
.
documentclass[tikz]standalone
newcommandstencilptreg[4]node[circle,fill,draw,inner sep=1.5pt,label=below:#4,#1] at (#2) (#3)
newcommandstencilptstg[4]node[circle,fill,white,draw=black,inner sep=1.5pt,label=below:#4,#1] at (#2) (#3)
begindocument
begintikzpicture[x=2cm,y=2cm]
pgfmathsetmacroN5;
pgfmathsetmacroM3;
pgfmathsetmacroNN(N*2); % Number of points in staggered grid
pgfmathsetmacroMM(M*2); % Number of points in staggered grid
foreach j [evaluate=j as q using int(j/2)] in 0,1,...,MM
ifoddj
draw [black!50,thin] (0,j) node[red,left] $n=fracj2$ -- (N,j);
else
draw [black!50,thin] (0,j) node[red,left] $n=q$ -- (N,j);
fi
foreach i [evaluate=i as p using (i/2)] in 0,1,...,NN
ifoddi
ifoddj
stencilptstgp,jx-i-j$p$;
fi
else
%ifevenj
pgfmathsetmacropint(p);
stencilptregp,jx-i-j$p$;
%fi
fi
endtikzpicture
enddocument
conditionals
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
Why the following sample fails to compile in pdflatex when ifeven
is used?
It fails with many errors in line 34 (where the last closing brackets are). The errors are like: Undefined control sequence. }
, Extra }, or forgoten endgroup.}
, Extra else.}
, Extra fi }
.
documentclass[tikz]standalone
newcommandstencilptreg[4]node[circle,fill,draw,inner sep=1.5pt,label=below:#4,#1] at (#2) (#3)
newcommandstencilptstg[4]node[circle,fill,white,draw=black,inner sep=1.5pt,label=below:#4,#1] at (#2) (#3)
begindocument
begintikzpicture[x=2cm,y=2cm]
pgfmathsetmacroN5;
pgfmathsetmacroM3;
pgfmathsetmacroNN(N*2); % Number of points in staggered grid
pgfmathsetmacroMM(M*2); % Number of points in staggered grid
foreach j [evaluate=j as q using int(j/2)] in 0,1,...,MM
ifoddj
draw [black!50,thin] (0,j) node[red,left] $n=fracj2$ -- (N,j);
else
draw [black!50,thin] (0,j) node[red,left] $n=q$ -- (N,j);
fi
foreach i [evaluate=i as p using (i/2)] in 0,1,...,NN
ifoddi
ifoddj
stencilptstgp,jx-i-j$p$;
fi
else
%ifevenj
pgfmathsetmacropint(p);
stencilptregp,jx-i-j$p$;
%fi
fi
endtikzpicture
enddocument
conditionals
Why the following sample fails to compile in pdflatex when ifeven
is used?
It fails with many errors in line 34 (where the last closing brackets are). The errors are like: Undefined control sequence. }
, Extra }, or forgoten endgroup.}
, Extra else.}
, Extra fi }
.
documentclass[tikz]standalone
newcommandstencilptreg[4]node[circle,fill,draw,inner sep=1.5pt,label=below:#4,#1] at (#2) (#3)
newcommandstencilptstg[4]node[circle,fill,white,draw=black,inner sep=1.5pt,label=below:#4,#1] at (#2) (#3)
begindocument
begintikzpicture[x=2cm,y=2cm]
pgfmathsetmacroN5;
pgfmathsetmacroM3;
pgfmathsetmacroNN(N*2); % Number of points in staggered grid
pgfmathsetmacroMM(M*2); % Number of points in staggered grid
foreach j [evaluate=j as q using int(j/2)] in 0,1,...,MM
ifoddj
draw [black!50,thin] (0,j) node[red,left] $n=fracj2$ -- (N,j);
else
draw [black!50,thin] (0,j) node[red,left] $n=q$ -- (N,j);
fi
foreach i [evaluate=i as p using (i/2)] in 0,1,...,NN
ifoddi
ifoddj
stencilptstgp,jx-i-j$p$;
fi
else
%ifevenj
pgfmathsetmacropint(p);
stencilptregp,jx-i-j$p$;
%fi
fi
endtikzpicture
enddocument
conditionals
conditionals
edited 27 mins ago
Werner
427k589361609
427k589361609
asked 38 mins ago
Lin
2747
2747
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
3
down vote
accepted
Because there is no ifeven
. However, it's equivalent to
ifoddjelse
% <ifeven> content
fi
1
Omg, I have read aboutifeven
in SO.
â Lin
29 mins ago
@Lin: See What are the most common mistakes that beginners of (La)TeX and Friends make?
â Werner
24 mins ago
@Lin Most engines nowadays have theunless
primitive, which "reverses" the conditional, soifoddjelse...fi
does the same asunlessifoddj...fi
â Phelype Oleinik
13 mins ago
add a comment |Â
up vote
2
down vote
You should look in the log file for the precise error message, rather than relying on the short tags shown by TeXStudio or other front-ends.
Running your file in batch mode, the first error message is
! Extra }, or forgotten endgroup.
<argument> ...p ,j }x-i -j $p $; fi fi }
l.36 }
Not really clear, but a few lines down you see
! Extra else.
pgffor@collectargument ...pgffor@body #1}else
expandafter long expand...
l.36 }
I'm ignoring this; it doesn't match any if.
! Extra fi.
pgffor@collectargument ...r pgffor@body #1fi
pgffor@iterate
l.36 }
We're getting closer! Let's go down some more:
! Undefined control sequence.
pgffor@body ...i -j }$p $; fi else ifeven
j pgfmathsetmacro p ...
l.36
The control sequence at the end of the top line
of your error message was never def'ed. If you have
misspelled it (e.g., `hobx'), type `I' and the correct
spelling (e.g., `Ihbox'). Otherwise just continue,
and I'll forget about whatever was undefined.
Hey! That's the problem!
TeX has no ifeven
and TikZ doesn't provide it. Actually, it is not possible to define an ifeven
command that works the same as ifodd
just reversing the test.
You can choose between
unlessifoddjrelax
pgfmathsetmacropint(p);
stencilptregp,jx-i-j$p$;
fi
or
ifoddjrelaxelse
pgfmathsetmacropint(p);
stencilptregp,jx-i-j$p$;
fi
I recommend relax
in order not to trigger premature expansions. Not a big deal here, but in other circumstances it could be crucial. However, it's not to be added for any numeric conditionals, particularly in contexts where full expansion is needed.
A safer protection might be
ifoddnumexprjrelaxelse
or
unlessifoddnumexprjrelax
but in this case it would be a waste.
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
Because there is no ifeven
. However, it's equivalent to
ifoddjelse
% <ifeven> content
fi
1
Omg, I have read aboutifeven
in SO.
â Lin
29 mins ago
@Lin: See What are the most common mistakes that beginners of (La)TeX and Friends make?
â Werner
24 mins ago
@Lin Most engines nowadays have theunless
primitive, which "reverses" the conditional, soifoddjelse...fi
does the same asunlessifoddj...fi
â Phelype Oleinik
13 mins ago
add a comment |Â
up vote
3
down vote
accepted
Because there is no ifeven
. However, it's equivalent to
ifoddjelse
% <ifeven> content
fi
1
Omg, I have read aboutifeven
in SO.
â Lin
29 mins ago
@Lin: See What are the most common mistakes that beginners of (La)TeX and Friends make?
â Werner
24 mins ago
@Lin Most engines nowadays have theunless
primitive, which "reverses" the conditional, soifoddjelse...fi
does the same asunlessifoddj...fi
â Phelype Oleinik
13 mins ago
add a comment |Â
up vote
3
down vote
accepted
up vote
3
down vote
accepted
Because there is no ifeven
. However, it's equivalent to
ifoddjelse
% <ifeven> content
fi
Because there is no ifeven
. However, it's equivalent to
ifoddjelse
% <ifeven> content
fi
answered 30 mins ago
Werner
427k589361609
427k589361609
1
Omg, I have read aboutifeven
in SO.
â Lin
29 mins ago
@Lin: See What are the most common mistakes that beginners of (La)TeX and Friends make?
â Werner
24 mins ago
@Lin Most engines nowadays have theunless
primitive, which "reverses" the conditional, soifoddjelse...fi
does the same asunlessifoddj...fi
â Phelype Oleinik
13 mins ago
add a comment |Â
1
Omg, I have read aboutifeven
in SO.
â Lin
29 mins ago
@Lin: See What are the most common mistakes that beginners of (La)TeX and Friends make?
â Werner
24 mins ago
@Lin Most engines nowadays have theunless
primitive, which "reverses" the conditional, soifoddjelse...fi
does the same asunlessifoddj...fi
â Phelype Oleinik
13 mins ago
1
1
Omg, I have read about
ifeven
in SO.â Lin
29 mins ago
Omg, I have read about
ifeven
in SO.â Lin
29 mins ago
@Lin: See What are the most common mistakes that beginners of (La)TeX and Friends make?
â Werner
24 mins ago
@Lin: See What are the most common mistakes that beginners of (La)TeX and Friends make?
â Werner
24 mins ago
@Lin Most engines nowadays have the
unless
primitive, which "reverses" the conditional, so ifoddjelse...fi
does the same as unlessifoddj...fi
â Phelype Oleinik
13 mins ago
@Lin Most engines nowadays have the
unless
primitive, which "reverses" the conditional, so ifoddjelse...fi
does the same as unlessifoddj...fi
â Phelype Oleinik
13 mins ago
add a comment |Â
up vote
2
down vote
You should look in the log file for the precise error message, rather than relying on the short tags shown by TeXStudio or other front-ends.
Running your file in batch mode, the first error message is
! Extra }, or forgotten endgroup.
<argument> ...p ,j }x-i -j $p $; fi fi }
l.36 }
Not really clear, but a few lines down you see
! Extra else.
pgffor@collectargument ...pgffor@body #1}else
expandafter long expand...
l.36 }
I'm ignoring this; it doesn't match any if.
! Extra fi.
pgffor@collectargument ...r pgffor@body #1fi
pgffor@iterate
l.36 }
We're getting closer! Let's go down some more:
! Undefined control sequence.
pgffor@body ...i -j }$p $; fi else ifeven
j pgfmathsetmacro p ...
l.36
The control sequence at the end of the top line
of your error message was never def'ed. If you have
misspelled it (e.g., `hobx'), type `I' and the correct
spelling (e.g., `Ihbox'). Otherwise just continue,
and I'll forget about whatever was undefined.
Hey! That's the problem!
TeX has no ifeven
and TikZ doesn't provide it. Actually, it is not possible to define an ifeven
command that works the same as ifodd
just reversing the test.
You can choose between
unlessifoddjrelax
pgfmathsetmacropint(p);
stencilptregp,jx-i-j$p$;
fi
or
ifoddjrelaxelse
pgfmathsetmacropint(p);
stencilptregp,jx-i-j$p$;
fi
I recommend relax
in order not to trigger premature expansions. Not a big deal here, but in other circumstances it could be crucial. However, it's not to be added for any numeric conditionals, particularly in contexts where full expansion is needed.
A safer protection might be
ifoddnumexprjrelaxelse
or
unlessifoddnumexprjrelax
but in this case it would be a waste.
add a comment |Â
up vote
2
down vote
You should look in the log file for the precise error message, rather than relying on the short tags shown by TeXStudio or other front-ends.
Running your file in batch mode, the first error message is
! Extra }, or forgotten endgroup.
<argument> ...p ,j }x-i -j $p $; fi fi }
l.36 }
Not really clear, but a few lines down you see
! Extra else.
pgffor@collectargument ...pgffor@body #1}else
expandafter long expand...
l.36 }
I'm ignoring this; it doesn't match any if.
! Extra fi.
pgffor@collectargument ...r pgffor@body #1fi
pgffor@iterate
l.36 }
We're getting closer! Let's go down some more:
! Undefined control sequence.
pgffor@body ...i -j }$p $; fi else ifeven
j pgfmathsetmacro p ...
l.36
The control sequence at the end of the top line
of your error message was never def'ed. If you have
misspelled it (e.g., `hobx'), type `I' and the correct
spelling (e.g., `Ihbox'). Otherwise just continue,
and I'll forget about whatever was undefined.
Hey! That's the problem!
TeX has no ifeven
and TikZ doesn't provide it. Actually, it is not possible to define an ifeven
command that works the same as ifodd
just reversing the test.
You can choose between
unlessifoddjrelax
pgfmathsetmacropint(p);
stencilptregp,jx-i-j$p$;
fi
or
ifoddjrelaxelse
pgfmathsetmacropint(p);
stencilptregp,jx-i-j$p$;
fi
I recommend relax
in order not to trigger premature expansions. Not a big deal here, but in other circumstances it could be crucial. However, it's not to be added for any numeric conditionals, particularly in contexts where full expansion is needed.
A safer protection might be
ifoddnumexprjrelaxelse
or
unlessifoddnumexprjrelax
but in this case it would be a waste.
add a comment |Â
up vote
2
down vote
up vote
2
down vote
You should look in the log file for the precise error message, rather than relying on the short tags shown by TeXStudio or other front-ends.
Running your file in batch mode, the first error message is
! Extra }, or forgotten endgroup.
<argument> ...p ,j }x-i -j $p $; fi fi }
l.36 }
Not really clear, but a few lines down you see
! Extra else.
pgffor@collectargument ...pgffor@body #1}else
expandafter long expand...
l.36 }
I'm ignoring this; it doesn't match any if.
! Extra fi.
pgffor@collectargument ...r pgffor@body #1fi
pgffor@iterate
l.36 }
We're getting closer! Let's go down some more:
! Undefined control sequence.
pgffor@body ...i -j }$p $; fi else ifeven
j pgfmathsetmacro p ...
l.36
The control sequence at the end of the top line
of your error message was never def'ed. If you have
misspelled it (e.g., `hobx'), type `I' and the correct
spelling (e.g., `Ihbox'). Otherwise just continue,
and I'll forget about whatever was undefined.
Hey! That's the problem!
TeX has no ifeven
and TikZ doesn't provide it. Actually, it is not possible to define an ifeven
command that works the same as ifodd
just reversing the test.
You can choose between
unlessifoddjrelax
pgfmathsetmacropint(p);
stencilptregp,jx-i-j$p$;
fi
or
ifoddjrelaxelse
pgfmathsetmacropint(p);
stencilptregp,jx-i-j$p$;
fi
I recommend relax
in order not to trigger premature expansions. Not a big deal here, but in other circumstances it could be crucial. However, it's not to be added for any numeric conditionals, particularly in contexts where full expansion is needed.
A safer protection might be
ifoddnumexprjrelaxelse
or
unlessifoddnumexprjrelax
but in this case it would be a waste.
You should look in the log file for the precise error message, rather than relying on the short tags shown by TeXStudio or other front-ends.
Running your file in batch mode, the first error message is
! Extra }, or forgotten endgroup.
<argument> ...p ,j }x-i -j $p $; fi fi }
l.36 }
Not really clear, but a few lines down you see
! Extra else.
pgffor@collectargument ...pgffor@body #1}else
expandafter long expand...
l.36 }
I'm ignoring this; it doesn't match any if.
! Extra fi.
pgffor@collectargument ...r pgffor@body #1fi
pgffor@iterate
l.36 }
We're getting closer! Let's go down some more:
! Undefined control sequence.
pgffor@body ...i -j }$p $; fi else ifeven
j pgfmathsetmacro p ...
l.36
The control sequence at the end of the top line
of your error message was never def'ed. If you have
misspelled it (e.g., `hobx'), type `I' and the correct
spelling (e.g., `Ihbox'). Otherwise just continue,
and I'll forget about whatever was undefined.
Hey! That's the problem!
TeX has no ifeven
and TikZ doesn't provide it. Actually, it is not possible to define an ifeven
command that works the same as ifodd
just reversing the test.
You can choose between
unlessifoddjrelax
pgfmathsetmacropint(p);
stencilptregp,jx-i-j$p$;
fi
or
ifoddjrelaxelse
pgfmathsetmacropint(p);
stencilptregp,jx-i-j$p$;
fi
I recommend relax
in order not to trigger premature expansions. Not a big deal here, but in other circumstances it could be crucial. However, it's not to be added for any numeric conditionals, particularly in contexts where full expansion is needed.
A safer protection might be
ifoddnumexprjrelaxelse
or
unlessifoddnumexprjrelax
but in this case it would be a waste.
answered 14 mins ago
egreg
693k8518443094
693k8518443094
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f457420%2ftikz-ifeven-triggering-error%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password