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
How did the Allies achieve air superiority on Sicily?
Passport queue length in UK in relation to arrival method
Is the default 512 byte physical sector size appropriate for SSD disks under Linux?
What pc resources are used when bruteforcing?
Is there a word for pant sleeves?
Is it safe to redirect stdout and stderr to the same file without file descriptor copies?
How many wires should be in a new thermostat cable?
Does the fact that we can only measure the two-way speed of light undermine the axiom of invariance?
Can a UK national work as a paid shop assistant in the USA?
Can someone get a spouse off a deed that never lived together and was incarcerated?
What technology is there beyond RAID for disk cluster in a server
If I arrive in the UK, and then head to mainland Europe, does my Schengen visa 90 day limit start when I arrived in the UK, or mainland Europe?
How do I write real-world stories separate from my country of origin?
Were there any developed countries that became "undeveloped" for reasons other than war?
What is the winged creature on the back of the Mordenkainen's Tome of Foes book?
Find this Unique UVC Palindrome ( ignoring signs and decimal) from Given Fractional Relationship
Can the Conjure Barrage spell stack with the Disarming Attack or Trip Attack Battle Master maneuvers?
How to safely discharge oneself
Which values for voltage divider
What is this dime sized black bug with white on the segments near Loveland Colorodao?
Department head said that group project may be rejected. How to mitigate?
Adobe Illustrator: How can I change the profile of a dashed stroke?
One word for 'the thing that attracts me'?
Is it normal to "extract a paper" from a master thesis?
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 1 hour ago
GrzzlwmpfGrzzlwmpf
183
183
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 59 mins 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 1 hour 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