Macro expansion inside hrefUsing the doi package with hyperref pagebacklinks=trueUsing href inside...
How can I play a serial killer in a party of good PCs?
Most demanding German Newspapers
Visualize manifold specified by equalities
Why don't key signatures indicate the tonic?
How to deal with possible delayed baggage?
TikZ graph edges not drawn nicely
systemd service won't start nodejs
Early credit roll before the end of the film
How to politely refuse in-office gym instructor for steroids and protein
Current across a wire with zero potential difference
A starship is travelling at 0.9c and collides with a small rock. Will it leave a clean hole through, or will more happen?
Why is it that Bernie Sanders is always called a "socialist"?
Can 5 Aarakocra PCs summon an Air Elemental?
What will happen if Parliament votes "no" on each of the Brexit-related votes to be held on the 12th, 13th and 14th of March?
Definition of "atomic object"
What makes papers publishable in top-tier journals?
Changing the laptop's CPU. Should I reinstall Linux?
Is there a lava-breathing lizard creature (that could be worshipped by a cult) in 5e?
What language shall they sing in?
What is a good reason for every spaceship to carry a weapon on board?
Why avoid shared user accounts?
How do you voice extended chords?
What happens when I Twin Life Transference?
What is the difference between "...", '...', $'...', and $"..." quotes?
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 55 mins 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