Macro expansion inside hrefUsing the doi package with hyperref pagebacklinks=trueUsing href inside...
What is the wife of a henpecked husband called?
What language shall they sing in?
Airplane generations - how does it work?
Citing paid articles from illegal web sharing
In Linux what happens if 1000 files in a directory are moved to another location while another 300 files were added to the source directory?
Why did Democrats in the Senate oppose the Born-Alive Abortion Survivors Protection Act?
Could an Apollo mission be possible if Moon would be Earth like?
How to not let the Identify spell spoil everything?
Eww, those bytes are gross
What happens when I Twin Life Transference?
Visualize manifold specified by equalities
Is a new boolean field better than null reference when a value can be meaningfully absent?
What will happen if I transfer large sums of money into my bank account from a pre-paid debit card or gift card?
Treasure Hunt Riddle
Can I announce prefix 161.117.25.0/24 even though I don't have all of /24 IPs
Why didn't Tom Riddle take the presence of Fawkes and the Sorting Hat as more of a threat?
Non-Cancer terminal illness that can affect young (age 10-13) girls?
How to access internet and run apt-get through a middle server?
Is there a verb that means to inject with poison?
Changing the laptop's CPU. Should I reinstall Linux?
What makes papers publishable in top-tier journals?
What is the difference between rolling more dice versus fewer dice?
How would you say "I like to go bowling" and other suru verbs?
Definition of "atomic object"
Macro expansion inside href
Using the doi package with hyperref pagebacklinks=trueUsing href inside footnoteMacro expansion and href with hyperlinkinput inside hrefReplacing a substring from a commandProblem with nested IfSubStr callshref not ignoring special characters inside macrocitefield inside of hrefFile link with space in hrefwhy href inside endnotes do not works
I want to make a shortcut for
href{tel:0123456789}{01,23,45,67,89}
I can use StrSubstitute from the xstring package as
StrSubstitute{01 23 45 67 89}{ }{,}
inside the second argument to href. But the same thing with
StrSubstitute{01 23 45 67 89}{ }{}
in the first argument won't work.
I think, I understand that this is an issue with macro expansion order. But how can I get LaTeX to first expand StrSubstitute into a string that can be parsed by href?
Here is a minimal example of what I actually want to achieve:
documentclass{minimal}
usepackage{xstring}
usepackage{hyperref}
newcommandphone[1]{href{tel:StrSubstitute{#1}{ }{}}{StrSubstitute{#1}{ }{,}}}
begin{document}
href{tel:0123456789}{01,23,45,67,89}
href{StrSubstitute{01 23 45 67 89}{ }{}}{StrSubstitute{01 23 45 67 89}{ }{,}}
phone{01 23 45 67 89}
end{document}
hyperref xstring href
add a comment |
I want to make a shortcut for
href{tel:0123456789}{01,23,45,67,89}
I can use StrSubstitute from the xstring package as
StrSubstitute{01 23 45 67 89}{ }{,}
inside the second argument to href. But the same thing with
StrSubstitute{01 23 45 67 89}{ }{}
in the first argument won't work.
I think, I understand that this is an issue with macro expansion order. But how can I get LaTeX to first expand StrSubstitute into a string that can be parsed by href?
Here is a minimal example of what I actually want to achieve:
documentclass{minimal}
usepackage{xstring}
usepackage{hyperref}
newcommandphone[1]{href{tel:StrSubstitute{#1}{ }{}}{StrSubstitute{#1}{ }{,}}}
begin{document}
href{tel:0123456789}{01,23,45,67,89}
href{StrSubstitute{01 23 45 67 89}{ }{}}{StrSubstitute{01 23 45 67 89}{ }{,}}
phone{01 23 45 67 89}
end{document}
hyperref xstring href
add a comment |
I want to make a shortcut for
href{tel:0123456789}{01,23,45,67,89}
I can use StrSubstitute from the xstring package as
StrSubstitute{01 23 45 67 89}{ }{,}
inside the second argument to href. But the same thing with
StrSubstitute{01 23 45 67 89}{ }{}
in the first argument won't work.
I think, I understand that this is an issue with macro expansion order. But how can I get LaTeX to first expand StrSubstitute into a string that can be parsed by href?
Here is a minimal example of what I actually want to achieve:
documentclass{minimal}
usepackage{xstring}
usepackage{hyperref}
newcommandphone[1]{href{tel:StrSubstitute{#1}{ }{}}{StrSubstitute{#1}{ }{,}}}
begin{document}
href{tel:0123456789}{01,23,45,67,89}
href{StrSubstitute{01 23 45 67 89}{ }{}}{StrSubstitute{01 23 45 67 89}{ }{,}}
phone{01 23 45 67 89}
end{document}
hyperref xstring href
I want to make a shortcut for
href{tel:0123456789}{01,23,45,67,89}
I can use StrSubstitute from the xstring package as
StrSubstitute{01 23 45 67 89}{ }{,}
inside the second argument to href. But the same thing with
StrSubstitute{01 23 45 67 89}{ }{}
in the first argument won't work.
I think, I understand that this is an issue with macro expansion order. But how can I get LaTeX to first expand StrSubstitute into a string that can be parsed by href?
Here is a minimal example of what I actually want to achieve:
documentclass{minimal}
usepackage{xstring}
usepackage{hyperref}
newcommandphone[1]{href{tel:StrSubstitute{#1}{ }{}}{StrSubstitute{#1}{ }{,}}}
begin{document}
href{tel:0123456789}{01,23,45,67,89}
href{StrSubstitute{01 23 45 67 89}{ }{}}{StrSubstitute{01 23 45 67 89}{ }{,}}
phone{01 23 45 67 89}
end{document}
hyperref xstring href
hyperref xstring href
asked 2 hours ago
DLichtiDLichti
605
605
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
You can't use StrSubstitute in those places, because it doesn't produce the string after the substitution, but rather a fairly complicated set of instructions to produce that string.
A more complicated solution that avoids the need to input spaces between pairs of digits, so it will work even if you forget them.
documentclass{article}
usepackage{xparse}
usepackage{hyperref}
ExplSyntaxOn
NewDocumentCommand{phone}{m}
{
dlichti_phone:n { #1 }
}
tl_new:N l_dlichti_phone_href_tl
tl_new:N l_dlichti_phone_print_tl
cs_new_protected:Nn dlichti_phone:n
{
tl_set:Nx l_dlichti_phone_href_tl { #1 }
% remove all spaces
tl_replace_all:Nnn l_dlichti_phone_href_tl { ~ } { }
% save a copy
tl_set_eq:NN l_dlichti_phone_print_tl l_dlichti_phone_href_tl
% insert a thin space between any pair of digits
regex_replace_all:nnN
{ ([0-9][0-9]) } % two digits followed by another digit
{ 1c{,} } % the same with , in between
l_dlichti_phone_print_tl
% remove the trailing ,
regex_replace_once:nnN { c{,} Z } { } l_dlichti_phone_print_tl
dlichti_phone_href:VVV
c_colon_str
l_dlichti_phone_href_tl
l_dlichti_phone_print_tl
}
cs_new_protected:Nn dlichti_phone_href:nnn
{
href{tel#1#2}{#3}
}
cs_generate_variant:Nn dlichti_phone_href:nnn { VVV }
ExplSyntaxOff
begin{document}
phone{01 23 45 67 89}
phone{0123456789}
end{document}

add a comment |
Expand the string substitution first by storing it in an argument, which you can then use with hyperref's href:
documentclass{article}
usepackage{xstring}
usepackage{hyperref}
newcommandphone[1]{%
StrSubstitute{#1}{ }{}[firstarg]% Store first substitution in firstarg
StrSubstitute{#1}{ }{,}[secondarg]% Store second substitution in secondarg
href{tel:firstarg}{secondarg}% Use stored arguments in href
}
begin{document}
href{tel:0123456789}{01,23,45,67,89}
phone{01 23 45 67 89}
end{document}
add a comment |
The xstring commands are not expandable so can't in general be used inline in other commands. You can use a simple expandable replacement here.
documentclass{minimal}
usepackage{hyperref}
makeatletter
defzza#1 {#1zza}
defzzb#1 {#1,zzb}
newcommandphone[1]{{def!##1{}def$##1##2{}href{tel:zza#1! }{zzb#1$ }}}
makeatother
begin{document}
href{tel:0123456789}{01,23,45,67,89}
phone{01 23 45 67 89}
end{document}
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%2f476835%2fmacro-expansion-inside-href%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can't use StrSubstitute in those places, because it doesn't produce the string after the substitution, but rather a fairly complicated set of instructions to produce that string.
A more complicated solution that avoids the need to input spaces between pairs of digits, so it will work even if you forget them.
documentclass{article}
usepackage{xparse}
usepackage{hyperref}
ExplSyntaxOn
NewDocumentCommand{phone}{m}
{
dlichti_phone:n { #1 }
}
tl_new:N l_dlichti_phone_href_tl
tl_new:N l_dlichti_phone_print_tl
cs_new_protected:Nn dlichti_phone:n
{
tl_set:Nx l_dlichti_phone_href_tl { #1 }
% remove all spaces
tl_replace_all:Nnn l_dlichti_phone_href_tl { ~ } { }
% save a copy
tl_set_eq:NN l_dlichti_phone_print_tl l_dlichti_phone_href_tl
% insert a thin space between any pair of digits
regex_replace_all:nnN
{ ([0-9][0-9]) } % two digits followed by another digit
{ 1c{,} } % the same with , in between
l_dlichti_phone_print_tl
% remove the trailing ,
regex_replace_once:nnN { c{,} Z } { } l_dlichti_phone_print_tl
dlichti_phone_href:VVV
c_colon_str
l_dlichti_phone_href_tl
l_dlichti_phone_print_tl
}
cs_new_protected:Nn dlichti_phone_href:nnn
{
href{tel#1#2}{#3}
}
cs_generate_variant:Nn dlichti_phone_href:nnn { VVV }
ExplSyntaxOff
begin{document}
phone{01 23 45 67 89}
phone{0123456789}
end{document}

add a comment |
You can't use StrSubstitute in those places, because it doesn't produce the string after the substitution, but rather a fairly complicated set of instructions to produce that string.
A more complicated solution that avoids the need to input spaces between pairs of digits, so it will work even if you forget them.
documentclass{article}
usepackage{xparse}
usepackage{hyperref}
ExplSyntaxOn
NewDocumentCommand{phone}{m}
{
dlichti_phone:n { #1 }
}
tl_new:N l_dlichti_phone_href_tl
tl_new:N l_dlichti_phone_print_tl
cs_new_protected:Nn dlichti_phone:n
{
tl_set:Nx l_dlichti_phone_href_tl { #1 }
% remove all spaces
tl_replace_all:Nnn l_dlichti_phone_href_tl { ~ } { }
% save a copy
tl_set_eq:NN l_dlichti_phone_print_tl l_dlichti_phone_href_tl
% insert a thin space between any pair of digits
regex_replace_all:nnN
{ ([0-9][0-9]) } % two digits followed by another digit
{ 1c{,} } % the same with , in between
l_dlichti_phone_print_tl
% remove the trailing ,
regex_replace_once:nnN { c{,} Z } { } l_dlichti_phone_print_tl
dlichti_phone_href:VVV
c_colon_str
l_dlichti_phone_href_tl
l_dlichti_phone_print_tl
}
cs_new_protected:Nn dlichti_phone_href:nnn
{
href{tel#1#2}{#3}
}
cs_generate_variant:Nn dlichti_phone_href:nnn { VVV }
ExplSyntaxOff
begin{document}
phone{01 23 45 67 89}
phone{0123456789}
end{document}

add a comment |
You can't use StrSubstitute in those places, because it doesn't produce the string after the substitution, but rather a fairly complicated set of instructions to produce that string.
A more complicated solution that avoids the need to input spaces between pairs of digits, so it will work even if you forget them.
documentclass{article}
usepackage{xparse}
usepackage{hyperref}
ExplSyntaxOn
NewDocumentCommand{phone}{m}
{
dlichti_phone:n { #1 }
}
tl_new:N l_dlichti_phone_href_tl
tl_new:N l_dlichti_phone_print_tl
cs_new_protected:Nn dlichti_phone:n
{
tl_set:Nx l_dlichti_phone_href_tl { #1 }
% remove all spaces
tl_replace_all:Nnn l_dlichti_phone_href_tl { ~ } { }
% save a copy
tl_set_eq:NN l_dlichti_phone_print_tl l_dlichti_phone_href_tl
% insert a thin space between any pair of digits
regex_replace_all:nnN
{ ([0-9][0-9]) } % two digits followed by another digit
{ 1c{,} } % the same with , in between
l_dlichti_phone_print_tl
% remove the trailing ,
regex_replace_once:nnN { c{,} Z } { } l_dlichti_phone_print_tl
dlichti_phone_href:VVV
c_colon_str
l_dlichti_phone_href_tl
l_dlichti_phone_print_tl
}
cs_new_protected:Nn dlichti_phone_href:nnn
{
href{tel#1#2}{#3}
}
cs_generate_variant:Nn dlichti_phone_href:nnn { VVV }
ExplSyntaxOff
begin{document}
phone{01 23 45 67 89}
phone{0123456789}
end{document}

You can't use StrSubstitute in those places, because it doesn't produce the string after the substitution, but rather a fairly complicated set of instructions to produce that string.
A more complicated solution that avoids the need to input spaces between pairs of digits, so it will work even if you forget them.
documentclass{article}
usepackage{xparse}
usepackage{hyperref}
ExplSyntaxOn
NewDocumentCommand{phone}{m}
{
dlichti_phone:n { #1 }
}
tl_new:N l_dlichti_phone_href_tl
tl_new:N l_dlichti_phone_print_tl
cs_new_protected:Nn dlichti_phone:n
{
tl_set:Nx l_dlichti_phone_href_tl { #1 }
% remove all spaces
tl_replace_all:Nnn l_dlichti_phone_href_tl { ~ } { }
% save a copy
tl_set_eq:NN l_dlichti_phone_print_tl l_dlichti_phone_href_tl
% insert a thin space between any pair of digits
regex_replace_all:nnN
{ ([0-9][0-9]) } % two digits followed by another digit
{ 1c{,} } % the same with , in between
l_dlichti_phone_print_tl
% remove the trailing ,
regex_replace_once:nnN { c{,} Z } { } l_dlichti_phone_print_tl
dlichti_phone_href:VVV
c_colon_str
l_dlichti_phone_href_tl
l_dlichti_phone_print_tl
}
cs_new_protected:Nn dlichti_phone_href:nnn
{
href{tel#1#2}{#3}
}
cs_generate_variant:Nn dlichti_phone_href:nnn { VVV }
ExplSyntaxOff
begin{document}
phone{01 23 45 67 89}
phone{0123456789}
end{document}

edited 1 hour ago
answered 1 hour ago
egregegreg
722k8719163217
722k8719163217
add a comment |
add a comment |
Expand the string substitution first by storing it in an argument, which you can then use with hyperref's href:
documentclass{article}
usepackage{xstring}
usepackage{hyperref}
newcommandphone[1]{%
StrSubstitute{#1}{ }{}[firstarg]% Store first substitution in firstarg
StrSubstitute{#1}{ }{,}[secondarg]% Store second substitution in secondarg
href{tel:firstarg}{secondarg}% Use stored arguments in href
}
begin{document}
href{tel:0123456789}{01,23,45,67,89}
phone{01 23 45 67 89}
end{document}
add a comment |
Expand the string substitution first by storing it in an argument, which you can then use with hyperref's href:
documentclass{article}
usepackage{xstring}
usepackage{hyperref}
newcommandphone[1]{%
StrSubstitute{#1}{ }{}[firstarg]% Store first substitution in firstarg
StrSubstitute{#1}{ }{,}[secondarg]% Store second substitution in secondarg
href{tel:firstarg}{secondarg}% Use stored arguments in href
}
begin{document}
href{tel:0123456789}{01,23,45,67,89}
phone{01 23 45 67 89}
end{document}
add a comment |
Expand the string substitution first by storing it in an argument, which you can then use with hyperref's href:
documentclass{article}
usepackage{xstring}
usepackage{hyperref}
newcommandphone[1]{%
StrSubstitute{#1}{ }{}[firstarg]% Store first substitution in firstarg
StrSubstitute{#1}{ }{,}[secondarg]% Store second substitution in secondarg
href{tel:firstarg}{secondarg}% Use stored arguments in href
}
begin{document}
href{tel:0123456789}{01,23,45,67,89}
phone{01 23 45 67 89}
end{document}
Expand the string substitution first by storing it in an argument, which you can then use with hyperref's href:
documentclass{article}
usepackage{xstring}
usepackage{hyperref}
newcommandphone[1]{%
StrSubstitute{#1}{ }{}[firstarg]% Store first substitution in firstarg
StrSubstitute{#1}{ }{,}[secondarg]% Store second substitution in secondarg
href{tel:firstarg}{secondarg}% Use stored arguments in href
}
begin{document}
href{tel:0123456789}{01,23,45,67,89}
phone{01 23 45 67 89}
end{document}
answered 1 hour ago
WernerWerner
445k699811686
445k699811686
add a comment |
add a comment |
The xstring commands are not expandable so can't in general be used inline in other commands. You can use a simple expandable replacement here.
documentclass{minimal}
usepackage{hyperref}
makeatletter
defzza#1 {#1zza}
defzzb#1 {#1,zzb}
newcommandphone[1]{{def!##1{}def$##1##2{}href{tel:zza#1! }{zzb#1$ }}}
makeatother
begin{document}
href{tel:0123456789}{01,23,45,67,89}
phone{01 23 45 67 89}
end{document}
add a comment |
The xstring commands are not expandable so can't in general be used inline in other commands. You can use a simple expandable replacement here.
documentclass{minimal}
usepackage{hyperref}
makeatletter
defzza#1 {#1zza}
defzzb#1 {#1,zzb}
newcommandphone[1]{{def!##1{}def$##1##2{}href{tel:zza#1! }{zzb#1$ }}}
makeatother
begin{document}
href{tel:0123456789}{01,23,45,67,89}
phone{01 23 45 67 89}
end{document}
add a comment |
The xstring commands are not expandable so can't in general be used inline in other commands. You can use a simple expandable replacement here.
documentclass{minimal}
usepackage{hyperref}
makeatletter
defzza#1 {#1zza}
defzzb#1 {#1,zzb}
newcommandphone[1]{{def!##1{}def$##1##2{}href{tel:zza#1! }{zzb#1$ }}}
makeatother
begin{document}
href{tel:0123456789}{01,23,45,67,89}
phone{01 23 45 67 89}
end{document}
The xstring commands are not expandable so can't in general be used inline in other commands. You can use a simple expandable replacement here.
documentclass{minimal}
usepackage{hyperref}
makeatletter
defzza#1 {#1zza}
defzzb#1 {#1,zzb}
newcommandphone[1]{{def!##1{}def$##1##2{}href{tel:zza#1! }{zzb#1$ }}}
makeatother
begin{document}
href{tel:0123456789}{01,23,45,67,89}
phone{01 23 45 67 89}
end{document}
edited 1 hour ago
answered 1 hour ago
David CarlisleDavid Carlisle
492k4111371885
492k4111371885
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%2f476835%2fmacro-expansion-inside-href%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