How to test if argument is a single space?Looping over stringsSplit single argument in multiple partsWhy do braces around a single-letter argument of a macro affect its output?def'ed plain-text argument behaves differently from plain texthow to determine the number of characters in the argument of a commandUsing the compulsory argument for the optional argument?Omitting argument in command definitionDefine macro whose argument is a wordSine squared with parentheses for argumentWhat is this newcommand argument?Macro that takes any latex code as an argument
What was the primary motivation for a historical figure like Xenophon to create an extensive collection of written material?
Why is unzipped file smaller than zipped file
How could the B-29 bomber back up under its own power?
What defines a person who is circumcised "of the heart"?
size of pointers and architecture
How many wires should be in a new thermostat cable?
amsmath: How can I use the equation numbering and label manually and anywhere?
Is a world with one country feeding everyone possible?
Is being an extrovert a necessary condition to be a manager?
Variable does not Exist: CaseTrigger
Is there a word for pant sleeves?
Why is a weak base more able to deprotonate a strong acid than a weak acid?
What is this dime sized black bug with white on the segments near Loveland Colorodao?
Sony VAIO Duo 13 Wifi not working on Ubuntu 16.04
Department head said that group project may be rejected. How to mitigate?
Managing heat dissipation in a magic wand
How can I reduce the size of matrix?
Anatomically correct Guivre
Way of refund if scammed?
Can a UK national work as a paid shop assistant in the USA?
How to create razor wire
JavaScript: Access 'this' when calling function stored in variable
Keeping the dodos out of the field
Nunc est bibendum: gerund or gerundive?
How to test if argument is a single space?
Looping over stringsSplit single argument in multiple partsWhy do braces around a single-letter argument of a macro affect its output?def'ed plain-text argument behaves differently from plain texthow to determine the number of characters in the argument of a commandUsing the compulsory argument for the optional argument?Omitting argument in command definitionDefine macro whose argument is a wordSine squared with parentheses for argumentWhat is this newcommand argument?Macro that takes any latex code as an argument
I am currently writing a document, that sometimes requires me to alternate the colors of the letters in a sentence. I thought it would be easy to find a way to create a macro that does that, but I've run into some problems.
MWE:
% !TeX program = xelatex
% !TeX spellcheck = en_US
documentclass[11pt,a4paper,english,twoside,notitlepage]book
usepackagefontspec
usepackagelmodern
usepackage[english,main=english]babel
usepackagexcolor
usepackageetoolbox
definecolorpurpleHTML2B0057
definecolorcandyHTMLFF0000
newcounteralternate
%the macro in question
newcommandcolset[1]%
ifnumvaluealternate=0 colorcandy#1setcounteralternate1%
elsecolorpurple#1setcounteralternate0%
fi
%snippet for the loop taken from https://tex.stackexchange.com/questions/359189/looping-over-strings
%iterates over the supplied string and replaces every letter with colset<letter>
defgobblecharletxchar=
defassignthencheckafterassignmentxloopgobblechar
defxloop%
ifxrelaxxchar
letnext=relax
else
colsetxcharletnext=assignthencheck
fi
next
defmarkletters#1setcounteralternate0assignthencheck#1relax
begindocument
marklettersHello World
enddocument
Output:
The issue is that I have found no way to skip the spaces (i.e. the "W" in "World" should be purple, not red). I thought it would be easy to simply check if the argument is a space and just skip the rest of the macro, but after hours of searching and just trial-and-error (approaches included etoolbox's ifblank#1
, constructs like ifx#1
or even ifnum`#1=32
, creating temporary macros [e.g. edeftemp#1ifblanktemp
]) I am still no step closer, and I'm definitely out of my depth on this one.
Is there a way to check if the argument of a macro is only a space? If no, are there any other ways to construct this macro? (I'm using XeLaTeX via MiKTeX)
Thanks!
macros arguments
add a comment |
I am currently writing a document, that sometimes requires me to alternate the colors of the letters in a sentence. I thought it would be easy to find a way to create a macro that does that, but I've run into some problems.
MWE:
% !TeX program = xelatex
% !TeX spellcheck = en_US
documentclass[11pt,a4paper,english,twoside,notitlepage]book
usepackagefontspec
usepackagelmodern
usepackage[english,main=english]babel
usepackagexcolor
usepackageetoolbox
definecolorpurpleHTML2B0057
definecolorcandyHTMLFF0000
newcounteralternate
%the macro in question
newcommandcolset[1]%
ifnumvaluealternate=0 colorcandy#1setcounteralternate1%
elsecolorpurple#1setcounteralternate0%
fi
%snippet for the loop taken from https://tex.stackexchange.com/questions/359189/looping-over-strings
%iterates over the supplied string and replaces every letter with colset<letter>
defgobblecharletxchar=
defassignthencheckafterassignmentxloopgobblechar
defxloop%
ifxrelaxxchar
letnext=relax
else
colsetxcharletnext=assignthencheck
fi
next
defmarkletters#1setcounteralternate0assignthencheck#1relax
begindocument
marklettersHello World
enddocument
Output:
The issue is that I have found no way to skip the spaces (i.e. the "W" in "World" should be purple, not red). I thought it would be easy to simply check if the argument is a space and just skip the rest of the macro, but after hours of searching and just trial-and-error (approaches included etoolbox's ifblank#1
, constructs like ifx#1
or even ifnum`#1=32
, creating temporary macros [e.g. edeftemp#1ifblanktemp
]) I am still no step closer, and I'm definitely out of my depth on this one.
Is there a way to check if the argument of a macro is only a space? If no, are there any other ways to construct this macro? (I'm using XeLaTeX via MiKTeX)
Thanks!
macros arguments
add a comment |
I am currently writing a document, that sometimes requires me to alternate the colors of the letters in a sentence. I thought it would be easy to find a way to create a macro that does that, but I've run into some problems.
MWE:
% !TeX program = xelatex
% !TeX spellcheck = en_US
documentclass[11pt,a4paper,english,twoside,notitlepage]book
usepackagefontspec
usepackagelmodern
usepackage[english,main=english]babel
usepackagexcolor
usepackageetoolbox
definecolorpurpleHTML2B0057
definecolorcandyHTMLFF0000
newcounteralternate
%the macro in question
newcommandcolset[1]%
ifnumvaluealternate=0 colorcandy#1setcounteralternate1%
elsecolorpurple#1setcounteralternate0%
fi
%snippet for the loop taken from https://tex.stackexchange.com/questions/359189/looping-over-strings
%iterates over the supplied string and replaces every letter with colset<letter>
defgobblecharletxchar=
defassignthencheckafterassignmentxloopgobblechar
defxloop%
ifxrelaxxchar
letnext=relax
else
colsetxcharletnext=assignthencheck
fi
next
defmarkletters#1setcounteralternate0assignthencheck#1relax
begindocument
marklettersHello World
enddocument
Output:
The issue is that I have found no way to skip the spaces (i.e. the "W" in "World" should be purple, not red). I thought it would be easy to simply check if the argument is a space and just skip the rest of the macro, but after hours of searching and just trial-and-error (approaches included etoolbox's ifblank#1
, constructs like ifx#1
or even ifnum`#1=32
, creating temporary macros [e.g. edeftemp#1ifblanktemp
]) I am still no step closer, and I'm definitely out of my depth on this one.
Is there a way to check if the argument of a macro is only a space? If no, are there any other ways to construct this macro? (I'm using XeLaTeX via MiKTeX)
Thanks!
macros arguments
I am currently writing a document, that sometimes requires me to alternate the colors of the letters in a sentence. I thought it would be easy to find a way to create a macro that does that, but I've run into some problems.
MWE:
% !TeX program = xelatex
% !TeX spellcheck = en_US
documentclass[11pt,a4paper,english,twoside,notitlepage]book
usepackagefontspec
usepackagelmodern
usepackage[english,main=english]babel
usepackagexcolor
usepackageetoolbox
definecolorpurpleHTML2B0057
definecolorcandyHTMLFF0000
newcounteralternate
%the macro in question
newcommandcolset[1]%
ifnumvaluealternate=0 colorcandy#1setcounteralternate1%
elsecolorpurple#1setcounteralternate0%
fi
%snippet for the loop taken from https://tex.stackexchange.com/questions/359189/looping-over-strings
%iterates over the supplied string and replaces every letter with colset<letter>
defgobblecharletxchar=
defassignthencheckafterassignmentxloopgobblechar
defxloop%
ifxrelaxxchar
letnext=relax
else
colsetxcharletnext=assignthencheck
fi
next
defmarkletters#1setcounteralternate0assignthencheck#1relax
begindocument
marklettersHello World
enddocument
Output:
The issue is that I have found no way to skip the spaces (i.e. the "W" in "World" should be purple, not red). I thought it would be easy to simply check if the argument is a space and just skip the rest of the macro, but after hours of searching and just trial-and-error (approaches included etoolbox's ifblank#1
, constructs like ifx#1
or even ifnum`#1=32
, creating temporary macros [e.g. edeftemp#1ifblanktemp
]) I am still no step closer, and I'm definitely out of my depth on this one.
Is there a way to check if the argument of a macro is only a space? If no, are there any other ways to construct this macro? (I'm using XeLaTeX via MiKTeX)
Thanks!
macros arguments
macros arguments
asked 2 hours ago
GrzzlwmpfGrzzlwmpf
233
233
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
You are not iterating using macro arguments, so you do not need to test a macro argument, just test the token you have already:
documentclass[11pt,a4paper,english,twoside,notitlepage]book
usepackagefontspec
usepackagelmodern
usepackage[english,main=english]babel
usepackagexcolor
usepackageetoolbox
definecolorpurpleHTML2B0057
definecolorcandyHTMLFF0000
newcounteralternate
%the macro in question
newcommandcolset[1]%
ifnumvaluealternate=0 colorcandy#1setcounteralternate1%
elsecolorpurple#1setcounteralternate0%
fi
makeatletter
%snippet for the loop taken from https://tex.stackexchange.com/questions/359189/looping-over-strings
%iterates over the supplied string and replaces every letter with colset<letter>
defgobblecharletxchar=
defassignthencheckafterassignmentxloopgobblechar
defxloop%
ifxrelaxxchar
letnext=relax
else
ifx@sptokenxcharsetcounteralternatenumexpr1-valuealternatefi
colsetxcharletnext=assignthencheck
fi
next
makeatother
defmarkletters#1setcounteralternate0assignthencheck#1relax
begindocument
marklettersHello World
enddocument
add a comment |
You can substitute spaces with something that expands to a space.
documentclass[11pt,a4paper,english,twoside,notitlepage]book
usepackagefontspec
usepackagelmodern
usepackage[english,main=english]babel
usepackagexcolor
definecolorpurpleHTML2B0057
definecolorcandyHTMLFF0000
ExplSyntaxOn
NewDocumentCommandmarklettersm
int_zero:N l_tmpa_int
tl_set:Nn l_tmpa_tl #1
% replace spaces with something different
tl_replace_all:Nnn l_tmpa_tl ~ c_space_tl
tl_map_inline:Nn l_tmpa_tl
tl_if_blank:eTF ##1
~ % don't advance the counter and issue a space
textcolor int_if_odd:nTF l_tmpa_int purple candy ##1
int_incr:N l_tmpa_int
prg_generate_conditional_variant:Nnn tl_if_blank:n e T,F,TF,p
ExplSyntaxOff
begindocument
marklettersHello World
enddocument
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%2f491668%2fhow-to-test-if-argument-is-a-single-space%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 are not iterating using macro arguments, so you do not need to test a macro argument, just test the token you have already:
documentclass[11pt,a4paper,english,twoside,notitlepage]book
usepackagefontspec
usepackagelmodern
usepackage[english,main=english]babel
usepackagexcolor
usepackageetoolbox
definecolorpurpleHTML2B0057
definecolorcandyHTMLFF0000
newcounteralternate
%the macro in question
newcommandcolset[1]%
ifnumvaluealternate=0 colorcandy#1setcounteralternate1%
elsecolorpurple#1setcounteralternate0%
fi
makeatletter
%snippet for the loop taken from https://tex.stackexchange.com/questions/359189/looping-over-strings
%iterates over the supplied string and replaces every letter with colset<letter>
defgobblecharletxchar=
defassignthencheckafterassignmentxloopgobblechar
defxloop%
ifxrelaxxchar
letnext=relax
else
ifx@sptokenxcharsetcounteralternatenumexpr1-valuealternatefi
colsetxcharletnext=assignthencheck
fi
next
makeatother
defmarkletters#1setcounteralternate0assignthencheck#1relax
begindocument
marklettersHello World
enddocument
add a comment |
You are not iterating using macro arguments, so you do not need to test a macro argument, just test the token you have already:
documentclass[11pt,a4paper,english,twoside,notitlepage]book
usepackagefontspec
usepackagelmodern
usepackage[english,main=english]babel
usepackagexcolor
usepackageetoolbox
definecolorpurpleHTML2B0057
definecolorcandyHTMLFF0000
newcounteralternate
%the macro in question
newcommandcolset[1]%
ifnumvaluealternate=0 colorcandy#1setcounteralternate1%
elsecolorpurple#1setcounteralternate0%
fi
makeatletter
%snippet for the loop taken from https://tex.stackexchange.com/questions/359189/looping-over-strings
%iterates over the supplied string and replaces every letter with colset<letter>
defgobblecharletxchar=
defassignthencheckafterassignmentxloopgobblechar
defxloop%
ifxrelaxxchar
letnext=relax
else
ifx@sptokenxcharsetcounteralternatenumexpr1-valuealternatefi
colsetxcharletnext=assignthencheck
fi
next
makeatother
defmarkletters#1setcounteralternate0assignthencheck#1relax
begindocument
marklettersHello World
enddocument
add a comment |
You are not iterating using macro arguments, so you do not need to test a macro argument, just test the token you have already:
documentclass[11pt,a4paper,english,twoside,notitlepage]book
usepackagefontspec
usepackagelmodern
usepackage[english,main=english]babel
usepackagexcolor
usepackageetoolbox
definecolorpurpleHTML2B0057
definecolorcandyHTMLFF0000
newcounteralternate
%the macro in question
newcommandcolset[1]%
ifnumvaluealternate=0 colorcandy#1setcounteralternate1%
elsecolorpurple#1setcounteralternate0%
fi
makeatletter
%snippet for the loop taken from https://tex.stackexchange.com/questions/359189/looping-over-strings
%iterates over the supplied string and replaces every letter with colset<letter>
defgobblecharletxchar=
defassignthencheckafterassignmentxloopgobblechar
defxloop%
ifxrelaxxchar
letnext=relax
else
ifx@sptokenxcharsetcounteralternatenumexpr1-valuealternatefi
colsetxcharletnext=assignthencheck
fi
next
makeatother
defmarkletters#1setcounteralternate0assignthencheck#1relax
begindocument
marklettersHello World
enddocument
You are not iterating using macro arguments, so you do not need to test a macro argument, just test the token you have already:
documentclass[11pt,a4paper,english,twoside,notitlepage]book
usepackagefontspec
usepackagelmodern
usepackage[english,main=english]babel
usepackagexcolor
usepackageetoolbox
definecolorpurpleHTML2B0057
definecolorcandyHTMLFF0000
newcounteralternate
%the macro in question
newcommandcolset[1]%
ifnumvaluealternate=0 colorcandy#1setcounteralternate1%
elsecolorpurple#1setcounteralternate0%
fi
makeatletter
%snippet for the loop taken from https://tex.stackexchange.com/questions/359189/looping-over-strings
%iterates over the supplied string and replaces every letter with colset<letter>
defgobblecharletxchar=
defassignthencheckafterassignmentxloopgobblechar
defxloop%
ifxrelaxxchar
letnext=relax
else
ifx@sptokenxcharsetcounteralternatenumexpr1-valuealternatefi
colsetxcharletnext=assignthencheck
fi
next
makeatother
defmarkletters#1setcounteralternate0assignthencheck#1relax
begindocument
marklettersHello World
enddocument
answered 2 hours ago
David CarlisleDavid Carlisle
505k4211521903
505k4211521903
add a comment |
add a comment |
You can substitute spaces with something that expands to a space.
documentclass[11pt,a4paper,english,twoside,notitlepage]book
usepackagefontspec
usepackagelmodern
usepackage[english,main=english]babel
usepackagexcolor
definecolorpurpleHTML2B0057
definecolorcandyHTMLFF0000
ExplSyntaxOn
NewDocumentCommandmarklettersm
int_zero:N l_tmpa_int
tl_set:Nn l_tmpa_tl #1
% replace spaces with something different
tl_replace_all:Nnn l_tmpa_tl ~ c_space_tl
tl_map_inline:Nn l_tmpa_tl
tl_if_blank:eTF ##1
~ % don't advance the counter and issue a space
textcolor int_if_odd:nTF l_tmpa_int purple candy ##1
int_incr:N l_tmpa_int
prg_generate_conditional_variant:Nnn tl_if_blank:n e T,F,TF,p
ExplSyntaxOff
begindocument
marklettersHello World
enddocument
add a comment |
You can substitute spaces with something that expands to a space.
documentclass[11pt,a4paper,english,twoside,notitlepage]book
usepackagefontspec
usepackagelmodern
usepackage[english,main=english]babel
usepackagexcolor
definecolorpurpleHTML2B0057
definecolorcandyHTMLFF0000
ExplSyntaxOn
NewDocumentCommandmarklettersm
int_zero:N l_tmpa_int
tl_set:Nn l_tmpa_tl #1
% replace spaces with something different
tl_replace_all:Nnn l_tmpa_tl ~ c_space_tl
tl_map_inline:Nn l_tmpa_tl
tl_if_blank:eTF ##1
~ % don't advance the counter and issue a space
textcolor int_if_odd:nTF l_tmpa_int purple candy ##1
int_incr:N l_tmpa_int
prg_generate_conditional_variant:Nnn tl_if_blank:n e T,F,TF,p
ExplSyntaxOff
begindocument
marklettersHello World
enddocument
add a comment |
You can substitute spaces with something that expands to a space.
documentclass[11pt,a4paper,english,twoside,notitlepage]book
usepackagefontspec
usepackagelmodern
usepackage[english,main=english]babel
usepackagexcolor
definecolorpurpleHTML2B0057
definecolorcandyHTMLFF0000
ExplSyntaxOn
NewDocumentCommandmarklettersm
int_zero:N l_tmpa_int
tl_set:Nn l_tmpa_tl #1
% replace spaces with something different
tl_replace_all:Nnn l_tmpa_tl ~ c_space_tl
tl_map_inline:Nn l_tmpa_tl
tl_if_blank:eTF ##1
~ % don't advance the counter and issue a space
textcolor int_if_odd:nTF l_tmpa_int purple candy ##1
int_incr:N l_tmpa_int
prg_generate_conditional_variant:Nnn tl_if_blank:n e T,F,TF,p
ExplSyntaxOff
begindocument
marklettersHello World
enddocument
You can substitute spaces with something that expands to a space.
documentclass[11pt,a4paper,english,twoside,notitlepage]book
usepackagefontspec
usepackagelmodern
usepackage[english,main=english]babel
usepackagexcolor
definecolorpurpleHTML2B0057
definecolorcandyHTMLFF0000
ExplSyntaxOn
NewDocumentCommandmarklettersm
int_zero:N l_tmpa_int
tl_set:Nn l_tmpa_tl #1
% replace spaces with something different
tl_replace_all:Nnn l_tmpa_tl ~ c_space_tl
tl_map_inline:Nn l_tmpa_tl
tl_if_blank:eTF ##1
~ % don't advance the counter and issue a space
textcolor int_if_odd:nTF l_tmpa_int purple candy ##1
int_incr:N l_tmpa_int
prg_generate_conditional_variant:Nnn tl_if_blank:n e T,F,TF,p
ExplSyntaxOff
begindocument
marklettersHello World
enddocument
answered 2 hours ago
egregegreg
742k8919443277
742k8919443277
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%2f491668%2fhow-to-test-if-argument-is-a-single-space%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