@nameuse as conditional
Please consider the following, non-working, example:
documentclass{standalone}
makeatletter
parindentz@
@namedef{blafasel}{foo}
deffoo{foo}
defbar{bar}
makeatother
begin{document}
1:
expandafterifx@nameuse{blafasel}foo
message{true}
else
message{false}
fi
2:
expandafterifx@nameuse{blafasel}bar
message{true}
else
message{false}
fi
end{document}
How must I alter this code so that the output is "correct" (1: truen2: false
)? So far, I tried up to 9 expandafter
before ifx
, but none gave me the desired output. Why is that?
EDIT
Okay, my mistake was that @ wasn't a letter anymore... Using three expandafters
did the trick. Nonetheless i'd like to know what happens here. How does LaTeX expand @namedef and @nameuse resp.? Extending the example by the following code also gives weired results:
3:
expandafterifxcsname blafaselendcsnamebar
true
else
false
fi
4:
expandafterifxcsname blafaselendcsnamebar
true
else
false
fi
tex-core conditionals
add a comment |
Please consider the following, non-working, example:
documentclass{standalone}
makeatletter
parindentz@
@namedef{blafasel}{foo}
deffoo{foo}
defbar{bar}
makeatother
begin{document}
1:
expandafterifx@nameuse{blafasel}foo
message{true}
else
message{false}
fi
2:
expandafterifx@nameuse{blafasel}bar
message{true}
else
message{false}
fi
end{document}
How must I alter this code so that the output is "correct" (1: truen2: false
)? So far, I tried up to 9 expandafter
before ifx
, but none gave me the desired output. Why is that?
EDIT
Okay, my mistake was that @ wasn't a letter anymore... Using three expandafters
did the trick. Nonetheless i'd like to know what happens here. How does LaTeX expand @namedef and @nameuse resp.? Extending the example by the following code also gives weired results:
3:
expandafterifxcsname blafaselendcsnamebar
true
else
false
fi
4:
expandafterifxcsname blafaselendcsnamebar
true
else
false
fi
tex-core conditionals
I'd useetoolbox
'sifcsequal{<csname one>}{<csname two>}{<true>}{<false>}
– moewe
Jan 24 at 11:37
Yea, thanks all, i noticed my mistake as soon as i clicked "submit"... I added a "follow up" to the question, see edit above. Using(end)csname
gave me twice "false" for some reason...
– Lupino
Jan 24 at 11:41
2
If you usefoo
in 3, then you'll gettrue
. You're gettingfalse
twice because you're doing the same test.
– egreg
Jan 24 at 11:43
@egreg and all: m( i'm so sorry
– Lupino
Jan 24 at 11:45
add a comment |
Please consider the following, non-working, example:
documentclass{standalone}
makeatletter
parindentz@
@namedef{blafasel}{foo}
deffoo{foo}
defbar{bar}
makeatother
begin{document}
1:
expandafterifx@nameuse{blafasel}foo
message{true}
else
message{false}
fi
2:
expandafterifx@nameuse{blafasel}bar
message{true}
else
message{false}
fi
end{document}
How must I alter this code so that the output is "correct" (1: truen2: false
)? So far, I tried up to 9 expandafter
before ifx
, but none gave me the desired output. Why is that?
EDIT
Okay, my mistake was that @ wasn't a letter anymore... Using three expandafters
did the trick. Nonetheless i'd like to know what happens here. How does LaTeX expand @namedef and @nameuse resp.? Extending the example by the following code also gives weired results:
3:
expandafterifxcsname blafaselendcsnamebar
true
else
false
fi
4:
expandafterifxcsname blafaselendcsnamebar
true
else
false
fi
tex-core conditionals
Please consider the following, non-working, example:
documentclass{standalone}
makeatletter
parindentz@
@namedef{blafasel}{foo}
deffoo{foo}
defbar{bar}
makeatother
begin{document}
1:
expandafterifx@nameuse{blafasel}foo
message{true}
else
message{false}
fi
2:
expandafterifx@nameuse{blafasel}bar
message{true}
else
message{false}
fi
end{document}
How must I alter this code so that the output is "correct" (1: truen2: false
)? So far, I tried up to 9 expandafter
before ifx
, but none gave me the desired output. Why is that?
EDIT
Okay, my mistake was that @ wasn't a letter anymore... Using three expandafters
did the trick. Nonetheless i'd like to know what happens here. How does LaTeX expand @namedef and @nameuse resp.? Extending the example by the following code also gives weired results:
3:
expandafterifxcsname blafaselendcsnamebar
true
else
false
fi
4:
expandafterifxcsname blafaselendcsnamebar
true
else
false
fi
tex-core conditionals
tex-core conditionals
edited Jan 24 at 11:39
Lupino
asked Jan 24 at 11:32
LupinoLupino
1,176610
1,176610
I'd useetoolbox
'sifcsequal{<csname one>}{<csname two>}{<true>}{<false>}
– moewe
Jan 24 at 11:37
Yea, thanks all, i noticed my mistake as soon as i clicked "submit"... I added a "follow up" to the question, see edit above. Using(end)csname
gave me twice "false" for some reason...
– Lupino
Jan 24 at 11:41
2
If you usefoo
in 3, then you'll gettrue
. You're gettingfalse
twice because you're doing the same test.
– egreg
Jan 24 at 11:43
@egreg and all: m( i'm so sorry
– Lupino
Jan 24 at 11:45
add a comment |
I'd useetoolbox
'sifcsequal{<csname one>}{<csname two>}{<true>}{<false>}
– moewe
Jan 24 at 11:37
Yea, thanks all, i noticed my mistake as soon as i clicked "submit"... I added a "follow up" to the question, see edit above. Using(end)csname
gave me twice "false" for some reason...
– Lupino
Jan 24 at 11:41
2
If you usefoo
in 3, then you'll gettrue
. You're gettingfalse
twice because you're doing the same test.
– egreg
Jan 24 at 11:43
@egreg and all: m( i'm so sorry
– Lupino
Jan 24 at 11:45
I'd use
etoolbox
's ifcsequal{<csname one>}{<csname two>}{<true>}{<false>}
– moewe
Jan 24 at 11:37
I'd use
etoolbox
's ifcsequal{<csname one>}{<csname two>}{<true>}{<false>}
– moewe
Jan 24 at 11:37
Yea, thanks all, i noticed my mistake as soon as i clicked "submit"... I added a "follow up" to the question, see edit above. Using
(end)csname
gave me twice "false" for some reason...– Lupino
Jan 24 at 11:41
Yea, thanks all, i noticed my mistake as soon as i clicked "submit"... I added a "follow up" to the question, see edit above. Using
(end)csname
gave me twice "false" for some reason...– Lupino
Jan 24 at 11:41
2
2
If you use
foo
in 3, then you'll get true
. You're getting false
twice because you're doing the same test.– egreg
Jan 24 at 11:43
If you use
foo
in 3, then you'll get true
. You're getting false
twice because you're doing the same test.– egreg
Jan 24 at 11:43
@egreg and all: m( i'm so sorry
– Lupino
Jan 24 at 11:45
@egreg and all: m( i'm so sorry
– Lupino
Jan 24 at 11:45
add a comment |
2 Answers
2
active
oldest
votes
You're almost there. Two problems only.
First, @nameuse
contains an @
in the name, so you need to makeatletter
before using it.
Second, if you show@nameuse
(after a makeatletter
, of course) you see:
> @nameuse=macro:
#1->csname #1endcsname
so one expansion of @nameuse{foo}
yields csname blafaselendcsname
. The csname
...endcsname
requires another expansion to make blafasel
, which is what you want. So now you know you need two expansions of @nameuse
.
With
expandafterifx@nameuse{blafasel}foo
you expand it once. To expand twice you need one more expandafter
before each token that precedes @nameuse
. That is, one expandafter
for the "old" expandafter
, and another for the ifx
:
expandafterexpandafterexpandafterifx@nameuse{blafasel}foo
Now the code:
documentclass{standalone}
makeatletter
parindentz@
@namedef{blafasel}{foo}
deffoo{foo}
defbar{bar}
makeatother
begin{document}
1:
makeatletter
expandafterexpandafterexpandafterifx@nameuse{blafasel}foo
message{true}
else
message{false}
fi
2:
expandafterexpandafterexpandafterifx@nameuse{blafasel}bar
message{true}
else
message{false}
fi
end{document}
prints true false
somewhere in the terminal.
thank you, i'm going to accept the answer because it answers the OP. Unfortunately, in my "real" code, which is an xmltex project, this doesn't work. TeX complains about anExtra else
with this construction.
– Lupino
Jan 24 at 11:50
I found the difference: In my "real" code i usedrelax
instead offoo
or {foo}. This gives me "false" twice
– Lupino
Jan 24 at 11:56
@Lupino I'd need to see the code... TheExtra else
shouldn't appear even if you replacefoo
byrelax
.ifx
compares the meaning of two tokens without expanding them previously, sorelax
is valid. Of course the comparison will only be true if both tokens expand torelax
, for instance this code first yieldsfoo is NOT relax
because, obviously,foo
is notrelax
, it only containsrelax
in its definition. The second comparison yieldsfoo is relax
because you makefoo
an exact copy ofrelax
.
– Phelype Oleinik
Jan 24 at 12:16
add a comment |
You need to expand two levels, so expandafterexpandafterexpandafter
, besides making @
a letter in order to avoid TeX compare the first two tokens in the expansion of @
(precisely, spacefactor
and @m
).
A single expandafter
is sufficient with expandafterifxcsname blafaselendcsnamefoo
.
There are simpler ways to compare macros expanding to strings of characters, the simplest one being
ifnumpdfstrcmp{@nameuse{blafadel}}{foo}=0
true
else
false
fi
that doesn't need to define foo
. Since pdfstrcmp
is available with different names in other engines, it's best to do
usepackage{pdftexcmds}
and use pdf@strcmp
.
Much more powerful string comparison functions are available with expl3
.
Thanks for the answer. Is that package bound to pdflatex? If so, i cant use it. Dvi output only...
– Lupino
Jan 24 at 12:02
@Lupino No, you can useexpl3
with any of the major engines (pdfTeX, XeTeX, LuaTeX, (u)pTeX) and it doesn't depend on the format being used, so you can use with plain, LaTeX, ConTeXt or basically any other format. It won't work in Knuth's TeX though, because it requires ε-TeX extensions.
– Phelype Oleinik
Jan 24 at 12:20
Since we are using Texlive2017 this should be fine. I will have a look at it, maybe i find something useful in there. Thanks for the advice :) .
– Lupino
Jan 24 at 14:55
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%2f471625%2fnameuse-as-conditional%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
You're almost there. Two problems only.
First, @nameuse
contains an @
in the name, so you need to makeatletter
before using it.
Second, if you show@nameuse
(after a makeatletter
, of course) you see:
> @nameuse=macro:
#1->csname #1endcsname
so one expansion of @nameuse{foo}
yields csname blafaselendcsname
. The csname
...endcsname
requires another expansion to make blafasel
, which is what you want. So now you know you need two expansions of @nameuse
.
With
expandafterifx@nameuse{blafasel}foo
you expand it once. To expand twice you need one more expandafter
before each token that precedes @nameuse
. That is, one expandafter
for the "old" expandafter
, and another for the ifx
:
expandafterexpandafterexpandafterifx@nameuse{blafasel}foo
Now the code:
documentclass{standalone}
makeatletter
parindentz@
@namedef{blafasel}{foo}
deffoo{foo}
defbar{bar}
makeatother
begin{document}
1:
makeatletter
expandafterexpandafterexpandafterifx@nameuse{blafasel}foo
message{true}
else
message{false}
fi
2:
expandafterexpandafterexpandafterifx@nameuse{blafasel}bar
message{true}
else
message{false}
fi
end{document}
prints true false
somewhere in the terminal.
thank you, i'm going to accept the answer because it answers the OP. Unfortunately, in my "real" code, which is an xmltex project, this doesn't work. TeX complains about anExtra else
with this construction.
– Lupino
Jan 24 at 11:50
I found the difference: In my "real" code i usedrelax
instead offoo
or {foo}. This gives me "false" twice
– Lupino
Jan 24 at 11:56
@Lupino I'd need to see the code... TheExtra else
shouldn't appear even if you replacefoo
byrelax
.ifx
compares the meaning of two tokens without expanding them previously, sorelax
is valid. Of course the comparison will only be true if both tokens expand torelax
, for instance this code first yieldsfoo is NOT relax
because, obviously,foo
is notrelax
, it only containsrelax
in its definition. The second comparison yieldsfoo is relax
because you makefoo
an exact copy ofrelax
.
– Phelype Oleinik
Jan 24 at 12:16
add a comment |
You're almost there. Two problems only.
First, @nameuse
contains an @
in the name, so you need to makeatletter
before using it.
Second, if you show@nameuse
(after a makeatletter
, of course) you see:
> @nameuse=macro:
#1->csname #1endcsname
so one expansion of @nameuse{foo}
yields csname blafaselendcsname
. The csname
...endcsname
requires another expansion to make blafasel
, which is what you want. So now you know you need two expansions of @nameuse
.
With
expandafterifx@nameuse{blafasel}foo
you expand it once. To expand twice you need one more expandafter
before each token that precedes @nameuse
. That is, one expandafter
for the "old" expandafter
, and another for the ifx
:
expandafterexpandafterexpandafterifx@nameuse{blafasel}foo
Now the code:
documentclass{standalone}
makeatletter
parindentz@
@namedef{blafasel}{foo}
deffoo{foo}
defbar{bar}
makeatother
begin{document}
1:
makeatletter
expandafterexpandafterexpandafterifx@nameuse{blafasel}foo
message{true}
else
message{false}
fi
2:
expandafterexpandafterexpandafterifx@nameuse{blafasel}bar
message{true}
else
message{false}
fi
end{document}
prints true false
somewhere in the terminal.
thank you, i'm going to accept the answer because it answers the OP. Unfortunately, in my "real" code, which is an xmltex project, this doesn't work. TeX complains about anExtra else
with this construction.
– Lupino
Jan 24 at 11:50
I found the difference: In my "real" code i usedrelax
instead offoo
or {foo}. This gives me "false" twice
– Lupino
Jan 24 at 11:56
@Lupino I'd need to see the code... TheExtra else
shouldn't appear even if you replacefoo
byrelax
.ifx
compares the meaning of two tokens without expanding them previously, sorelax
is valid. Of course the comparison will only be true if both tokens expand torelax
, for instance this code first yieldsfoo is NOT relax
because, obviously,foo
is notrelax
, it only containsrelax
in its definition. The second comparison yieldsfoo is relax
because you makefoo
an exact copy ofrelax
.
– Phelype Oleinik
Jan 24 at 12:16
add a comment |
You're almost there. Two problems only.
First, @nameuse
contains an @
in the name, so you need to makeatletter
before using it.
Second, if you show@nameuse
(after a makeatletter
, of course) you see:
> @nameuse=macro:
#1->csname #1endcsname
so one expansion of @nameuse{foo}
yields csname blafaselendcsname
. The csname
...endcsname
requires another expansion to make blafasel
, which is what you want. So now you know you need two expansions of @nameuse
.
With
expandafterifx@nameuse{blafasel}foo
you expand it once. To expand twice you need one more expandafter
before each token that precedes @nameuse
. That is, one expandafter
for the "old" expandafter
, and another for the ifx
:
expandafterexpandafterexpandafterifx@nameuse{blafasel}foo
Now the code:
documentclass{standalone}
makeatletter
parindentz@
@namedef{blafasel}{foo}
deffoo{foo}
defbar{bar}
makeatother
begin{document}
1:
makeatletter
expandafterexpandafterexpandafterifx@nameuse{blafasel}foo
message{true}
else
message{false}
fi
2:
expandafterexpandafterexpandafterifx@nameuse{blafasel}bar
message{true}
else
message{false}
fi
end{document}
prints true false
somewhere in the terminal.
You're almost there. Two problems only.
First, @nameuse
contains an @
in the name, so you need to makeatletter
before using it.
Second, if you show@nameuse
(after a makeatletter
, of course) you see:
> @nameuse=macro:
#1->csname #1endcsname
so one expansion of @nameuse{foo}
yields csname blafaselendcsname
. The csname
...endcsname
requires another expansion to make blafasel
, which is what you want. So now you know you need two expansions of @nameuse
.
With
expandafterifx@nameuse{blafasel}foo
you expand it once. To expand twice you need one more expandafter
before each token that precedes @nameuse
. That is, one expandafter
for the "old" expandafter
, and another for the ifx
:
expandafterexpandafterexpandafterifx@nameuse{blafasel}foo
Now the code:
documentclass{standalone}
makeatletter
parindentz@
@namedef{blafasel}{foo}
deffoo{foo}
defbar{bar}
makeatother
begin{document}
1:
makeatletter
expandafterexpandafterexpandafterifx@nameuse{blafasel}foo
message{true}
else
message{false}
fi
2:
expandafterexpandafterexpandafterifx@nameuse{blafasel}bar
message{true}
else
message{false}
fi
end{document}
prints true false
somewhere in the terminal.
answered Jan 24 at 11:40
Phelype OleinikPhelype Oleinik
24.2k54688
24.2k54688
thank you, i'm going to accept the answer because it answers the OP. Unfortunately, in my "real" code, which is an xmltex project, this doesn't work. TeX complains about anExtra else
with this construction.
– Lupino
Jan 24 at 11:50
I found the difference: In my "real" code i usedrelax
instead offoo
or {foo}. This gives me "false" twice
– Lupino
Jan 24 at 11:56
@Lupino I'd need to see the code... TheExtra else
shouldn't appear even if you replacefoo
byrelax
.ifx
compares the meaning of two tokens without expanding them previously, sorelax
is valid. Of course the comparison will only be true if both tokens expand torelax
, for instance this code first yieldsfoo is NOT relax
because, obviously,foo
is notrelax
, it only containsrelax
in its definition. The second comparison yieldsfoo is relax
because you makefoo
an exact copy ofrelax
.
– Phelype Oleinik
Jan 24 at 12:16
add a comment |
thank you, i'm going to accept the answer because it answers the OP. Unfortunately, in my "real" code, which is an xmltex project, this doesn't work. TeX complains about anExtra else
with this construction.
– Lupino
Jan 24 at 11:50
I found the difference: In my "real" code i usedrelax
instead offoo
or {foo}. This gives me "false" twice
– Lupino
Jan 24 at 11:56
@Lupino I'd need to see the code... TheExtra else
shouldn't appear even if you replacefoo
byrelax
.ifx
compares the meaning of two tokens without expanding them previously, sorelax
is valid. Of course the comparison will only be true if both tokens expand torelax
, for instance this code first yieldsfoo is NOT relax
because, obviously,foo
is notrelax
, it only containsrelax
in its definition. The second comparison yieldsfoo is relax
because you makefoo
an exact copy ofrelax
.
– Phelype Oleinik
Jan 24 at 12:16
thank you, i'm going to accept the answer because it answers the OP. Unfortunately, in my "real" code, which is an xmltex project, this doesn't work. TeX complains about an
Extra else
with this construction.– Lupino
Jan 24 at 11:50
thank you, i'm going to accept the answer because it answers the OP. Unfortunately, in my "real" code, which is an xmltex project, this doesn't work. TeX complains about an
Extra else
with this construction.– Lupino
Jan 24 at 11:50
I found the difference: In my "real" code i used
relax
instead of foo
or {foo}. This gives me "false" twice– Lupino
Jan 24 at 11:56
I found the difference: In my "real" code i used
relax
instead of foo
or {foo}. This gives me "false" twice– Lupino
Jan 24 at 11:56
@Lupino I'd need to see the code... The
Extra else
shouldn't appear even if you replace foo
by relax
. ifx
compares the meaning of two tokens without expanding them previously, so relax
is valid. Of course the comparison will only be true if both tokens expand to relax
, for instance this code first yields foo is NOT relax
because, obviously, foo
is not relax
, it only contains relax
in its definition. The second comparison yields foo is relax
because you make foo
an exact copy of relax
.– Phelype Oleinik
Jan 24 at 12:16
@Lupino I'd need to see the code... The
Extra else
shouldn't appear even if you replace foo
by relax
. ifx
compares the meaning of two tokens without expanding them previously, so relax
is valid. Of course the comparison will only be true if both tokens expand to relax
, for instance this code first yields foo is NOT relax
because, obviously, foo
is not relax
, it only contains relax
in its definition. The second comparison yields foo is relax
because you make foo
an exact copy of relax
.– Phelype Oleinik
Jan 24 at 12:16
add a comment |
You need to expand two levels, so expandafterexpandafterexpandafter
, besides making @
a letter in order to avoid TeX compare the first two tokens in the expansion of @
(precisely, spacefactor
and @m
).
A single expandafter
is sufficient with expandafterifxcsname blafaselendcsnamefoo
.
There are simpler ways to compare macros expanding to strings of characters, the simplest one being
ifnumpdfstrcmp{@nameuse{blafadel}}{foo}=0
true
else
false
fi
that doesn't need to define foo
. Since pdfstrcmp
is available with different names in other engines, it's best to do
usepackage{pdftexcmds}
and use pdf@strcmp
.
Much more powerful string comparison functions are available with expl3
.
Thanks for the answer. Is that package bound to pdflatex? If so, i cant use it. Dvi output only...
– Lupino
Jan 24 at 12:02
@Lupino No, you can useexpl3
with any of the major engines (pdfTeX, XeTeX, LuaTeX, (u)pTeX) and it doesn't depend on the format being used, so you can use with plain, LaTeX, ConTeXt or basically any other format. It won't work in Knuth's TeX though, because it requires ε-TeX extensions.
– Phelype Oleinik
Jan 24 at 12:20
Since we are using Texlive2017 this should be fine. I will have a look at it, maybe i find something useful in there. Thanks for the advice :) .
– Lupino
Jan 24 at 14:55
add a comment |
You need to expand two levels, so expandafterexpandafterexpandafter
, besides making @
a letter in order to avoid TeX compare the first two tokens in the expansion of @
(precisely, spacefactor
and @m
).
A single expandafter
is sufficient with expandafterifxcsname blafaselendcsnamefoo
.
There are simpler ways to compare macros expanding to strings of characters, the simplest one being
ifnumpdfstrcmp{@nameuse{blafadel}}{foo}=0
true
else
false
fi
that doesn't need to define foo
. Since pdfstrcmp
is available with different names in other engines, it's best to do
usepackage{pdftexcmds}
and use pdf@strcmp
.
Much more powerful string comparison functions are available with expl3
.
Thanks for the answer. Is that package bound to pdflatex? If so, i cant use it. Dvi output only...
– Lupino
Jan 24 at 12:02
@Lupino No, you can useexpl3
with any of the major engines (pdfTeX, XeTeX, LuaTeX, (u)pTeX) and it doesn't depend on the format being used, so you can use with plain, LaTeX, ConTeXt or basically any other format. It won't work in Knuth's TeX though, because it requires ε-TeX extensions.
– Phelype Oleinik
Jan 24 at 12:20
Since we are using Texlive2017 this should be fine. I will have a look at it, maybe i find something useful in there. Thanks for the advice :) .
– Lupino
Jan 24 at 14:55
add a comment |
You need to expand two levels, so expandafterexpandafterexpandafter
, besides making @
a letter in order to avoid TeX compare the first two tokens in the expansion of @
(precisely, spacefactor
and @m
).
A single expandafter
is sufficient with expandafterifxcsname blafaselendcsnamefoo
.
There are simpler ways to compare macros expanding to strings of characters, the simplest one being
ifnumpdfstrcmp{@nameuse{blafadel}}{foo}=0
true
else
false
fi
that doesn't need to define foo
. Since pdfstrcmp
is available with different names in other engines, it's best to do
usepackage{pdftexcmds}
and use pdf@strcmp
.
Much more powerful string comparison functions are available with expl3
.
You need to expand two levels, so expandafterexpandafterexpandafter
, besides making @
a letter in order to avoid TeX compare the first two tokens in the expansion of @
(precisely, spacefactor
and @m
).
A single expandafter
is sufficient with expandafterifxcsname blafaselendcsnamefoo
.
There are simpler ways to compare macros expanding to strings of characters, the simplest one being
ifnumpdfstrcmp{@nameuse{blafadel}}{foo}=0
true
else
false
fi
that doesn't need to define foo
. Since pdfstrcmp
is available with different names in other engines, it's best to do
usepackage{pdftexcmds}
and use pdf@strcmp
.
Much more powerful string comparison functions are available with expl3
.
answered Jan 24 at 11:53
egregegreg
727k8819223231
727k8819223231
Thanks for the answer. Is that package bound to pdflatex? If so, i cant use it. Dvi output only...
– Lupino
Jan 24 at 12:02
@Lupino No, you can useexpl3
with any of the major engines (pdfTeX, XeTeX, LuaTeX, (u)pTeX) and it doesn't depend on the format being used, so you can use with plain, LaTeX, ConTeXt or basically any other format. It won't work in Knuth's TeX though, because it requires ε-TeX extensions.
– Phelype Oleinik
Jan 24 at 12:20
Since we are using Texlive2017 this should be fine. I will have a look at it, maybe i find something useful in there. Thanks for the advice :) .
– Lupino
Jan 24 at 14:55
add a comment |
Thanks for the answer. Is that package bound to pdflatex? If so, i cant use it. Dvi output only...
– Lupino
Jan 24 at 12:02
@Lupino No, you can useexpl3
with any of the major engines (pdfTeX, XeTeX, LuaTeX, (u)pTeX) and it doesn't depend on the format being used, so you can use with plain, LaTeX, ConTeXt or basically any other format. It won't work in Knuth's TeX though, because it requires ε-TeX extensions.
– Phelype Oleinik
Jan 24 at 12:20
Since we are using Texlive2017 this should be fine. I will have a look at it, maybe i find something useful in there. Thanks for the advice :) .
– Lupino
Jan 24 at 14:55
Thanks for the answer. Is that package bound to pdflatex? If so, i cant use it. Dvi output only...
– Lupino
Jan 24 at 12:02
Thanks for the answer. Is that package bound to pdflatex? If so, i cant use it. Dvi output only...
– Lupino
Jan 24 at 12:02
@Lupino No, you can use
expl3
with any of the major engines (pdfTeX, XeTeX, LuaTeX, (u)pTeX) and it doesn't depend on the format being used, so you can use with plain, LaTeX, ConTeXt or basically any other format. It won't work in Knuth's TeX though, because it requires ε-TeX extensions.– Phelype Oleinik
Jan 24 at 12:20
@Lupino No, you can use
expl3
with any of the major engines (pdfTeX, XeTeX, LuaTeX, (u)pTeX) and it doesn't depend on the format being used, so you can use with plain, LaTeX, ConTeXt or basically any other format. It won't work in Knuth's TeX though, because it requires ε-TeX extensions.– Phelype Oleinik
Jan 24 at 12:20
Since we are using Texlive2017 this should be fine. I will have a look at it, maybe i find something useful in there. Thanks for the advice :) .
– Lupino
Jan 24 at 14:55
Since we are using Texlive2017 this should be fine. I will have a look at it, maybe i find something useful in there. Thanks for the advice :) .
– Lupino
Jan 24 at 14:55
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%2f471625%2fnameuse-as-conditional%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'd use
etoolbox
'sifcsequal{<csname one>}{<csname two>}{<true>}{<false>}
– moewe
Jan 24 at 11:37
Yea, thanks all, i noticed my mistake as soon as i clicked "submit"... I added a "follow up" to the question, see edit above. Using
(end)csname
gave me twice "false" for some reason...– Lupino
Jan 24 at 11:41
2
If you use
foo
in 3, then you'll gettrue
. You're gettingfalse
twice because you're doing the same test.– egreg
Jan 24 at 11:43
@egreg and all: m( i'm so sorry
– Lupino
Jan 24 at 11:45