Hyphenation in LINK text












2














I use, in agreement with the post of SE, the command link.



documentclass[10pt]{article}
usepackage{bookmark}
usepackage[table]{xcolor}
usepackage{tabularx}

newcommand{link}[1]{%
{%
deftextbf##1{##1}%
deftextit##1{##1}%
deftextcolor##1##2{##2}%
defprotect##1##2{##2}%
edef_{string_}%
edef&{string&}%
xdeftmp{noexpandhref{#1}}}%
ttfamily%
tmp{#1}%
}

begin{document}

begin{tabularx}{linewidth}{|l|l|}
link{https://www.textcolor{blue}{longlink}.com/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/} & Long link descriptiontabularnewline
link{www.textcolor{blue}{longlinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglink}.net} & Long link descriptiontabularnewline
end{tabularx}

end{document}


and I get:



Compilation output



So… two questions:




  • How can I change the text of link to get the hyphenation on the slash character without the hyphen char?


and if there isn't any slash character




  • How can I change the text of link to get hyphenation anywhere but without the hyphen char?










share|improve this question
























  • Maybe tex.stackexchange.com/a/108003 can help you (i.e., the breakurl package with anythingbreaks option)?
    – Marijn
    5 hours ago










  • No, with usepackage[breaklinks=true]{hyperref} i get: Option clash for package hyperref, and sloppy doesn't work.
    – BnG
    5 hours ago










  • I've linked to a specific answer which does not mention the breaklinks option for hyperref, it uses a separate package for breaking links (called breakurl). Did you try that?
    – Marijn
    5 hours ago












  • I'm sorry, usepackage{breakurl} or usepackage[anythingbreaks]{breakurl} don't work either.
    – BnG
    5 hours ago








  • 1




    I tried it myself now and it does not work indeed - and many other possible solutions also seem to fail for this specific case. I hope someone here comes along to solve it.
    – Marijn
    5 hours ago
















2














I use, in agreement with the post of SE, the command link.



documentclass[10pt]{article}
usepackage{bookmark}
usepackage[table]{xcolor}
usepackage{tabularx}

newcommand{link}[1]{%
{%
deftextbf##1{##1}%
deftextit##1{##1}%
deftextcolor##1##2{##2}%
defprotect##1##2{##2}%
edef_{string_}%
edef&{string&}%
xdeftmp{noexpandhref{#1}}}%
ttfamily%
tmp{#1}%
}

begin{document}

begin{tabularx}{linewidth}{|l|l|}
link{https://www.textcolor{blue}{longlink}.com/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/} & Long link descriptiontabularnewline
link{www.textcolor{blue}{longlinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglink}.net} & Long link descriptiontabularnewline
end{tabularx}

end{document}


and I get:



Compilation output



So… two questions:




  • How can I change the text of link to get the hyphenation on the slash character without the hyphen char?


and if there isn't any slash character




  • How can I change the text of link to get hyphenation anywhere but without the hyphen char?










share|improve this question
























  • Maybe tex.stackexchange.com/a/108003 can help you (i.e., the breakurl package with anythingbreaks option)?
    – Marijn
    5 hours ago










  • No, with usepackage[breaklinks=true]{hyperref} i get: Option clash for package hyperref, and sloppy doesn't work.
    – BnG
    5 hours ago










  • I've linked to a specific answer which does not mention the breaklinks option for hyperref, it uses a separate package for breaking links (called breakurl). Did you try that?
    – Marijn
    5 hours ago












  • I'm sorry, usepackage{breakurl} or usepackage[anythingbreaks]{breakurl} don't work either.
    – BnG
    5 hours ago








  • 1




    I tried it myself now and it does not work indeed - and many other possible solutions also seem to fail for this specific case. I hope someone here comes along to solve it.
    – Marijn
    5 hours ago














2












2








2


1





I use, in agreement with the post of SE, the command link.



documentclass[10pt]{article}
usepackage{bookmark}
usepackage[table]{xcolor}
usepackage{tabularx}

newcommand{link}[1]{%
{%
deftextbf##1{##1}%
deftextit##1{##1}%
deftextcolor##1##2{##2}%
defprotect##1##2{##2}%
edef_{string_}%
edef&{string&}%
xdeftmp{noexpandhref{#1}}}%
ttfamily%
tmp{#1}%
}

begin{document}

begin{tabularx}{linewidth}{|l|l|}
link{https://www.textcolor{blue}{longlink}.com/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/} & Long link descriptiontabularnewline
link{www.textcolor{blue}{longlinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglink}.net} & Long link descriptiontabularnewline
end{tabularx}

end{document}


and I get:



Compilation output



So… two questions:




  • How can I change the text of link to get the hyphenation on the slash character without the hyphen char?


and if there isn't any slash character




  • How can I change the text of link to get hyphenation anywhere but without the hyphen char?










share|improve this question















I use, in agreement with the post of SE, the command link.



documentclass[10pt]{article}
usepackage{bookmark}
usepackage[table]{xcolor}
usepackage{tabularx}

newcommand{link}[1]{%
{%
deftextbf##1{##1}%
deftextit##1{##1}%
deftextcolor##1##2{##2}%
defprotect##1##2{##2}%
edef_{string_}%
edef&{string&}%
xdeftmp{noexpandhref{#1}}}%
ttfamily%
tmp{#1}%
}

begin{document}

begin{tabularx}{linewidth}{|l|l|}
link{https://www.textcolor{blue}{longlink}.com/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/} & Long link descriptiontabularnewline
link{www.textcolor{blue}{longlinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglink}.net} & Long link descriptiontabularnewline
end{tabularx}

end{document}


and I get:



Compilation output



So… two questions:




  • How can I change the text of link to get the hyphenation on the slash character without the hyphen char?


and if there isn't any slash character




  • How can I change the text of link to get hyphenation anywhere but without the hyphen char?







hyphenation url






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 5 hours ago







BnG

















asked 6 hours ago









BnGBnG

255




255












  • Maybe tex.stackexchange.com/a/108003 can help you (i.e., the breakurl package with anythingbreaks option)?
    – Marijn
    5 hours ago










  • No, with usepackage[breaklinks=true]{hyperref} i get: Option clash for package hyperref, and sloppy doesn't work.
    – BnG
    5 hours ago










  • I've linked to a specific answer which does not mention the breaklinks option for hyperref, it uses a separate package for breaking links (called breakurl). Did you try that?
    – Marijn
    5 hours ago












  • I'm sorry, usepackage{breakurl} or usepackage[anythingbreaks]{breakurl} don't work either.
    – BnG
    5 hours ago








  • 1




    I tried it myself now and it does not work indeed - and many other possible solutions also seem to fail for this specific case. I hope someone here comes along to solve it.
    – Marijn
    5 hours ago


















  • Maybe tex.stackexchange.com/a/108003 can help you (i.e., the breakurl package with anythingbreaks option)?
    – Marijn
    5 hours ago










  • No, with usepackage[breaklinks=true]{hyperref} i get: Option clash for package hyperref, and sloppy doesn't work.
    – BnG
    5 hours ago










  • I've linked to a specific answer which does not mention the breaklinks option for hyperref, it uses a separate package for breaking links (called breakurl). Did you try that?
    – Marijn
    5 hours ago












  • I'm sorry, usepackage{breakurl} or usepackage[anythingbreaks]{breakurl} don't work either.
    – BnG
    5 hours ago








  • 1




    I tried it myself now and it does not work indeed - and many other possible solutions also seem to fail for this specific case. I hope someone here comes along to solve it.
    – Marijn
    5 hours ago
















Maybe tex.stackexchange.com/a/108003 can help you (i.e., the breakurl package with anythingbreaks option)?
– Marijn
5 hours ago




Maybe tex.stackexchange.com/a/108003 can help you (i.e., the breakurl package with anythingbreaks option)?
– Marijn
5 hours ago












No, with usepackage[breaklinks=true]{hyperref} i get: Option clash for package hyperref, and sloppy doesn't work.
– BnG
5 hours ago




No, with usepackage[breaklinks=true]{hyperref} i get: Option clash for package hyperref, and sloppy doesn't work.
– BnG
5 hours ago












I've linked to a specific answer which does not mention the breaklinks option for hyperref, it uses a separate package for breaking links (called breakurl). Did you try that?
– Marijn
5 hours ago






I've linked to a specific answer which does not mention the breaklinks option for hyperref, it uses a separate package for breaking links (called breakurl). Did you try that?
– Marijn
5 hours ago














I'm sorry, usepackage{breakurl} or usepackage[anythingbreaks]{breakurl} don't work either.
– BnG
5 hours ago






I'm sorry, usepackage{breakurl} or usepackage[anythingbreaks]{breakurl} don't work either.
– BnG
5 hours ago






1




1




I tried it myself now and it does not work indeed - and many other possible solutions also seem to fail for this specific case. I hope someone here comes along to solve it.
– Marijn
5 hours ago




I tried it myself now and it does not work indeed - and many other possible solutions also seem to fail for this specific case. I hope someone here comes along to solve it.
– Marijn
5 hours ago










1 Answer
1






active

oldest

votes


















2














The idea is the same, but using more powerful expl3 methods.



With link{<link>} you get the same as before, but with the possibility of breaking lines at slashes.



With link*{<link>} you allow breaking at any letter. However this requires changing textcolor{blue}{<string>} to blue{<string>} otherwise also blue would be considered for breaking. Define similar commands for all colors you need and update the equivalences.



documentclass[10pt]{article}
usepackage{bookmark}
usepackage[table]{xcolor}
usepackage{tabularx}
usepackage{xparse}

NewDocumentCommand{blue}{m}{textcolor{blue}{#1}}

ExplSyntaxOn
NewDocumentCommand{link}{sm}
{
group_begin:
cs_set_eq:NN textbf use:n
cs_set_eq:NN textit use:n
cs_set_eq:NN blue use:n
cs_set:Npx _ { c_underscore_str }
cs_set:Npx & { c_ampersand_str }
tl_gset:Nx g_tmpa_tl { #2 }
group_end:
tl_set:Nn l_tmpa_tl { #2 }
IfBooleanTF{#1}
{
regex_replace_all:nnN { [A-Za-z] } { c{linebreak}[0] } l_tmpa_tl
}
{
tl_replace_all:Nnn l_tmpa_tl { / } { /linebreak[0] }
}
group_begin:
ttfamily
exp_args:NVV href g_tmpa_tl l_tmpa_tl
group_end:
}
ExplSyntaxOff

begin{document}

noindent
begin{tabularx}{linewidth}{|>{raggedright}X|l|}
link{https://www.blue{longlink}.com/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/} & Long link descriptiontabularnewline
link*{www.blue{longlinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglink}.net} & Long link descriptiontabularnewline
end{tabularx}

end{document}


enter image description here



It is also possible to adopt the “break everywhere” strategy when there is no slash:



documentclass[10pt]{article}
usepackage{bookmark}
usepackage[table]{xcolor}
usepackage{tabularx}
usepackage{xparse}

NewDocumentCommand{blue}{m}{textcolor{blue}{#1}}

ExplSyntaxOn
NewDocumentCommand{link}{m}
{
group_begin:
cs_set_eq:NN textbf use:n
cs_set_eq:NN textit use:n
cs_set_eq:NN blue use:n
cs_set:Npx _ { c_underscore_str }
cs_set:Npx & { c_ampersand_str }
tl_gset:Nx g_tmpa_tl { #1 }
group_end:
tl_set:Nn l_tmpa_tl { #1 }
regex_match:nnTF { / } { #1 }
{
tl_replace_all:Nnn l_tmpa_tl { / } { /linebreak[0] }
}
{
regex_replace_all:nnN { [A-Za-z] } { c{linebreak}[0] } l_tmpa_tl
}
group_begin:
ttfamily
exp_args:NVV href g_tmpa_tl l_tmpa_tl
group_end:
}
ExplSyntaxOff

begin{document}

noindent
begin{tabularx}{linewidth}{|>{raggedright}X|l|}
link{https://www.blue{example}.com/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/} & Long link descriptiontabularnewline
link{www.blue{longlinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglink}.net} & Long link descriptiontabularnewline
end{tabularx}

end{document}


The output is the same.






share|improve this answer























  • Is it possible to get the second behavior in case of non-existence of the slash?
    – BnG
    4 hours ago










  • I get Use of @undeclaredcolor doesn't match its definition. end{tabularx} if i try to use another color like textcolor{red}.
    – BnG
    4 hours ago










  • @BnG Yes, it's possible and I added it. As I said, you need to define red for textcolor{red} similarly as for blue and to add the line cs_set:Npn red use:n in the code.
    – egreg
    4 hours ago










  • Doh :-) !!! Is there no way to avoid the definition of all colors… or even better, to delete all the commands starting with ``
    – BnG
    4 hours ago










  • @BnG Maybe, but the regular expression would be quite complicated. I think that defining semantic commands instead of using textcolor is better; I used blue and red, but you can use whatever name that conveys the idea you want to express. This has also the advantage that you can redefine the colors uniformly in case of need, without chasing through the document.
    – egreg
    3 hours ago













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%2f469249%2fhyphenation-in-link-text%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














The idea is the same, but using more powerful expl3 methods.



With link{<link>} you get the same as before, but with the possibility of breaking lines at slashes.



With link*{<link>} you allow breaking at any letter. However this requires changing textcolor{blue}{<string>} to blue{<string>} otherwise also blue would be considered for breaking. Define similar commands for all colors you need and update the equivalences.



documentclass[10pt]{article}
usepackage{bookmark}
usepackage[table]{xcolor}
usepackage{tabularx}
usepackage{xparse}

NewDocumentCommand{blue}{m}{textcolor{blue}{#1}}

ExplSyntaxOn
NewDocumentCommand{link}{sm}
{
group_begin:
cs_set_eq:NN textbf use:n
cs_set_eq:NN textit use:n
cs_set_eq:NN blue use:n
cs_set:Npx _ { c_underscore_str }
cs_set:Npx & { c_ampersand_str }
tl_gset:Nx g_tmpa_tl { #2 }
group_end:
tl_set:Nn l_tmpa_tl { #2 }
IfBooleanTF{#1}
{
regex_replace_all:nnN { [A-Za-z] } { c{linebreak}[0] } l_tmpa_tl
}
{
tl_replace_all:Nnn l_tmpa_tl { / } { /linebreak[0] }
}
group_begin:
ttfamily
exp_args:NVV href g_tmpa_tl l_tmpa_tl
group_end:
}
ExplSyntaxOff

begin{document}

noindent
begin{tabularx}{linewidth}{|>{raggedright}X|l|}
link{https://www.blue{longlink}.com/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/} & Long link descriptiontabularnewline
link*{www.blue{longlinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglink}.net} & Long link descriptiontabularnewline
end{tabularx}

end{document}


enter image description here



It is also possible to adopt the “break everywhere” strategy when there is no slash:



documentclass[10pt]{article}
usepackage{bookmark}
usepackage[table]{xcolor}
usepackage{tabularx}
usepackage{xparse}

NewDocumentCommand{blue}{m}{textcolor{blue}{#1}}

ExplSyntaxOn
NewDocumentCommand{link}{m}
{
group_begin:
cs_set_eq:NN textbf use:n
cs_set_eq:NN textit use:n
cs_set_eq:NN blue use:n
cs_set:Npx _ { c_underscore_str }
cs_set:Npx & { c_ampersand_str }
tl_gset:Nx g_tmpa_tl { #1 }
group_end:
tl_set:Nn l_tmpa_tl { #1 }
regex_match:nnTF { / } { #1 }
{
tl_replace_all:Nnn l_tmpa_tl { / } { /linebreak[0] }
}
{
regex_replace_all:nnN { [A-Za-z] } { c{linebreak}[0] } l_tmpa_tl
}
group_begin:
ttfamily
exp_args:NVV href g_tmpa_tl l_tmpa_tl
group_end:
}
ExplSyntaxOff

begin{document}

noindent
begin{tabularx}{linewidth}{|>{raggedright}X|l|}
link{https://www.blue{example}.com/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/} & Long link descriptiontabularnewline
link{www.blue{longlinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglink}.net} & Long link descriptiontabularnewline
end{tabularx}

end{document}


The output is the same.






share|improve this answer























  • Is it possible to get the second behavior in case of non-existence of the slash?
    – BnG
    4 hours ago










  • I get Use of @undeclaredcolor doesn't match its definition. end{tabularx} if i try to use another color like textcolor{red}.
    – BnG
    4 hours ago










  • @BnG Yes, it's possible and I added it. As I said, you need to define red for textcolor{red} similarly as for blue and to add the line cs_set:Npn red use:n in the code.
    – egreg
    4 hours ago










  • Doh :-) !!! Is there no way to avoid the definition of all colors… or even better, to delete all the commands starting with ``
    – BnG
    4 hours ago










  • @BnG Maybe, but the regular expression would be quite complicated. I think that defining semantic commands instead of using textcolor is better; I used blue and red, but you can use whatever name that conveys the idea you want to express. This has also the advantage that you can redefine the colors uniformly in case of need, without chasing through the document.
    – egreg
    3 hours ago


















2














The idea is the same, but using more powerful expl3 methods.



With link{<link>} you get the same as before, but with the possibility of breaking lines at slashes.



With link*{<link>} you allow breaking at any letter. However this requires changing textcolor{blue}{<string>} to blue{<string>} otherwise also blue would be considered for breaking. Define similar commands for all colors you need and update the equivalences.



documentclass[10pt]{article}
usepackage{bookmark}
usepackage[table]{xcolor}
usepackage{tabularx}
usepackage{xparse}

NewDocumentCommand{blue}{m}{textcolor{blue}{#1}}

ExplSyntaxOn
NewDocumentCommand{link}{sm}
{
group_begin:
cs_set_eq:NN textbf use:n
cs_set_eq:NN textit use:n
cs_set_eq:NN blue use:n
cs_set:Npx _ { c_underscore_str }
cs_set:Npx & { c_ampersand_str }
tl_gset:Nx g_tmpa_tl { #2 }
group_end:
tl_set:Nn l_tmpa_tl { #2 }
IfBooleanTF{#1}
{
regex_replace_all:nnN { [A-Za-z] } { c{linebreak}[0] } l_tmpa_tl
}
{
tl_replace_all:Nnn l_tmpa_tl { / } { /linebreak[0] }
}
group_begin:
ttfamily
exp_args:NVV href g_tmpa_tl l_tmpa_tl
group_end:
}
ExplSyntaxOff

begin{document}

noindent
begin{tabularx}{linewidth}{|>{raggedright}X|l|}
link{https://www.blue{longlink}.com/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/} & Long link descriptiontabularnewline
link*{www.blue{longlinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglink}.net} & Long link descriptiontabularnewline
end{tabularx}

end{document}


enter image description here



It is also possible to adopt the “break everywhere” strategy when there is no slash:



documentclass[10pt]{article}
usepackage{bookmark}
usepackage[table]{xcolor}
usepackage{tabularx}
usepackage{xparse}

NewDocumentCommand{blue}{m}{textcolor{blue}{#1}}

ExplSyntaxOn
NewDocumentCommand{link}{m}
{
group_begin:
cs_set_eq:NN textbf use:n
cs_set_eq:NN textit use:n
cs_set_eq:NN blue use:n
cs_set:Npx _ { c_underscore_str }
cs_set:Npx & { c_ampersand_str }
tl_gset:Nx g_tmpa_tl { #1 }
group_end:
tl_set:Nn l_tmpa_tl { #1 }
regex_match:nnTF { / } { #1 }
{
tl_replace_all:Nnn l_tmpa_tl { / } { /linebreak[0] }
}
{
regex_replace_all:nnN { [A-Za-z] } { c{linebreak}[0] } l_tmpa_tl
}
group_begin:
ttfamily
exp_args:NVV href g_tmpa_tl l_tmpa_tl
group_end:
}
ExplSyntaxOff

begin{document}

noindent
begin{tabularx}{linewidth}{|>{raggedright}X|l|}
link{https://www.blue{example}.com/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/} & Long link descriptiontabularnewline
link{www.blue{longlinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglink}.net} & Long link descriptiontabularnewline
end{tabularx}

end{document}


The output is the same.






share|improve this answer























  • Is it possible to get the second behavior in case of non-existence of the slash?
    – BnG
    4 hours ago










  • I get Use of @undeclaredcolor doesn't match its definition. end{tabularx} if i try to use another color like textcolor{red}.
    – BnG
    4 hours ago










  • @BnG Yes, it's possible and I added it. As I said, you need to define red for textcolor{red} similarly as for blue and to add the line cs_set:Npn red use:n in the code.
    – egreg
    4 hours ago










  • Doh :-) !!! Is there no way to avoid the definition of all colors… or even better, to delete all the commands starting with ``
    – BnG
    4 hours ago










  • @BnG Maybe, but the regular expression would be quite complicated. I think that defining semantic commands instead of using textcolor is better; I used blue and red, but you can use whatever name that conveys the idea you want to express. This has also the advantage that you can redefine the colors uniformly in case of need, without chasing through the document.
    – egreg
    3 hours ago
















2












2








2






The idea is the same, but using more powerful expl3 methods.



With link{<link>} you get the same as before, but with the possibility of breaking lines at slashes.



With link*{<link>} you allow breaking at any letter. However this requires changing textcolor{blue}{<string>} to blue{<string>} otherwise also blue would be considered for breaking. Define similar commands for all colors you need and update the equivalences.



documentclass[10pt]{article}
usepackage{bookmark}
usepackage[table]{xcolor}
usepackage{tabularx}
usepackage{xparse}

NewDocumentCommand{blue}{m}{textcolor{blue}{#1}}

ExplSyntaxOn
NewDocumentCommand{link}{sm}
{
group_begin:
cs_set_eq:NN textbf use:n
cs_set_eq:NN textit use:n
cs_set_eq:NN blue use:n
cs_set:Npx _ { c_underscore_str }
cs_set:Npx & { c_ampersand_str }
tl_gset:Nx g_tmpa_tl { #2 }
group_end:
tl_set:Nn l_tmpa_tl { #2 }
IfBooleanTF{#1}
{
regex_replace_all:nnN { [A-Za-z] } { c{linebreak}[0] } l_tmpa_tl
}
{
tl_replace_all:Nnn l_tmpa_tl { / } { /linebreak[0] }
}
group_begin:
ttfamily
exp_args:NVV href g_tmpa_tl l_tmpa_tl
group_end:
}
ExplSyntaxOff

begin{document}

noindent
begin{tabularx}{linewidth}{|>{raggedright}X|l|}
link{https://www.blue{longlink}.com/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/} & Long link descriptiontabularnewline
link*{www.blue{longlinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglink}.net} & Long link descriptiontabularnewline
end{tabularx}

end{document}


enter image description here



It is also possible to adopt the “break everywhere” strategy when there is no slash:



documentclass[10pt]{article}
usepackage{bookmark}
usepackage[table]{xcolor}
usepackage{tabularx}
usepackage{xparse}

NewDocumentCommand{blue}{m}{textcolor{blue}{#1}}

ExplSyntaxOn
NewDocumentCommand{link}{m}
{
group_begin:
cs_set_eq:NN textbf use:n
cs_set_eq:NN textit use:n
cs_set_eq:NN blue use:n
cs_set:Npx _ { c_underscore_str }
cs_set:Npx & { c_ampersand_str }
tl_gset:Nx g_tmpa_tl { #1 }
group_end:
tl_set:Nn l_tmpa_tl { #1 }
regex_match:nnTF { / } { #1 }
{
tl_replace_all:Nnn l_tmpa_tl { / } { /linebreak[0] }
}
{
regex_replace_all:nnN { [A-Za-z] } { c{linebreak}[0] } l_tmpa_tl
}
group_begin:
ttfamily
exp_args:NVV href g_tmpa_tl l_tmpa_tl
group_end:
}
ExplSyntaxOff

begin{document}

noindent
begin{tabularx}{linewidth}{|>{raggedright}X|l|}
link{https://www.blue{example}.com/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/} & Long link descriptiontabularnewline
link{www.blue{longlinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglink}.net} & Long link descriptiontabularnewline
end{tabularx}

end{document}


The output is the same.






share|improve this answer














The idea is the same, but using more powerful expl3 methods.



With link{<link>} you get the same as before, but with the possibility of breaking lines at slashes.



With link*{<link>} you allow breaking at any letter. However this requires changing textcolor{blue}{<string>} to blue{<string>} otherwise also blue would be considered for breaking. Define similar commands for all colors you need and update the equivalences.



documentclass[10pt]{article}
usepackage{bookmark}
usepackage[table]{xcolor}
usepackage{tabularx}
usepackage{xparse}

NewDocumentCommand{blue}{m}{textcolor{blue}{#1}}

ExplSyntaxOn
NewDocumentCommand{link}{sm}
{
group_begin:
cs_set_eq:NN textbf use:n
cs_set_eq:NN textit use:n
cs_set_eq:NN blue use:n
cs_set:Npx _ { c_underscore_str }
cs_set:Npx & { c_ampersand_str }
tl_gset:Nx g_tmpa_tl { #2 }
group_end:
tl_set:Nn l_tmpa_tl { #2 }
IfBooleanTF{#1}
{
regex_replace_all:nnN { [A-Za-z] } { c{linebreak}[0] } l_tmpa_tl
}
{
tl_replace_all:Nnn l_tmpa_tl { / } { /linebreak[0] }
}
group_begin:
ttfamily
exp_args:NVV href g_tmpa_tl l_tmpa_tl
group_end:
}
ExplSyntaxOff

begin{document}

noindent
begin{tabularx}{linewidth}{|>{raggedright}X|l|}
link{https://www.blue{longlink}.com/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/} & Long link descriptiontabularnewline
link*{www.blue{longlinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglink}.net} & Long link descriptiontabularnewline
end{tabularx}

end{document}


enter image description here



It is also possible to adopt the “break everywhere” strategy when there is no slash:



documentclass[10pt]{article}
usepackage{bookmark}
usepackage[table]{xcolor}
usepackage{tabularx}
usepackage{xparse}

NewDocumentCommand{blue}{m}{textcolor{blue}{#1}}

ExplSyntaxOn
NewDocumentCommand{link}{m}
{
group_begin:
cs_set_eq:NN textbf use:n
cs_set_eq:NN textit use:n
cs_set_eq:NN blue use:n
cs_set:Npx _ { c_underscore_str }
cs_set:Npx & { c_ampersand_str }
tl_gset:Nx g_tmpa_tl { #1 }
group_end:
tl_set:Nn l_tmpa_tl { #1 }
regex_match:nnTF { / } { #1 }
{
tl_replace_all:Nnn l_tmpa_tl { / } { /linebreak[0] }
}
{
regex_replace_all:nnN { [A-Za-z] } { c{linebreak}[0] } l_tmpa_tl
}
group_begin:
ttfamily
exp_args:NVV href g_tmpa_tl l_tmpa_tl
group_end:
}
ExplSyntaxOff

begin{document}

noindent
begin{tabularx}{linewidth}{|>{raggedright}X|l|}
link{https://www.blue{example}.com/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/longlink/} & Long link descriptiontabularnewline
link{www.blue{longlinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglinklonglink}.net} & Long link descriptiontabularnewline
end{tabularx}

end{document}


The output is the same.







share|improve this answer














share|improve this answer



share|improve this answer








edited 4 hours ago

























answered 4 hours ago









egregegreg

710k8618893173




710k8618893173












  • Is it possible to get the second behavior in case of non-existence of the slash?
    – BnG
    4 hours ago










  • I get Use of @undeclaredcolor doesn't match its definition. end{tabularx} if i try to use another color like textcolor{red}.
    – BnG
    4 hours ago










  • @BnG Yes, it's possible and I added it. As I said, you need to define red for textcolor{red} similarly as for blue and to add the line cs_set:Npn red use:n in the code.
    – egreg
    4 hours ago










  • Doh :-) !!! Is there no way to avoid the definition of all colors… or even better, to delete all the commands starting with ``
    – BnG
    4 hours ago










  • @BnG Maybe, but the regular expression would be quite complicated. I think that defining semantic commands instead of using textcolor is better; I used blue and red, but you can use whatever name that conveys the idea you want to express. This has also the advantage that you can redefine the colors uniformly in case of need, without chasing through the document.
    – egreg
    3 hours ago




















  • Is it possible to get the second behavior in case of non-existence of the slash?
    – BnG
    4 hours ago










  • I get Use of @undeclaredcolor doesn't match its definition. end{tabularx} if i try to use another color like textcolor{red}.
    – BnG
    4 hours ago










  • @BnG Yes, it's possible and I added it. As I said, you need to define red for textcolor{red} similarly as for blue and to add the line cs_set:Npn red use:n in the code.
    – egreg
    4 hours ago










  • Doh :-) !!! Is there no way to avoid the definition of all colors… or even better, to delete all the commands starting with ``
    – BnG
    4 hours ago










  • @BnG Maybe, but the regular expression would be quite complicated. I think that defining semantic commands instead of using textcolor is better; I used blue and red, but you can use whatever name that conveys the idea you want to express. This has also the advantage that you can redefine the colors uniformly in case of need, without chasing through the document.
    – egreg
    3 hours ago


















Is it possible to get the second behavior in case of non-existence of the slash?
– BnG
4 hours ago




Is it possible to get the second behavior in case of non-existence of the slash?
– BnG
4 hours ago












I get Use of @undeclaredcolor doesn't match its definition. end{tabularx} if i try to use another color like textcolor{red}.
– BnG
4 hours ago




I get Use of @undeclaredcolor doesn't match its definition. end{tabularx} if i try to use another color like textcolor{red}.
– BnG
4 hours ago












@BnG Yes, it's possible and I added it. As I said, you need to define red for textcolor{red} similarly as for blue and to add the line cs_set:Npn red use:n in the code.
– egreg
4 hours ago




@BnG Yes, it's possible and I added it. As I said, you need to define red for textcolor{red} similarly as for blue and to add the line cs_set:Npn red use:n in the code.
– egreg
4 hours ago












Doh :-) !!! Is there no way to avoid the definition of all colors… or even better, to delete all the commands starting with ``
– BnG
4 hours ago




Doh :-) !!! Is there no way to avoid the definition of all colors… or even better, to delete all the commands starting with ``
– BnG
4 hours ago












@BnG Maybe, but the regular expression would be quite complicated. I think that defining semantic commands instead of using textcolor is better; I used blue and red, but you can use whatever name that conveys the idea you want to express. This has also the advantage that you can redefine the colors uniformly in case of need, without chasing through the document.
– egreg
3 hours ago






@BnG Maybe, but the regular expression would be quite complicated. I think that defining semantic commands instead of using textcolor is better; I used blue and red, but you can use whatever name that conveys the idea you want to express. This has also the advantage that you can redefine the colors uniformly in case of need, without chasing through the document.
– egreg
3 hours ago




















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.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • 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%2f469249%2fhyphenation-in-link-text%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

A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

Calculate evaluation metrics using cross_val_predict sklearn

Insert data from modal to MySQL (multiple modal on website)