plain IF structure with one def-ed token and one literal
In some hand-me-down tex i inherited, a control sequence is used as a variable, for instance:
defaccessflavor{ats}
it is used to generate postfixes on included tex files (called, i.e., image01_ats
) and the like.
I want to use it in a conditional structure, i. e. something like
ifaccessflavor ats
This text is only shown if the Flavor of Access is 'ats'.
fi
I tried a a lot of variations, including various brackets, escape sequences and macros, but i cannot get it to work. Mostly, not even an error message appears. The online examples i found either deal with a more specific IF, like ifodd
, ifx
, etc., or more (seemingly) complex cases like testing two macros for identity.
Can somebody clear up the usage for me?
ifthenelse
add a comment |
In some hand-me-down tex i inherited, a control sequence is used as a variable, for instance:
defaccessflavor{ats}
it is used to generate postfixes on included tex files (called, i.e., image01_ats
) and the like.
I want to use it in a conditional structure, i. e. something like
ifaccessflavor ats
This text is only shown if the Flavor of Access is 'ats'.
fi
I tried a a lot of variations, including various brackets, escape sequences and macros, but i cannot get it to work. Mostly, not even an error message appears. The online examples i found either deal with a more specific IF, like ifodd
, ifx
, etc., or more (seemingly) complex cases like testing two macros for identity.
Can somebody clear up the usage for me?
ifthenelse
I can recommend themultiaudience
package which allows you to separate some parts of your text for different "audiences" and provides higher-level switches. As part of this, you can use itsCurrentAudience
variable to get the audience you are currently writing for (e.g. for file names).
– TeXnician
Apr 15 at 14:57
add a comment |
In some hand-me-down tex i inherited, a control sequence is used as a variable, for instance:
defaccessflavor{ats}
it is used to generate postfixes on included tex files (called, i.e., image01_ats
) and the like.
I want to use it in a conditional structure, i. e. something like
ifaccessflavor ats
This text is only shown if the Flavor of Access is 'ats'.
fi
I tried a a lot of variations, including various brackets, escape sequences and macros, but i cannot get it to work. Mostly, not even an error message appears. The online examples i found either deal with a more specific IF, like ifodd
, ifx
, etc., or more (seemingly) complex cases like testing two macros for identity.
Can somebody clear up the usage for me?
ifthenelse
In some hand-me-down tex i inherited, a control sequence is used as a variable, for instance:
defaccessflavor{ats}
it is used to generate postfixes on included tex files (called, i.e., image01_ats
) and the like.
I want to use it in a conditional structure, i. e. something like
ifaccessflavor ats
This text is only shown if the Flavor of Access is 'ats'.
fi
I tried a a lot of variations, including various brackets, escape sequences and macros, but i cannot get it to work. Mostly, not even an error message appears. The online examples i found either deal with a more specific IF, like ifodd
, ifx
, etc., or more (seemingly) complex cases like testing two macros for identity.
Can somebody clear up the usage for me?
ifthenelse
ifthenelse
edited Apr 15 at 15:18
Kurt
41.6k950164
41.6k950164
asked Apr 15 at 14:54
bukwyrmbukwyrm
1212
1212
I can recommend themultiaudience
package which allows you to separate some parts of your text for different "audiences" and provides higher-level switches. As part of this, you can use itsCurrentAudience
variable to get the audience you are currently writing for (e.g. for file names).
– TeXnician
Apr 15 at 14:57
add a comment |
I can recommend themultiaudience
package which allows you to separate some parts of your text for different "audiences" and provides higher-level switches. As part of this, you can use itsCurrentAudience
variable to get the audience you are currently writing for (e.g. for file names).
– TeXnician
Apr 15 at 14:57
I can recommend the
multiaudience
package which allows you to separate some parts of your text for different "audiences" and provides higher-level switches. As part of this, you can use its CurrentAudience
variable to get the audience you are currently writing for (e.g. for file names).– TeXnician
Apr 15 at 14:57
I can recommend the
multiaudience
package which allows you to separate some parts of your text for different "audiences" and provides higher-level switches. As part of this, you can use its CurrentAudience
variable to get the audience you are currently writing for (e.g. for file names).– TeXnician
Apr 15 at 14:57
add a comment |
2 Answers
2
active
oldest
votes
documentclass{article}
defatscomparetoken{ats}
newcommanddomytest{%
ifxatscomparetokenaccessflavor MATCHES atselse DOES NOT MATCH atsfi
}
begin{document}
defaccessflavor{ats}
domytest
defaccessflavor{pdq}
domytest
end{document}
Thank you! Can you explain what is going on? If i understand it correctly, you def-ed atscomparetoken so that the ifx could work on two tokens - is there a reason you packed the whole thing into a command? Also, do you know why one needs the string as an expansion inside a token (for the ifx case it is clear, but why dies if not work?)
– bukwyrm
Apr 15 at 15:22
@bukwyrm Correct, theifx
works on two tokens, and the comparison is whether the substitution text (one level of expansion) for the two tokens matches or not. The problem with trying to do this withif
is thatif
fully expands and then compares the first two tokens; thus,ifaccessflavor ats
expands toif atsats
anda
is compared tot
, with the remainingsats
extraneous.
– Steven B. Segletes
Apr 15 at 15:50
add a comment |
If you want to maintain the if...else...fi
structure, you can use
documentclass{article}
usepackage{pdftexcmds}
makeatletter
newcommandflavor[1]{%
TTfi
ifnumpdf@strcmp{#1}{accessflavor}=z@
}
makeatother
begin{document}
defaccessflavor{ats}
Shown
ifflavor{ats}
This text is only shown if the Flavor of Access is `ats'.
fi
defaccessflavor{notats}
Not shown
ifflavor{ats}
This text is only shown if the Flavor of Access is `ats'.
fi
end{document}
The usage of pdftexcmds
is to obtain engine independence, so the code works with pdftex
, luatex
and xetex
.
The trick is that if
expands tokens.
Note that this can be used inside other conditionals.
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%2f484974%2fplain-if-structure-with-one-def-ed-token-and-one-literal%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
documentclass{article}
defatscomparetoken{ats}
newcommanddomytest{%
ifxatscomparetokenaccessflavor MATCHES atselse DOES NOT MATCH atsfi
}
begin{document}
defaccessflavor{ats}
domytest
defaccessflavor{pdq}
domytest
end{document}
Thank you! Can you explain what is going on? If i understand it correctly, you def-ed atscomparetoken so that the ifx could work on two tokens - is there a reason you packed the whole thing into a command? Also, do you know why one needs the string as an expansion inside a token (for the ifx case it is clear, but why dies if not work?)
– bukwyrm
Apr 15 at 15:22
@bukwyrm Correct, theifx
works on two tokens, and the comparison is whether the substitution text (one level of expansion) for the two tokens matches or not. The problem with trying to do this withif
is thatif
fully expands and then compares the first two tokens; thus,ifaccessflavor ats
expands toif atsats
anda
is compared tot
, with the remainingsats
extraneous.
– Steven B. Segletes
Apr 15 at 15:50
add a comment |
documentclass{article}
defatscomparetoken{ats}
newcommanddomytest{%
ifxatscomparetokenaccessflavor MATCHES atselse DOES NOT MATCH atsfi
}
begin{document}
defaccessflavor{ats}
domytest
defaccessflavor{pdq}
domytest
end{document}
Thank you! Can you explain what is going on? If i understand it correctly, you def-ed atscomparetoken so that the ifx could work on two tokens - is there a reason you packed the whole thing into a command? Also, do you know why one needs the string as an expansion inside a token (for the ifx case it is clear, but why dies if not work?)
– bukwyrm
Apr 15 at 15:22
@bukwyrm Correct, theifx
works on two tokens, and the comparison is whether the substitution text (one level of expansion) for the two tokens matches or not. The problem with trying to do this withif
is thatif
fully expands and then compares the first two tokens; thus,ifaccessflavor ats
expands toif atsats
anda
is compared tot
, with the remainingsats
extraneous.
– Steven B. Segletes
Apr 15 at 15:50
add a comment |
documentclass{article}
defatscomparetoken{ats}
newcommanddomytest{%
ifxatscomparetokenaccessflavor MATCHES atselse DOES NOT MATCH atsfi
}
begin{document}
defaccessflavor{ats}
domytest
defaccessflavor{pdq}
domytest
end{document}
documentclass{article}
defatscomparetoken{ats}
newcommanddomytest{%
ifxatscomparetokenaccessflavor MATCHES atselse DOES NOT MATCH atsfi
}
begin{document}
defaccessflavor{ats}
domytest
defaccessflavor{pdq}
domytest
end{document}
answered Apr 15 at 15:01
Steven B. SegletesSteven B. Segletes
163k9207419
163k9207419
Thank you! Can you explain what is going on? If i understand it correctly, you def-ed atscomparetoken so that the ifx could work on two tokens - is there a reason you packed the whole thing into a command? Also, do you know why one needs the string as an expansion inside a token (for the ifx case it is clear, but why dies if not work?)
– bukwyrm
Apr 15 at 15:22
@bukwyrm Correct, theifx
works on two tokens, and the comparison is whether the substitution text (one level of expansion) for the two tokens matches or not. The problem with trying to do this withif
is thatif
fully expands and then compares the first two tokens; thus,ifaccessflavor ats
expands toif atsats
anda
is compared tot
, with the remainingsats
extraneous.
– Steven B. Segletes
Apr 15 at 15:50
add a comment |
Thank you! Can you explain what is going on? If i understand it correctly, you def-ed atscomparetoken so that the ifx could work on two tokens - is there a reason you packed the whole thing into a command? Also, do you know why one needs the string as an expansion inside a token (for the ifx case it is clear, but why dies if not work?)
– bukwyrm
Apr 15 at 15:22
@bukwyrm Correct, theifx
works on two tokens, and the comparison is whether the substitution text (one level of expansion) for the two tokens matches or not. The problem with trying to do this withif
is thatif
fully expands and then compares the first two tokens; thus,ifaccessflavor ats
expands toif atsats
anda
is compared tot
, with the remainingsats
extraneous.
– Steven B. Segletes
Apr 15 at 15:50
Thank you! Can you explain what is going on? If i understand it correctly, you def-ed atscomparetoken so that the ifx could work on two tokens - is there a reason you packed the whole thing into a command? Also, do you know why one needs the string as an expansion inside a token (for the ifx case it is clear, but why dies if not work?)
– bukwyrm
Apr 15 at 15:22
Thank you! Can you explain what is going on? If i understand it correctly, you def-ed atscomparetoken so that the ifx could work on two tokens - is there a reason you packed the whole thing into a command? Also, do you know why one needs the string as an expansion inside a token (for the ifx case it is clear, but why dies if not work?)
– bukwyrm
Apr 15 at 15:22
@bukwyrm Correct, the
ifx
works on two tokens, and the comparison is whether the substitution text (one level of expansion) for the two tokens matches or not. The problem with trying to do this with if
is that if
fully expands and then compares the first two tokens; thus, ifaccessflavor ats
expands to if atsats
and a
is compared to t
, with the remaining sats
extraneous.– Steven B. Segletes
Apr 15 at 15:50
@bukwyrm Correct, the
ifx
works on two tokens, and the comparison is whether the substitution text (one level of expansion) for the two tokens matches or not. The problem with trying to do this with if
is that if
fully expands and then compares the first two tokens; thus, ifaccessflavor ats
expands to if atsats
and a
is compared to t
, with the remaining sats
extraneous.– Steven B. Segletes
Apr 15 at 15:50
add a comment |
If you want to maintain the if...else...fi
structure, you can use
documentclass{article}
usepackage{pdftexcmds}
makeatletter
newcommandflavor[1]{%
TTfi
ifnumpdf@strcmp{#1}{accessflavor}=z@
}
makeatother
begin{document}
defaccessflavor{ats}
Shown
ifflavor{ats}
This text is only shown if the Flavor of Access is `ats'.
fi
defaccessflavor{notats}
Not shown
ifflavor{ats}
This text is only shown if the Flavor of Access is `ats'.
fi
end{document}
The usage of pdftexcmds
is to obtain engine independence, so the code works with pdftex
, luatex
and xetex
.
The trick is that if
expands tokens.
Note that this can be used inside other conditionals.
add a comment |
If you want to maintain the if...else...fi
structure, you can use
documentclass{article}
usepackage{pdftexcmds}
makeatletter
newcommandflavor[1]{%
TTfi
ifnumpdf@strcmp{#1}{accessflavor}=z@
}
makeatother
begin{document}
defaccessflavor{ats}
Shown
ifflavor{ats}
This text is only shown if the Flavor of Access is `ats'.
fi
defaccessflavor{notats}
Not shown
ifflavor{ats}
This text is only shown if the Flavor of Access is `ats'.
fi
end{document}
The usage of pdftexcmds
is to obtain engine independence, so the code works with pdftex
, luatex
and xetex
.
The trick is that if
expands tokens.
Note that this can be used inside other conditionals.
add a comment |
If you want to maintain the if...else...fi
structure, you can use
documentclass{article}
usepackage{pdftexcmds}
makeatletter
newcommandflavor[1]{%
TTfi
ifnumpdf@strcmp{#1}{accessflavor}=z@
}
makeatother
begin{document}
defaccessflavor{ats}
Shown
ifflavor{ats}
This text is only shown if the Flavor of Access is `ats'.
fi
defaccessflavor{notats}
Not shown
ifflavor{ats}
This text is only shown if the Flavor of Access is `ats'.
fi
end{document}
The usage of pdftexcmds
is to obtain engine independence, so the code works with pdftex
, luatex
and xetex
.
The trick is that if
expands tokens.
Note that this can be used inside other conditionals.
If you want to maintain the if...else...fi
structure, you can use
documentclass{article}
usepackage{pdftexcmds}
makeatletter
newcommandflavor[1]{%
TTfi
ifnumpdf@strcmp{#1}{accessflavor}=z@
}
makeatother
begin{document}
defaccessflavor{ats}
Shown
ifflavor{ats}
This text is only shown if the Flavor of Access is `ats'.
fi
defaccessflavor{notats}
Not shown
ifflavor{ats}
This text is only shown if the Flavor of Access is `ats'.
fi
end{document}
The usage of pdftexcmds
is to obtain engine independence, so the code works with pdftex
, luatex
and xetex
.
The trick is that if
expands tokens.
Note that this can be used inside other conditionals.
answered Apr 15 at 15:29
egregegreg
735k8919343260
735k8919343260
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%2f484974%2fplain-if-structure-with-one-def-ed-token-and-one-literal%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
I can recommend the
multiaudience
package which allows you to separate some parts of your text for different "audiences" and provides higher-level switches. As part of this, you can use itsCurrentAudience
variable to get the audience you are currently writing for (e.g. for file names).– TeXnician
Apr 15 at 14:57