How to repeat over all characters in a string? Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)Apply a macro to every wordSecurity code generatorSpreading letters evenly across a line from margin to marginOpenType 'rand' (Randomize) feature not correct implemented in XeTeX?Using newcommand to format numbers/strings according to a patternA command for making a string of charactersCommand to count characters in a specified stringForEachX and string concatenationHow to wrap a `newcommand*` into a multi-paragraph environment?Expandable macro with loops and advanced string functions?Repeat characters n timesLooping over stringsNew macro and glossary entry in a commandLoop through letters and apply a color to the first 3

Do regular languages belong to Space(1)?

Trying to enter the Fox's den

How do I find my Spellcasting Ability for my D&D character?

Weaponising the Grasp-at-a-Distance spell

How to create a button that adds InputFields when clicked?

"Destructive power" carried by a B-52?

As a dual citizen, my US passport will expire one day after traveling to the US. Will this work?

Why does BitLocker not use RSA?

Flight departed from the gate 5 min before scheduled departure time. Refund options

Is there night in Alpha Complex?

How to achieve cat-like agility?

My mentor says to set image to Fine instead of RAW — how is this different from JPG?

Are there any irrational/transcendental numbers for which the distribution of decimal digits is not uniform?

How to resize main filesystem

Is my guitar action too high?

Why is there so little support for joining EFTA in the British parliament?

Does GDPR cover the collection of data by websites that crawl the web and resell user data

A German immigrant ancestor has a "Registration Affidavit of Alien Enemy" on file. What does that mean exactly?

Can a Knight grant Knighthood to another?

Magento 2 Editing phtml files in Production Mode

Restricting the Object Type for the get method in a Java HashMap

Proving that any solution to the differential equation of an oscillator can be written as a sum of sinusoids.

Who's this lady in the war room?

Combining list in a Cartesian product format with addition operation?



How to repeat over all characters in a string?



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)Apply a macro to every wordSecurity code generatorSpreading letters evenly across a line from margin to marginOpenType 'rand' (Randomize) feature not correct implemented in XeTeX?Using newcommand to format numbers/strings according to a patternA command for making a string of charactersCommand to count characters in a specified stringForEachX and string concatenationHow to wrap a `newcommand*` into a multi-paragraph environment?Expandable macro with loops and advanced string functions?Repeat characters n timesLooping over stringsNew macro and glossary entry in a commandLoop through letters and apply a color to the first 3










10















I have a command that formats a single character, let's call it d. (In my case, d adds a dot under a Chinese character, as this is the custom to emphasize Chinese texts).



I want to define a new command ds such that it applies d over every letter of the string.



For example dsabc would be equivalent to dadbdc.



Thanks!










share|improve this question
























  • Do you expect just characters in the string? Can you give a hint about what d should do? Is this for LaTeX or Plain?

    – egreg
    Jul 1 '15 at 16:16












  • Yes, there will just be characters in the string. Not equations. (But my d uses Latex maths inside it, if that matters).

    – Yan King Yin
    Jul 1 '15 at 16:26











  • Can you give us the d definition?

    – Gonzalo Medina
    Jul 1 '15 at 16:26











  • renewcommandd[1]$underaccentscalebox0.5textbullettextrm#1$

    – Yan King Yin
    Jul 1 '15 at 16:28















10















I have a command that formats a single character, let's call it d. (In my case, d adds a dot under a Chinese character, as this is the custom to emphasize Chinese texts).



I want to define a new command ds such that it applies d over every letter of the string.



For example dsabc would be equivalent to dadbdc.



Thanks!










share|improve this question
























  • Do you expect just characters in the string? Can you give a hint about what d should do? Is this for LaTeX or Plain?

    – egreg
    Jul 1 '15 at 16:16












  • Yes, there will just be characters in the string. Not equations. (But my d uses Latex maths inside it, if that matters).

    – Yan King Yin
    Jul 1 '15 at 16:26











  • Can you give us the d definition?

    – Gonzalo Medina
    Jul 1 '15 at 16:26











  • renewcommandd[1]$underaccentscalebox0.5textbullettextrm#1$

    – Yan King Yin
    Jul 1 '15 at 16:28













10












10








10


2






I have a command that formats a single character, let's call it d. (In my case, d adds a dot under a Chinese character, as this is the custom to emphasize Chinese texts).



I want to define a new command ds such that it applies d over every letter of the string.



For example dsabc would be equivalent to dadbdc.



Thanks!










share|improve this question
















I have a command that formats a single character, let's call it d. (In my case, d adds a dot under a Chinese character, as this is the custom to emphasize Chinese texts).



I want to define a new command ds such that it applies d over every letter of the string.



For example dsabc would be equivalent to dadbdc.



Thanks!







macros loops strings






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jul 1 '15 at 16:24







Yan King Yin

















asked Jul 1 '15 at 16:12









Yan King YinYan King Yin

6241619




6241619












  • Do you expect just characters in the string? Can you give a hint about what d should do? Is this for LaTeX or Plain?

    – egreg
    Jul 1 '15 at 16:16












  • Yes, there will just be characters in the string. Not equations. (But my d uses Latex maths inside it, if that matters).

    – Yan King Yin
    Jul 1 '15 at 16:26











  • Can you give us the d definition?

    – Gonzalo Medina
    Jul 1 '15 at 16:26











  • renewcommandd[1]$underaccentscalebox0.5textbullettextrm#1$

    – Yan King Yin
    Jul 1 '15 at 16:28

















  • Do you expect just characters in the string? Can you give a hint about what d should do? Is this for LaTeX or Plain?

    – egreg
    Jul 1 '15 at 16:16












  • Yes, there will just be characters in the string. Not equations. (But my d uses Latex maths inside it, if that matters).

    – Yan King Yin
    Jul 1 '15 at 16:26











  • Can you give us the d definition?

    – Gonzalo Medina
    Jul 1 '15 at 16:26











  • renewcommandd[1]$underaccentscalebox0.5textbullettextrm#1$

    – Yan King Yin
    Jul 1 '15 at 16:28
















Do you expect just characters in the string? Can you give a hint about what d should do? Is this for LaTeX or Plain?

– egreg
Jul 1 '15 at 16:16






Do you expect just characters in the string? Can you give a hint about what d should do? Is this for LaTeX or Plain?

– egreg
Jul 1 '15 at 16:16














Yes, there will just be characters in the string. Not equations. (But my d uses Latex maths inside it, if that matters).

– Yan King Yin
Jul 1 '15 at 16:26





Yes, there will just be characters in the string. Not equations. (But my d uses Latex maths inside it, if that matters).

– Yan King Yin
Jul 1 '15 at 16:26













Can you give us the d definition?

– Gonzalo Medina
Jul 1 '15 at 16:26





Can you give us the d definition?

– Gonzalo Medina
Jul 1 '15 at 16:26













renewcommandd[1]$underaccentscalebox0.5textbullettextrm#1$

– Yan King Yin
Jul 1 '15 at 16:28





renewcommandd[1]$underaccentscalebox0.5textbullettextrm#1$

– Yan King Yin
Jul 1 '15 at 16:28










2 Answers
2






active

oldest

votes


















14














You can use @tfor. I provide also a better redefinition of the dot under according to your wish:



documentclassarticle
usepackagegraphicx

letdrelax
DeclareRobustCommandd[1]%
oalign#1crhidewidthscalebox0.5textbullethidewidthcr%

makeatletter
newcommandds[1]%
@tfornext:=#1dodnext%

makeatother

begindocument

xdddsdax

xdsdsax

enddocument


enter image description here



What does @tfor do? Its syntax is



@tfor<scratch macro>:=<tokens>do<code>


The scratch macro is traditionally next, but it can be anything. The <tokens> part is any (brace balanced) list of tokens. In the loop, LaTeX essentially does def<scratch macro><next token>, so



@tfornext:=dsadodnext


will perform



defnextddnextdefnextsdnextdefnextadnext


However, with @tfornext:=d sadodnext we will just obtain



defnextddnextdefnextsadnext


Explicit space tokens are ignored and braced groups of tokens are treated as one.



The expl3 analog is tl_map_inline:nn:



documentclassarticle
usepackagexparse
usepackagegraphicx

letdrelax
DeclareRobustCommandd[1]%
oalign#1crhidewidthscalebox0.5textbullethidewidthcr%


ExplSyntaxOn
NewDocumentCommanddsm

tl_map_inline:n #1 d ##1

ExplSyntaxOff

begindocument

xdddsdax

xdsdsax

xdsd sabcx

enddocument


No scratch macro is used: the current item in the loop is denoted by #1 (which becomes ##1 in the body of a definition, as usual).



In this particular case where just a single command is applied with the current item as argument, one can use tl_map_function:nN:



NewDocumentCommanddsm

tl_map_function:n #1 d



which has the same effect and is shorter. It can also appear in a full expansion context (not for this particular case, because of d).



enter image description here






share|improve this answer

























  • It would be great to have an explanation of @tfor, especially since it's not defined in plain TeX

    – jpaugh
    Apr 27 '17 at 2:53


















5














This solution allows word wrap and handles spaces between words. In addition, the [w] option allows the task to be performed on each word, rather than each character.'



In the MWE, I demonstrate with variously defined tasks:



  1. overstrike each character (2 different settings)


  2. place a dot under each character


  3. place a semicolon under each word


  4. apply extra intercharacter space


  5. apply extra interword space.


The task is defined in charop for characters and wordop for words, while the chariterate[] macro does the iteration. Here is the MWE:



% WHILE THIS EXAMPLE IS SET UP FOR BOLDING A CALLIGRAPHIC FONT
% ITS GENERAL USE IS TO DO SOMETHING ON EACH char OF ITS ARGUMENT, ALLOWING LINE WRAP
% THE [W] OPTION TO chariterate DOES SOMETHING TO EACH WORD.
documentclass[10pt,a4paper,BCOR10mm,DIV11,toc=listof,parskip=full, openany]scrbook
usepackagestackengine
newcommandchariterate[2][c]if w#1worditeratehelper#2 relaxrelaxelse
chariteratehelpA#2 relaxrelaxfi
defchariteratehelpA#1 #2relax%
chariteratehelpB#1relaxrelax%
ifxrelax#2else chariteratehelpA#2relaxfi

defchariteratehelpB#1#2relax%
charop#1%
ifxrelax#2else
chariteratehelpB#2relax%
fi

defworditeratehelper#1 #2relax%
wordop#1%
ifxrelax#2else worditeratehelper#2relaxfi

defcharop#1#1
defwordop#1#1
% THIS EXAMPLE ARTIFICIALLY BOLDS EACH char WITH A SHIFTED OVERSTRIKE
defcharopA%
%defuseanchorwidthT%
defstacktypeL%
defstackalignmentl%
defcalup.2pt%
defcalover.15pt%
renewcommandcharop[1]stackon[calup]##1kerncalover##1%

% HERE'S AN EXAMPLE PLACING DOT UNDER EACH char
defcharopB%
defuseanchorwidthT%
defstacktypeL%
defstackalignmentc%
renewcommandcharop[1]stackunder[3pt]##1.%

% EXTRA INTER-CHARACTER SPACE
defcharopCrenewcommandcharop[1]##1,
% HERE'S AN EXAMPLE PLACING DOT UNDER EACH WORD
defwordopA%
renewcommandwordop[1]defstackalignmentcstackunder[3pt]##1;

% EXTRA INTER-WORD SPACE
defwordopBrenewcommandwordop[1]##1
%
newenvironmentcalligraphic%
fontencodingT1fontfamilypzcfontseriesmfontshapeitfontsize12pt12ptselectfont%
renewcommand*sectfontnormalcolorusefontT1pzcmit
begindocument
charopA
begincalligraphic
Test textbfthis is not boldpar
Test chariteratethis is bold with .2pt up shift and .15pt right shiftpar
defcalup.0pt
defcalover.2pt
Test chariteratethis is bold with .0pt up shift and .2pt right shiftpar
chariteratecvxc This is a test. This is a test. This is a test. This is a test.
This is a test. This is a test. This is a test. This is a test. This is a
test. This is a test. This is a test. This fdsfsd is a test. This is a test.
This is a test. This is a test. This is adfsdf test. This is a test.par
endcalligraphicpar
charopB
wordopA
chariterateThis is doing something to each character.par
chariterate[w]This is doing something to each word.par
chariterateIch bin m"ude.
chariterate[w]Ich bin m"ude.par
charopC
wordopB
chariterateThis is doing something to each character.par
chariterate[w]This is doing something to each word.par
enddocument


enter image description here



In the most simple incarnation, to do merely underdots on characters alone, the code can be greatly reduced:



documentclassarticle
usepackagestackengine
newcommandchariterate[2][c]if w#1worditeratehelper#2 relaxrelaxelse
chariteratehelpA#2 relaxrelaxfi
defchariteratehelpA#1 #2relax%
chariteratehelpB#1relaxrelax%
ifxrelax#2else chariteratehelpA#2relaxfi

defchariteratehelpB#1#2relax%
charop#1%
ifxrelax#2else
chariteratehelpB#2relax%
fi

defworditeratehelper#1 #2relax%
wordop#1%
ifxrelax#2else worditeratehelper#2relaxfi

defuseanchorwidthT%
defstacktypeL%
defstackalignmentc%
newcommandcharop[1]stackunder[3pt]#1.%
defwordop#1#1
begindocument
chariterateThis is doing something to each character.
This is doing something to each character.
This is doing something to each character.par
enddocument





share|improve this answer

























  • Thanks, that may be useful for Chinese fonts also, when they don't provide the bold fonts.

    – Yan King Yin
    Jul 6 '15 at 16:28











  • Extremely useful! To ensure that also bigger fontsizes like headings look good, I'd suggest to define the length for stackunder in ex though.

    – Florian
    Oct 14 '17 at 11:37











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
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f253203%2fhow-to-repeat-over-all-characters-in-a-string%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









14














You can use @tfor. I provide also a better redefinition of the dot under according to your wish:



documentclassarticle
usepackagegraphicx

letdrelax
DeclareRobustCommandd[1]%
oalign#1crhidewidthscalebox0.5textbullethidewidthcr%

makeatletter
newcommandds[1]%
@tfornext:=#1dodnext%

makeatother

begindocument

xdddsdax

xdsdsax

enddocument


enter image description here



What does @tfor do? Its syntax is



@tfor<scratch macro>:=<tokens>do<code>


The scratch macro is traditionally next, but it can be anything. The <tokens> part is any (brace balanced) list of tokens. In the loop, LaTeX essentially does def<scratch macro><next token>, so



@tfornext:=dsadodnext


will perform



defnextddnextdefnextsdnextdefnextadnext


However, with @tfornext:=d sadodnext we will just obtain



defnextddnextdefnextsadnext


Explicit space tokens are ignored and braced groups of tokens are treated as one.



The expl3 analog is tl_map_inline:nn:



documentclassarticle
usepackagexparse
usepackagegraphicx

letdrelax
DeclareRobustCommandd[1]%
oalign#1crhidewidthscalebox0.5textbullethidewidthcr%


ExplSyntaxOn
NewDocumentCommanddsm

tl_map_inline:n #1 d ##1

ExplSyntaxOff

begindocument

xdddsdax

xdsdsax

xdsd sabcx

enddocument


No scratch macro is used: the current item in the loop is denoted by #1 (which becomes ##1 in the body of a definition, as usual).



In this particular case where just a single command is applied with the current item as argument, one can use tl_map_function:nN:



NewDocumentCommanddsm

tl_map_function:n #1 d



which has the same effect and is shorter. It can also appear in a full expansion context (not for this particular case, because of d).



enter image description here






share|improve this answer

























  • It would be great to have an explanation of @tfor, especially since it's not defined in plain TeX

    – jpaugh
    Apr 27 '17 at 2:53















14














You can use @tfor. I provide also a better redefinition of the dot under according to your wish:



documentclassarticle
usepackagegraphicx

letdrelax
DeclareRobustCommandd[1]%
oalign#1crhidewidthscalebox0.5textbullethidewidthcr%

makeatletter
newcommandds[1]%
@tfornext:=#1dodnext%

makeatother

begindocument

xdddsdax

xdsdsax

enddocument


enter image description here



What does @tfor do? Its syntax is



@tfor<scratch macro>:=<tokens>do<code>


The scratch macro is traditionally next, but it can be anything. The <tokens> part is any (brace balanced) list of tokens. In the loop, LaTeX essentially does def<scratch macro><next token>, so



@tfornext:=dsadodnext


will perform



defnextddnextdefnextsdnextdefnextadnext


However, with @tfornext:=d sadodnext we will just obtain



defnextddnextdefnextsadnext


Explicit space tokens are ignored and braced groups of tokens are treated as one.



The expl3 analog is tl_map_inline:nn:



documentclassarticle
usepackagexparse
usepackagegraphicx

letdrelax
DeclareRobustCommandd[1]%
oalign#1crhidewidthscalebox0.5textbullethidewidthcr%


ExplSyntaxOn
NewDocumentCommanddsm

tl_map_inline:n #1 d ##1

ExplSyntaxOff

begindocument

xdddsdax

xdsdsax

xdsd sabcx

enddocument


No scratch macro is used: the current item in the loop is denoted by #1 (which becomes ##1 in the body of a definition, as usual).



In this particular case where just a single command is applied with the current item as argument, one can use tl_map_function:nN:



NewDocumentCommanddsm

tl_map_function:n #1 d



which has the same effect and is shorter. It can also appear in a full expansion context (not for this particular case, because of d).



enter image description here






share|improve this answer

























  • It would be great to have an explanation of @tfor, especially since it's not defined in plain TeX

    – jpaugh
    Apr 27 '17 at 2:53













14












14








14







You can use @tfor. I provide also a better redefinition of the dot under according to your wish:



documentclassarticle
usepackagegraphicx

letdrelax
DeclareRobustCommandd[1]%
oalign#1crhidewidthscalebox0.5textbullethidewidthcr%

makeatletter
newcommandds[1]%
@tfornext:=#1dodnext%

makeatother

begindocument

xdddsdax

xdsdsax

enddocument


enter image description here



What does @tfor do? Its syntax is



@tfor<scratch macro>:=<tokens>do<code>


The scratch macro is traditionally next, but it can be anything. The <tokens> part is any (brace balanced) list of tokens. In the loop, LaTeX essentially does def<scratch macro><next token>, so



@tfornext:=dsadodnext


will perform



defnextddnextdefnextsdnextdefnextadnext


However, with @tfornext:=d sadodnext we will just obtain



defnextddnextdefnextsadnext


Explicit space tokens are ignored and braced groups of tokens are treated as one.



The expl3 analog is tl_map_inline:nn:



documentclassarticle
usepackagexparse
usepackagegraphicx

letdrelax
DeclareRobustCommandd[1]%
oalign#1crhidewidthscalebox0.5textbullethidewidthcr%


ExplSyntaxOn
NewDocumentCommanddsm

tl_map_inline:n #1 d ##1

ExplSyntaxOff

begindocument

xdddsdax

xdsdsax

xdsd sabcx

enddocument


No scratch macro is used: the current item in the loop is denoted by #1 (which becomes ##1 in the body of a definition, as usual).



In this particular case where just a single command is applied with the current item as argument, one can use tl_map_function:nN:



NewDocumentCommanddsm

tl_map_function:n #1 d



which has the same effect and is shorter. It can also appear in a full expansion context (not for this particular case, because of d).



enter image description here






share|improve this answer















You can use @tfor. I provide also a better redefinition of the dot under according to your wish:



documentclassarticle
usepackagegraphicx

letdrelax
DeclareRobustCommandd[1]%
oalign#1crhidewidthscalebox0.5textbullethidewidthcr%

makeatletter
newcommandds[1]%
@tfornext:=#1dodnext%

makeatother

begindocument

xdddsdax

xdsdsax

enddocument


enter image description here



What does @tfor do? Its syntax is



@tfor<scratch macro>:=<tokens>do<code>


The scratch macro is traditionally next, but it can be anything. The <tokens> part is any (brace balanced) list of tokens. In the loop, LaTeX essentially does def<scratch macro><next token>, so



@tfornext:=dsadodnext


will perform



defnextddnextdefnextsdnextdefnextadnext


However, with @tfornext:=d sadodnext we will just obtain



defnextddnextdefnextsadnext


Explicit space tokens are ignored and braced groups of tokens are treated as one.



The expl3 analog is tl_map_inline:nn:



documentclassarticle
usepackagexparse
usepackagegraphicx

letdrelax
DeclareRobustCommandd[1]%
oalign#1crhidewidthscalebox0.5textbullethidewidthcr%


ExplSyntaxOn
NewDocumentCommanddsm

tl_map_inline:n #1 d ##1

ExplSyntaxOff

begindocument

xdddsdax

xdsdsax

xdsd sabcx

enddocument


No scratch macro is used: the current item in the loop is denoted by #1 (which becomes ##1 in the body of a definition, as usual).



In this particular case where just a single command is applied with the current item as argument, one can use tl_map_function:nN:



NewDocumentCommanddsm

tl_map_function:n #1 d



which has the same effect and is shorter. It can also appear in a full expansion context (not for this particular case, because of d).



enter image description here







share|improve this answer














share|improve this answer



share|improve this answer








edited 23 mins ago

























answered Jul 1 '15 at 16:38









egregegreg

736k8919353261




736k8919353261












  • It would be great to have an explanation of @tfor, especially since it's not defined in plain TeX

    – jpaugh
    Apr 27 '17 at 2:53

















  • It would be great to have an explanation of @tfor, especially since it's not defined in plain TeX

    – jpaugh
    Apr 27 '17 at 2:53
















It would be great to have an explanation of @tfor, especially since it's not defined in plain TeX

– jpaugh
Apr 27 '17 at 2:53





It would be great to have an explanation of @tfor, especially since it's not defined in plain TeX

– jpaugh
Apr 27 '17 at 2:53











5














This solution allows word wrap and handles spaces between words. In addition, the [w] option allows the task to be performed on each word, rather than each character.'



In the MWE, I demonstrate with variously defined tasks:



  1. overstrike each character (2 different settings)


  2. place a dot under each character


  3. place a semicolon under each word


  4. apply extra intercharacter space


  5. apply extra interword space.


The task is defined in charop for characters and wordop for words, while the chariterate[] macro does the iteration. Here is the MWE:



% WHILE THIS EXAMPLE IS SET UP FOR BOLDING A CALLIGRAPHIC FONT
% ITS GENERAL USE IS TO DO SOMETHING ON EACH char OF ITS ARGUMENT, ALLOWING LINE WRAP
% THE [W] OPTION TO chariterate DOES SOMETHING TO EACH WORD.
documentclass[10pt,a4paper,BCOR10mm,DIV11,toc=listof,parskip=full, openany]scrbook
usepackagestackengine
newcommandchariterate[2][c]if w#1worditeratehelper#2 relaxrelaxelse
chariteratehelpA#2 relaxrelaxfi
defchariteratehelpA#1 #2relax%
chariteratehelpB#1relaxrelax%
ifxrelax#2else chariteratehelpA#2relaxfi

defchariteratehelpB#1#2relax%
charop#1%
ifxrelax#2else
chariteratehelpB#2relax%
fi

defworditeratehelper#1 #2relax%
wordop#1%
ifxrelax#2else worditeratehelper#2relaxfi

defcharop#1#1
defwordop#1#1
% THIS EXAMPLE ARTIFICIALLY BOLDS EACH char WITH A SHIFTED OVERSTRIKE
defcharopA%
%defuseanchorwidthT%
defstacktypeL%
defstackalignmentl%
defcalup.2pt%
defcalover.15pt%
renewcommandcharop[1]stackon[calup]##1kerncalover##1%

% HERE'S AN EXAMPLE PLACING DOT UNDER EACH char
defcharopB%
defuseanchorwidthT%
defstacktypeL%
defstackalignmentc%
renewcommandcharop[1]stackunder[3pt]##1.%

% EXTRA INTER-CHARACTER SPACE
defcharopCrenewcommandcharop[1]##1,
% HERE'S AN EXAMPLE PLACING DOT UNDER EACH WORD
defwordopA%
renewcommandwordop[1]defstackalignmentcstackunder[3pt]##1;

% EXTRA INTER-WORD SPACE
defwordopBrenewcommandwordop[1]##1
%
newenvironmentcalligraphic%
fontencodingT1fontfamilypzcfontseriesmfontshapeitfontsize12pt12ptselectfont%
renewcommand*sectfontnormalcolorusefontT1pzcmit
begindocument
charopA
begincalligraphic
Test textbfthis is not boldpar
Test chariteratethis is bold with .2pt up shift and .15pt right shiftpar
defcalup.0pt
defcalover.2pt
Test chariteratethis is bold with .0pt up shift and .2pt right shiftpar
chariteratecvxc This is a test. This is a test. This is a test. This is a test.
This is a test. This is a test. This is a test. This is a test. This is a
test. This is a test. This is a test. This fdsfsd is a test. This is a test.
This is a test. This is a test. This is adfsdf test. This is a test.par
endcalligraphicpar
charopB
wordopA
chariterateThis is doing something to each character.par
chariterate[w]This is doing something to each word.par
chariterateIch bin m"ude.
chariterate[w]Ich bin m"ude.par
charopC
wordopB
chariterateThis is doing something to each character.par
chariterate[w]This is doing something to each word.par
enddocument


enter image description here



In the most simple incarnation, to do merely underdots on characters alone, the code can be greatly reduced:



documentclassarticle
usepackagestackengine
newcommandchariterate[2][c]if w#1worditeratehelper#2 relaxrelaxelse
chariteratehelpA#2 relaxrelaxfi
defchariteratehelpA#1 #2relax%
chariteratehelpB#1relaxrelax%
ifxrelax#2else chariteratehelpA#2relaxfi

defchariteratehelpB#1#2relax%
charop#1%
ifxrelax#2else
chariteratehelpB#2relax%
fi

defworditeratehelper#1 #2relax%
wordop#1%
ifxrelax#2else worditeratehelper#2relaxfi

defuseanchorwidthT%
defstacktypeL%
defstackalignmentc%
newcommandcharop[1]stackunder[3pt]#1.%
defwordop#1#1
begindocument
chariterateThis is doing something to each character.
This is doing something to each character.
This is doing something to each character.par
enddocument





share|improve this answer

























  • Thanks, that may be useful for Chinese fonts also, when they don't provide the bold fonts.

    – Yan King Yin
    Jul 6 '15 at 16:28











  • Extremely useful! To ensure that also bigger fontsizes like headings look good, I'd suggest to define the length for stackunder in ex though.

    – Florian
    Oct 14 '17 at 11:37















5














This solution allows word wrap and handles spaces between words. In addition, the [w] option allows the task to be performed on each word, rather than each character.'



In the MWE, I demonstrate with variously defined tasks:



  1. overstrike each character (2 different settings)


  2. place a dot under each character


  3. place a semicolon under each word


  4. apply extra intercharacter space


  5. apply extra interword space.


The task is defined in charop for characters and wordop for words, while the chariterate[] macro does the iteration. Here is the MWE:



% WHILE THIS EXAMPLE IS SET UP FOR BOLDING A CALLIGRAPHIC FONT
% ITS GENERAL USE IS TO DO SOMETHING ON EACH char OF ITS ARGUMENT, ALLOWING LINE WRAP
% THE [W] OPTION TO chariterate DOES SOMETHING TO EACH WORD.
documentclass[10pt,a4paper,BCOR10mm,DIV11,toc=listof,parskip=full, openany]scrbook
usepackagestackengine
newcommandchariterate[2][c]if w#1worditeratehelper#2 relaxrelaxelse
chariteratehelpA#2 relaxrelaxfi
defchariteratehelpA#1 #2relax%
chariteratehelpB#1relaxrelax%
ifxrelax#2else chariteratehelpA#2relaxfi

defchariteratehelpB#1#2relax%
charop#1%
ifxrelax#2else
chariteratehelpB#2relax%
fi

defworditeratehelper#1 #2relax%
wordop#1%
ifxrelax#2else worditeratehelper#2relaxfi

defcharop#1#1
defwordop#1#1
% THIS EXAMPLE ARTIFICIALLY BOLDS EACH char WITH A SHIFTED OVERSTRIKE
defcharopA%
%defuseanchorwidthT%
defstacktypeL%
defstackalignmentl%
defcalup.2pt%
defcalover.15pt%
renewcommandcharop[1]stackon[calup]##1kerncalover##1%

% HERE'S AN EXAMPLE PLACING DOT UNDER EACH char
defcharopB%
defuseanchorwidthT%
defstacktypeL%
defstackalignmentc%
renewcommandcharop[1]stackunder[3pt]##1.%

% EXTRA INTER-CHARACTER SPACE
defcharopCrenewcommandcharop[1]##1,
% HERE'S AN EXAMPLE PLACING DOT UNDER EACH WORD
defwordopA%
renewcommandwordop[1]defstackalignmentcstackunder[3pt]##1;

% EXTRA INTER-WORD SPACE
defwordopBrenewcommandwordop[1]##1
%
newenvironmentcalligraphic%
fontencodingT1fontfamilypzcfontseriesmfontshapeitfontsize12pt12ptselectfont%
renewcommand*sectfontnormalcolorusefontT1pzcmit
begindocument
charopA
begincalligraphic
Test textbfthis is not boldpar
Test chariteratethis is bold with .2pt up shift and .15pt right shiftpar
defcalup.0pt
defcalover.2pt
Test chariteratethis is bold with .0pt up shift and .2pt right shiftpar
chariteratecvxc This is a test. This is a test. This is a test. This is a test.
This is a test. This is a test. This is a test. This is a test. This is a
test. This is a test. This is a test. This fdsfsd is a test. This is a test.
This is a test. This is a test. This is adfsdf test. This is a test.par
endcalligraphicpar
charopB
wordopA
chariterateThis is doing something to each character.par
chariterate[w]This is doing something to each word.par
chariterateIch bin m"ude.
chariterate[w]Ich bin m"ude.par
charopC
wordopB
chariterateThis is doing something to each character.par
chariterate[w]This is doing something to each word.par
enddocument


enter image description here



In the most simple incarnation, to do merely underdots on characters alone, the code can be greatly reduced:



documentclassarticle
usepackagestackengine
newcommandchariterate[2][c]if w#1worditeratehelper#2 relaxrelaxelse
chariteratehelpA#2 relaxrelaxfi
defchariteratehelpA#1 #2relax%
chariteratehelpB#1relaxrelax%
ifxrelax#2else chariteratehelpA#2relaxfi

defchariteratehelpB#1#2relax%
charop#1%
ifxrelax#2else
chariteratehelpB#2relax%
fi

defworditeratehelper#1 #2relax%
wordop#1%
ifxrelax#2else worditeratehelper#2relaxfi

defuseanchorwidthT%
defstacktypeL%
defstackalignmentc%
newcommandcharop[1]stackunder[3pt]#1.%
defwordop#1#1
begindocument
chariterateThis is doing something to each character.
This is doing something to each character.
This is doing something to each character.par
enddocument





share|improve this answer

























  • Thanks, that may be useful for Chinese fonts also, when they don't provide the bold fonts.

    – Yan King Yin
    Jul 6 '15 at 16:28











  • Extremely useful! To ensure that also bigger fontsizes like headings look good, I'd suggest to define the length for stackunder in ex though.

    – Florian
    Oct 14 '17 at 11:37













5












5








5







This solution allows word wrap and handles spaces between words. In addition, the [w] option allows the task to be performed on each word, rather than each character.'



In the MWE, I demonstrate with variously defined tasks:



  1. overstrike each character (2 different settings)


  2. place a dot under each character


  3. place a semicolon under each word


  4. apply extra intercharacter space


  5. apply extra interword space.


The task is defined in charop for characters and wordop for words, while the chariterate[] macro does the iteration. Here is the MWE:



% WHILE THIS EXAMPLE IS SET UP FOR BOLDING A CALLIGRAPHIC FONT
% ITS GENERAL USE IS TO DO SOMETHING ON EACH char OF ITS ARGUMENT, ALLOWING LINE WRAP
% THE [W] OPTION TO chariterate DOES SOMETHING TO EACH WORD.
documentclass[10pt,a4paper,BCOR10mm,DIV11,toc=listof,parskip=full, openany]scrbook
usepackagestackengine
newcommandchariterate[2][c]if w#1worditeratehelper#2 relaxrelaxelse
chariteratehelpA#2 relaxrelaxfi
defchariteratehelpA#1 #2relax%
chariteratehelpB#1relaxrelax%
ifxrelax#2else chariteratehelpA#2relaxfi

defchariteratehelpB#1#2relax%
charop#1%
ifxrelax#2else
chariteratehelpB#2relax%
fi

defworditeratehelper#1 #2relax%
wordop#1%
ifxrelax#2else worditeratehelper#2relaxfi

defcharop#1#1
defwordop#1#1
% THIS EXAMPLE ARTIFICIALLY BOLDS EACH char WITH A SHIFTED OVERSTRIKE
defcharopA%
%defuseanchorwidthT%
defstacktypeL%
defstackalignmentl%
defcalup.2pt%
defcalover.15pt%
renewcommandcharop[1]stackon[calup]##1kerncalover##1%

% HERE'S AN EXAMPLE PLACING DOT UNDER EACH char
defcharopB%
defuseanchorwidthT%
defstacktypeL%
defstackalignmentc%
renewcommandcharop[1]stackunder[3pt]##1.%

% EXTRA INTER-CHARACTER SPACE
defcharopCrenewcommandcharop[1]##1,
% HERE'S AN EXAMPLE PLACING DOT UNDER EACH WORD
defwordopA%
renewcommandwordop[1]defstackalignmentcstackunder[3pt]##1;

% EXTRA INTER-WORD SPACE
defwordopBrenewcommandwordop[1]##1
%
newenvironmentcalligraphic%
fontencodingT1fontfamilypzcfontseriesmfontshapeitfontsize12pt12ptselectfont%
renewcommand*sectfontnormalcolorusefontT1pzcmit
begindocument
charopA
begincalligraphic
Test textbfthis is not boldpar
Test chariteratethis is bold with .2pt up shift and .15pt right shiftpar
defcalup.0pt
defcalover.2pt
Test chariteratethis is bold with .0pt up shift and .2pt right shiftpar
chariteratecvxc This is a test. This is a test. This is a test. This is a test.
This is a test. This is a test. This is a test. This is a test. This is a
test. This is a test. This is a test. This fdsfsd is a test. This is a test.
This is a test. This is a test. This is adfsdf test. This is a test.par
endcalligraphicpar
charopB
wordopA
chariterateThis is doing something to each character.par
chariterate[w]This is doing something to each word.par
chariterateIch bin m"ude.
chariterate[w]Ich bin m"ude.par
charopC
wordopB
chariterateThis is doing something to each character.par
chariterate[w]This is doing something to each word.par
enddocument


enter image description here



In the most simple incarnation, to do merely underdots on characters alone, the code can be greatly reduced:



documentclassarticle
usepackagestackengine
newcommandchariterate[2][c]if w#1worditeratehelper#2 relaxrelaxelse
chariteratehelpA#2 relaxrelaxfi
defchariteratehelpA#1 #2relax%
chariteratehelpB#1relaxrelax%
ifxrelax#2else chariteratehelpA#2relaxfi

defchariteratehelpB#1#2relax%
charop#1%
ifxrelax#2else
chariteratehelpB#2relax%
fi

defworditeratehelper#1 #2relax%
wordop#1%
ifxrelax#2else worditeratehelper#2relaxfi

defuseanchorwidthT%
defstacktypeL%
defstackalignmentc%
newcommandcharop[1]stackunder[3pt]#1.%
defwordop#1#1
begindocument
chariterateThis is doing something to each character.
This is doing something to each character.
This is doing something to each character.par
enddocument





share|improve this answer















This solution allows word wrap and handles spaces between words. In addition, the [w] option allows the task to be performed on each word, rather than each character.'



In the MWE, I demonstrate with variously defined tasks:



  1. overstrike each character (2 different settings)


  2. place a dot under each character


  3. place a semicolon under each word


  4. apply extra intercharacter space


  5. apply extra interword space.


The task is defined in charop for characters and wordop for words, while the chariterate[] macro does the iteration. Here is the MWE:



% WHILE THIS EXAMPLE IS SET UP FOR BOLDING A CALLIGRAPHIC FONT
% ITS GENERAL USE IS TO DO SOMETHING ON EACH char OF ITS ARGUMENT, ALLOWING LINE WRAP
% THE [W] OPTION TO chariterate DOES SOMETHING TO EACH WORD.
documentclass[10pt,a4paper,BCOR10mm,DIV11,toc=listof,parskip=full, openany]scrbook
usepackagestackengine
newcommandchariterate[2][c]if w#1worditeratehelper#2 relaxrelaxelse
chariteratehelpA#2 relaxrelaxfi
defchariteratehelpA#1 #2relax%
chariteratehelpB#1relaxrelax%
ifxrelax#2else chariteratehelpA#2relaxfi

defchariteratehelpB#1#2relax%
charop#1%
ifxrelax#2else
chariteratehelpB#2relax%
fi

defworditeratehelper#1 #2relax%
wordop#1%
ifxrelax#2else worditeratehelper#2relaxfi

defcharop#1#1
defwordop#1#1
% THIS EXAMPLE ARTIFICIALLY BOLDS EACH char WITH A SHIFTED OVERSTRIKE
defcharopA%
%defuseanchorwidthT%
defstacktypeL%
defstackalignmentl%
defcalup.2pt%
defcalover.15pt%
renewcommandcharop[1]stackon[calup]##1kerncalover##1%

% HERE'S AN EXAMPLE PLACING DOT UNDER EACH char
defcharopB%
defuseanchorwidthT%
defstacktypeL%
defstackalignmentc%
renewcommandcharop[1]stackunder[3pt]##1.%

% EXTRA INTER-CHARACTER SPACE
defcharopCrenewcommandcharop[1]##1,
% HERE'S AN EXAMPLE PLACING DOT UNDER EACH WORD
defwordopA%
renewcommandwordop[1]defstackalignmentcstackunder[3pt]##1;

% EXTRA INTER-WORD SPACE
defwordopBrenewcommandwordop[1]##1
%
newenvironmentcalligraphic%
fontencodingT1fontfamilypzcfontseriesmfontshapeitfontsize12pt12ptselectfont%
renewcommand*sectfontnormalcolorusefontT1pzcmit
begindocument
charopA
begincalligraphic
Test textbfthis is not boldpar
Test chariteratethis is bold with .2pt up shift and .15pt right shiftpar
defcalup.0pt
defcalover.2pt
Test chariteratethis is bold with .0pt up shift and .2pt right shiftpar
chariteratecvxc This is a test. This is a test. This is a test. This is a test.
This is a test. This is a test. This is a test. This is a test. This is a
test. This is a test. This is a test. This fdsfsd is a test. This is a test.
This is a test. This is a test. This is adfsdf test. This is a test.par
endcalligraphicpar
charopB
wordopA
chariterateThis is doing something to each character.par
chariterate[w]This is doing something to each word.par
chariterateIch bin m"ude.
chariterate[w]Ich bin m"ude.par
charopC
wordopB
chariterateThis is doing something to each character.par
chariterate[w]This is doing something to each word.par
enddocument


enter image description here



In the most simple incarnation, to do merely underdots on characters alone, the code can be greatly reduced:



documentclassarticle
usepackagestackengine
newcommandchariterate[2][c]if w#1worditeratehelper#2 relaxrelaxelse
chariteratehelpA#2 relaxrelaxfi
defchariteratehelpA#1 #2relax%
chariteratehelpB#1relaxrelax%
ifxrelax#2else chariteratehelpA#2relaxfi

defchariteratehelpB#1#2relax%
charop#1%
ifxrelax#2else
chariteratehelpB#2relax%
fi

defworditeratehelper#1 #2relax%
wordop#1%
ifxrelax#2else worditeratehelper#2relaxfi

defuseanchorwidthT%
defstacktypeL%
defstackalignmentc%
newcommandcharop[1]stackunder[3pt]#1.%
defwordop#1#1
begindocument
chariterateThis is doing something to each character.
This is doing something to each character.
This is doing something to each character.par
enddocument






share|improve this answer














share|improve this answer



share|improve this answer








edited Jul 1 '15 at 18:12

























answered Jul 1 '15 at 17:59









Steven B. SegletesSteven B. Segletes

163k9207419




163k9207419












  • Thanks, that may be useful for Chinese fonts also, when they don't provide the bold fonts.

    – Yan King Yin
    Jul 6 '15 at 16:28











  • Extremely useful! To ensure that also bigger fontsizes like headings look good, I'd suggest to define the length for stackunder in ex though.

    – Florian
    Oct 14 '17 at 11:37

















  • Thanks, that may be useful for Chinese fonts also, when they don't provide the bold fonts.

    – Yan King Yin
    Jul 6 '15 at 16:28











  • Extremely useful! To ensure that also bigger fontsizes like headings look good, I'd suggest to define the length for stackunder in ex though.

    – Florian
    Oct 14 '17 at 11:37
















Thanks, that may be useful for Chinese fonts also, when they don't provide the bold fonts.

– Yan King Yin
Jul 6 '15 at 16:28





Thanks, that may be useful for Chinese fonts also, when they don't provide the bold fonts.

– Yan King Yin
Jul 6 '15 at 16:28













Extremely useful! To ensure that also bigger fontsizes like headings look good, I'd suggest to define the length for stackunder in ex though.

– Florian
Oct 14 '17 at 11:37





Extremely useful! To ensure that also bigger fontsizes like headings look good, I'd suggest to define the length for stackunder in ex though.

– Florian
Oct 14 '17 at 11:37

















draft saved

draft discarded
















































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.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f253203%2fhow-to-repeat-over-all-characters-in-a-string%23new-answer', 'question_page');

);

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







Popular posts from this blog

Isabella Eugénie Boyer Biographie | Références | Menu de navigationmodifiermodifier le codeComparator to Compute the Relative Value of a U.S. Dollar Amount – 1774 to Present.

Lioubotyn Sommaire Géographie | Histoire | Population | Notes et références | Liens externes | Menu de navigationlubotin.kharkov.uamodifier« Recensements et estimations de la population depuis 1897 »« Office des statistiques d'Ukraine : population au 1er janvier 2010, 2011 et 2012 »« Office des statistiques d'Ukraine : population au 1er janvier 2011, 2012 et 2013 »Informations officiellesCartes topographiquesCarte routièrem

Mpande kaSenzangakhona Biographie | Références | Menu de navigationmodifierMpande kaSenzangakhonavoir la liste des auteursm