Expand `ifthenelse` immediately
Consider this script:
documentclass{report}
usepackage{ifthen}
newcommand{thesissize}{SHORT}
begin{document}
setcounter{page}{
%3
ifthenelse{
equal{thesissize}{SHORT}
}{3}{2}
}
hey
end{document}
Compiling this script gives the error:
! Missing number, treated as zero.
I suspect that this is due to ifthenelse
not being evaluated at the time of executing setcounter
. How do I solve this?
macros ifthenelse
add a comment |
Consider this script:
documentclass{report}
usepackage{ifthen}
newcommand{thesissize}{SHORT}
begin{document}
setcounter{page}{
%3
ifthenelse{
equal{thesissize}{SHORT}
}{3}{2}
}
hey
end{document}
Compiling this script gives the error:
! Missing number, treated as zero.
I suspect that this is due to ifthenelse
not being evaluated at the time of executing setcounter
. How do I solve this?
macros ifthenelse
add a comment |
Consider this script:
documentclass{report}
usepackage{ifthen}
newcommand{thesissize}{SHORT}
begin{document}
setcounter{page}{
%3
ifthenelse{
equal{thesissize}{SHORT}
}{3}{2}
}
hey
end{document}
Compiling this script gives the error:
! Missing number, treated as zero.
I suspect that this is due to ifthenelse
not being evaluated at the time of executing setcounter
. How do I solve this?
macros ifthenelse
Consider this script:
documentclass{report}
usepackage{ifthen}
newcommand{thesissize}{SHORT}
begin{document}
setcounter{page}{
%3
ifthenelse{
equal{thesissize}{SHORT}
}{3}{2}
}
hey
end{document}
Compiling this script gives the error:
! Missing number, treated as zero.
I suspect that this is due to ifthenelse
not being evaluated at the time of executing setcounter
. How do I solve this?
macros ifthenelse
macros ifthenelse
edited 2 hours ago
Peter Mortensen
54637
54637
asked 13 hours ago
ViestursViesturs
1,93141127
1,93141127
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
you can't use ifthenelse
inside setcounter
. Change the order:
documentclass{report}
usepackage{ifthen}
newcommand{thesissize}{SHORT}
begin{document}
ifthenelse{equal{thesissize}{SHORT}}
{setcounter{page}{3}}{setcounter{page}{2}}
hey
end{document}
Expandable tests are possible with expl3
and etoolbox
. For both you should store the reference text in a command:
documentclass{report}
usepackage{expl3,etoolbox}
newcommand{thesissize}{SHORT}
newcommand{shortsize}{SHORT}
begin{document}
ExplSyntaxOn
setcounter{page}{tl_if_eq:NNTFthesissizeshortsize{3}{2}}
ExplSyntaxOff
setcounter{page}{ifdefequal{thesissize}{shortsize}{3}{2}}
hey
end{document}
What is the reason?
– Viesturs
13 hours ago
6
ifthenelse is not expandable.
– Ulrike Fischer
13 hours ago
1
I added two more versions.
– Ulrike Fischer
12 hours ago
add a comment |
Another version of a string comparison using the pdfTeX macro pdfstrcmp
. The following uses the pdftexcmds
package to make it available to all engines under the same name:
documentclass{article}
usepackage{pdftexcmds}
makeatletter
newcommandifstreq[2]
{%
ifnumpdf@strcmp{#1}{#2}=0
}
makeatother
newcommandthesissize{SHORT}
begin{document}
setcounter{page}{ifstreq{thesissize}{SHORT}3else2fi}
hey
end{document}
add a comment |
No packages.
documentclass{report}
newcommand{thesissize}{SHORT}
begin{document}
newcommandtmp{SHORT}
ifxtmpthesissizerelaxsetcounter{page}{3}elsesetcounter{page}{2}fi
thepage
renewcommandtmp{NOT SHORT}
ifxtmpthesissizerelaxsetcounter{page}{3}elsesetcounter{page}{2}fi
thepage
end{document}
The expandable version:
documentclass{report}
newcommand{thesissize}{SHORT}
begin{document}
newcommandtmp{SHORT}
setcounter{page}{ifxtmpthesissize3else2fi}
thepage
renewcommandtmp{NOT SHORT}
setcounter{page}{ifxtmpthesissize3else2fi}
thepage
end{document}
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "85"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
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
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f483347%2fexpand-ifthenelse-immediately%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
you can't use ifthenelse
inside setcounter
. Change the order:
documentclass{report}
usepackage{ifthen}
newcommand{thesissize}{SHORT}
begin{document}
ifthenelse{equal{thesissize}{SHORT}}
{setcounter{page}{3}}{setcounter{page}{2}}
hey
end{document}
Expandable tests are possible with expl3
and etoolbox
. For both you should store the reference text in a command:
documentclass{report}
usepackage{expl3,etoolbox}
newcommand{thesissize}{SHORT}
newcommand{shortsize}{SHORT}
begin{document}
ExplSyntaxOn
setcounter{page}{tl_if_eq:NNTFthesissizeshortsize{3}{2}}
ExplSyntaxOff
setcounter{page}{ifdefequal{thesissize}{shortsize}{3}{2}}
hey
end{document}
What is the reason?
– Viesturs
13 hours ago
6
ifthenelse is not expandable.
– Ulrike Fischer
13 hours ago
1
I added two more versions.
– Ulrike Fischer
12 hours ago
add a comment |
you can't use ifthenelse
inside setcounter
. Change the order:
documentclass{report}
usepackage{ifthen}
newcommand{thesissize}{SHORT}
begin{document}
ifthenelse{equal{thesissize}{SHORT}}
{setcounter{page}{3}}{setcounter{page}{2}}
hey
end{document}
Expandable tests are possible with expl3
and etoolbox
. For both you should store the reference text in a command:
documentclass{report}
usepackage{expl3,etoolbox}
newcommand{thesissize}{SHORT}
newcommand{shortsize}{SHORT}
begin{document}
ExplSyntaxOn
setcounter{page}{tl_if_eq:NNTFthesissizeshortsize{3}{2}}
ExplSyntaxOff
setcounter{page}{ifdefequal{thesissize}{shortsize}{3}{2}}
hey
end{document}
What is the reason?
– Viesturs
13 hours ago
6
ifthenelse is not expandable.
– Ulrike Fischer
13 hours ago
1
I added two more versions.
– Ulrike Fischer
12 hours ago
add a comment |
you can't use ifthenelse
inside setcounter
. Change the order:
documentclass{report}
usepackage{ifthen}
newcommand{thesissize}{SHORT}
begin{document}
ifthenelse{equal{thesissize}{SHORT}}
{setcounter{page}{3}}{setcounter{page}{2}}
hey
end{document}
Expandable tests are possible with expl3
and etoolbox
. For both you should store the reference text in a command:
documentclass{report}
usepackage{expl3,etoolbox}
newcommand{thesissize}{SHORT}
newcommand{shortsize}{SHORT}
begin{document}
ExplSyntaxOn
setcounter{page}{tl_if_eq:NNTFthesissizeshortsize{3}{2}}
ExplSyntaxOff
setcounter{page}{ifdefequal{thesissize}{shortsize}{3}{2}}
hey
end{document}
you can't use ifthenelse
inside setcounter
. Change the order:
documentclass{report}
usepackage{ifthen}
newcommand{thesissize}{SHORT}
begin{document}
ifthenelse{equal{thesissize}{SHORT}}
{setcounter{page}{3}}{setcounter{page}{2}}
hey
end{document}
Expandable tests are possible with expl3
and etoolbox
. For both you should store the reference text in a command:
documentclass{report}
usepackage{expl3,etoolbox}
newcommand{thesissize}{SHORT}
newcommand{shortsize}{SHORT}
begin{document}
ExplSyntaxOn
setcounter{page}{tl_if_eq:NNTFthesissizeshortsize{3}{2}}
ExplSyntaxOff
setcounter{page}{ifdefequal{thesissize}{shortsize}{3}{2}}
hey
end{document}
edited 12 hours ago
Andrew Swann
78k9132332
78k9132332
answered 13 hours ago
Ulrike FischerUlrike Fischer
198k9305692
198k9305692
What is the reason?
– Viesturs
13 hours ago
6
ifthenelse is not expandable.
– Ulrike Fischer
13 hours ago
1
I added two more versions.
– Ulrike Fischer
12 hours ago
add a comment |
What is the reason?
– Viesturs
13 hours ago
6
ifthenelse is not expandable.
– Ulrike Fischer
13 hours ago
1
I added two more versions.
– Ulrike Fischer
12 hours ago
What is the reason?
– Viesturs
13 hours ago
What is the reason?
– Viesturs
13 hours ago
6
6
ifthenelse is not expandable.
– Ulrike Fischer
13 hours ago
ifthenelse is not expandable.
– Ulrike Fischer
13 hours ago
1
1
I added two more versions.
– Ulrike Fischer
12 hours ago
I added two more versions.
– Ulrike Fischer
12 hours ago
add a comment |
Another version of a string comparison using the pdfTeX macro pdfstrcmp
. The following uses the pdftexcmds
package to make it available to all engines under the same name:
documentclass{article}
usepackage{pdftexcmds}
makeatletter
newcommandifstreq[2]
{%
ifnumpdf@strcmp{#1}{#2}=0
}
makeatother
newcommandthesissize{SHORT}
begin{document}
setcounter{page}{ifstreq{thesissize}{SHORT}3else2fi}
hey
end{document}
add a comment |
Another version of a string comparison using the pdfTeX macro pdfstrcmp
. The following uses the pdftexcmds
package to make it available to all engines under the same name:
documentclass{article}
usepackage{pdftexcmds}
makeatletter
newcommandifstreq[2]
{%
ifnumpdf@strcmp{#1}{#2}=0
}
makeatother
newcommandthesissize{SHORT}
begin{document}
setcounter{page}{ifstreq{thesissize}{SHORT}3else2fi}
hey
end{document}
add a comment |
Another version of a string comparison using the pdfTeX macro pdfstrcmp
. The following uses the pdftexcmds
package to make it available to all engines under the same name:
documentclass{article}
usepackage{pdftexcmds}
makeatletter
newcommandifstreq[2]
{%
ifnumpdf@strcmp{#1}{#2}=0
}
makeatother
newcommandthesissize{SHORT}
begin{document}
setcounter{page}{ifstreq{thesissize}{SHORT}3else2fi}
hey
end{document}
Another version of a string comparison using the pdfTeX macro pdfstrcmp
. The following uses the pdftexcmds
package to make it available to all engines under the same name:
documentclass{article}
usepackage{pdftexcmds}
makeatletter
newcommandifstreq[2]
{%
ifnumpdf@strcmp{#1}{#2}=0
}
makeatother
newcommandthesissize{SHORT}
begin{document}
setcounter{page}{ifstreq{thesissize}{SHORT}3else2fi}
hey
end{document}
answered 8 hours ago
SkillmonSkillmon
24.2k12250
24.2k12250
add a comment |
add a comment |
No packages.
documentclass{report}
newcommand{thesissize}{SHORT}
begin{document}
newcommandtmp{SHORT}
ifxtmpthesissizerelaxsetcounter{page}{3}elsesetcounter{page}{2}fi
thepage
renewcommandtmp{NOT SHORT}
ifxtmpthesissizerelaxsetcounter{page}{3}elsesetcounter{page}{2}fi
thepage
end{document}
The expandable version:
documentclass{report}
newcommand{thesissize}{SHORT}
begin{document}
newcommandtmp{SHORT}
setcounter{page}{ifxtmpthesissize3else2fi}
thepage
renewcommandtmp{NOT SHORT}
setcounter{page}{ifxtmpthesissize3else2fi}
thepage
end{document}
add a comment |
No packages.
documentclass{report}
newcommand{thesissize}{SHORT}
begin{document}
newcommandtmp{SHORT}
ifxtmpthesissizerelaxsetcounter{page}{3}elsesetcounter{page}{2}fi
thepage
renewcommandtmp{NOT SHORT}
ifxtmpthesissizerelaxsetcounter{page}{3}elsesetcounter{page}{2}fi
thepage
end{document}
The expandable version:
documentclass{report}
newcommand{thesissize}{SHORT}
begin{document}
newcommandtmp{SHORT}
setcounter{page}{ifxtmpthesissize3else2fi}
thepage
renewcommandtmp{NOT SHORT}
setcounter{page}{ifxtmpthesissize3else2fi}
thepage
end{document}
add a comment |
No packages.
documentclass{report}
newcommand{thesissize}{SHORT}
begin{document}
newcommandtmp{SHORT}
ifxtmpthesissizerelaxsetcounter{page}{3}elsesetcounter{page}{2}fi
thepage
renewcommandtmp{NOT SHORT}
ifxtmpthesissizerelaxsetcounter{page}{3}elsesetcounter{page}{2}fi
thepage
end{document}
The expandable version:
documentclass{report}
newcommand{thesissize}{SHORT}
begin{document}
newcommandtmp{SHORT}
setcounter{page}{ifxtmpthesissize3else2fi}
thepage
renewcommandtmp{NOT SHORT}
setcounter{page}{ifxtmpthesissize3else2fi}
thepage
end{document}
No packages.
documentclass{report}
newcommand{thesissize}{SHORT}
begin{document}
newcommandtmp{SHORT}
ifxtmpthesissizerelaxsetcounter{page}{3}elsesetcounter{page}{2}fi
thepage
renewcommandtmp{NOT SHORT}
ifxtmpthesissizerelaxsetcounter{page}{3}elsesetcounter{page}{2}fi
thepage
end{document}
The expandable version:
documentclass{report}
newcommand{thesissize}{SHORT}
begin{document}
newcommandtmp{SHORT}
setcounter{page}{ifxtmpthesissize3else2fi}
thepage
renewcommandtmp{NOT SHORT}
setcounter{page}{ifxtmpthesissize3else2fi}
thepage
end{document}
edited 1 hour ago
answered 1 hour ago
Steven B. SegletesSteven B. Segletes
161k9205416
161k9205416
add a comment |
add a comment |
Thanks for contributing an answer to TeX - LaTeX Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f483347%2fexpand-ifthenelse-immediately%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown