Redefine `uline` so `colorbox` is locally defined to have underlined text, too












3















Initial problem:



I want to underline the text with a continuous line with the following code:



uline{No underlining for colorbox{lightgray}{everything} inside the colorbox.}


screenshot





Workaround:



A solution to get a continuous line for the text inside colorbox as well, is to do:



sbox0{uline{hspace{fboxsep}everythinghspace{fboxsep}}}
uline{No underlining for colorbox{lightgray}{hspace{-fboxsep}usebox0hspace{-fboxsep}} inside the colorbox.}


screenshot





Question:



How can I redefine uline, so every colorbox inside uline is locally defined as shown above in the workaround to have underlined text, too?





MCVE:



documentclass[12pt]{article}
usepackage[T1]{fontenc}
usepackage[utf8]{inputenc}
usepackage{lmodern}
usepackage{xcolor}
usepackage[normalem]{ulem}

begin{document}

uline{No underlining for colorbox{lightgray}{everything} inside the colorbox.}

end{document}












share|improve this question























  • Underlining is not the best way of typography, however. Do you really want to have gray box portions below the line? That does not look nice!

    – Christian Hupfer
    Jan 2 at 19:35
















3















Initial problem:



I want to underline the text with a continuous line with the following code:



uline{No underlining for colorbox{lightgray}{everything} inside the colorbox.}


screenshot





Workaround:



A solution to get a continuous line for the text inside colorbox as well, is to do:



sbox0{uline{hspace{fboxsep}everythinghspace{fboxsep}}}
uline{No underlining for colorbox{lightgray}{hspace{-fboxsep}usebox0hspace{-fboxsep}} inside the colorbox.}


screenshot





Question:



How can I redefine uline, so every colorbox inside uline is locally defined as shown above in the workaround to have underlined text, too?





MCVE:



documentclass[12pt]{article}
usepackage[T1]{fontenc}
usepackage[utf8]{inputenc}
usepackage{lmodern}
usepackage{xcolor}
usepackage[normalem]{ulem}

begin{document}

uline{No underlining for colorbox{lightgray}{everything} inside the colorbox.}

end{document}












share|improve this question























  • Underlining is not the best way of typography, however. Do you really want to have gray box portions below the line? That does not look nice!

    – Christian Hupfer
    Jan 2 at 19:35














3












3








3


0






Initial problem:



I want to underline the text with a continuous line with the following code:



uline{No underlining for colorbox{lightgray}{everything} inside the colorbox.}


screenshot





Workaround:



A solution to get a continuous line for the text inside colorbox as well, is to do:



sbox0{uline{hspace{fboxsep}everythinghspace{fboxsep}}}
uline{No underlining for colorbox{lightgray}{hspace{-fboxsep}usebox0hspace{-fboxsep}} inside the colorbox.}


screenshot





Question:



How can I redefine uline, so every colorbox inside uline is locally defined as shown above in the workaround to have underlined text, too?





MCVE:



documentclass[12pt]{article}
usepackage[T1]{fontenc}
usepackage[utf8]{inputenc}
usepackage{lmodern}
usepackage{xcolor}
usepackage[normalem]{ulem}

begin{document}

uline{No underlining for colorbox{lightgray}{everything} inside the colorbox.}

end{document}












share|improve this question














Initial problem:



I want to underline the text with a continuous line with the following code:



uline{No underlining for colorbox{lightgray}{everything} inside the colorbox.}


screenshot





Workaround:



A solution to get a continuous line for the text inside colorbox as well, is to do:



sbox0{uline{hspace{fboxsep}everythinghspace{fboxsep}}}
uline{No underlining for colorbox{lightgray}{hspace{-fboxsep}usebox0hspace{-fboxsep}} inside the colorbox.}


screenshot





Question:



How can I redefine uline, so every colorbox inside uline is locally defined as shown above in the workaround to have underlined text, too?





MCVE:



documentclass[12pt]{article}
usepackage[T1]{fontenc}
usepackage[utf8]{inputenc}
usepackage{lmodern}
usepackage{xcolor}
usepackage[normalem]{ulem}

begin{document}

uline{No underlining for colorbox{lightgray}{everything} inside the colorbox.}

end{document}









macros formatting ulem underline colorbox






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 2 at 19:26









finefootfinefoot

215110




215110













  • Underlining is not the best way of typography, however. Do you really want to have gray box portions below the line? That does not look nice!

    – Christian Hupfer
    Jan 2 at 19:35



















  • Underlining is not the best way of typography, however. Do you really want to have gray box portions below the line? That does not look nice!

    – Christian Hupfer
    Jan 2 at 19:35

















Underlining is not the best way of typography, however. Do you really want to have gray box portions below the line? That does not look nice!

– Christian Hupfer
Jan 2 at 19:35





Underlining is not the best way of typography, however. Do you really want to have gray box portions below the line? That does not look nice!

– Christian Hupfer
Jan 2 at 19:35










3 Answers
3






active

oldest

votes


















4














Here is a way with tikz and using a node, drawing a line at the bottom of the node. However, this does not work with text - wrapping, i.e. if the text is wider than text width, it will fail.



In principle, underlining is not the best way of typographical markup, in my point of view.



documentclass[12pt]{article}
usepackage[T1]{fontenc}
usepackage[utf8]{inputenc}
usepackage{lmodern}
usepackage{xcolor}
%usepackage[normalem]{ulem}
usepackage{tikz}

newcommand{underlinethis}[3][0.15baselineskip]{%
tikz[remember picture,baseline=(A.base)]{%
node[inner sep=0pt,outer sep=0pt] (A) {#3}; % Place the node and typeset the text
draw[#2] ([yshift=#1]A.south west) -- ([yshift=#1]A.south east); % Draw the line, shifted up by some value
}%
}

begin{document}
underlinethis{blue, line width=1pt}{No underlining for colorbox{lightgray}{everything} inside the colorbox.}

underlinethis{red, line width=1pt,dashed}{No underlining for colorbox{lightgray}{everything} inside the colorbox.}
end{document}


enter image description here






share|improve this answer





















  • 2





    Two wonderful examples of beautiful typography ;-)

    – Christian Hupfer
    Jan 2 at 20:06






  • 1





    This isn't line breakable is it?

    – Skillmon
    Jan 2 at 22:41











  • @Skillmon: Nope, I don't think so... and if I change the text options of the node, it will break, but the underline would occur on the last line only, for the full width of the text, not only for the width of the remainder of the text that is wrapped into there.

    – Christian Hupfer
    Jan 2 at 23:06






  • 1





    I couldn't find the original one, but tex.stackexchange.com/a/417634/117050 does use the same mechanism. Sadly it seems like I couldn't find the original one when I wrote that answer, too, and didn't cite it properly... And I don't know who posted the original code which I modified, so finding it is hard. (the code there is modified from a version I modified for myself of that code)

    – Skillmon
    Jan 3 at 18:39






  • 1





    Found the original ones. They were created by marmot: tex.stackexchange.com/a/411361/117050 and tex.stackexchange.com/a/411655/117050 use the approach.

    – Skillmon
    Jan 3 at 18:43



















4














Redefining uline to include a redefinition of colorbox.



documentclass[12pt]{article}
usepackage[T1]{fontenc}
usepackage[utf8]{inputenc}
usepackage{lmodern}
usepackage{xcolor}
usepackage[normalem]{ulem}

makeatletter
longdefafterelsefi#1else#2fi{fi#1}
longdefafterfi#1fi{fi#1}
defq@mark{q@mark}
newcommanduline@colorbox[3][q@mark]
{%
ifxq@mark#1%
afterelseficolorbox@orig{#2}%
else
afterficolorbox@orig[#1]{#2}%
fi
{%
% nested uline becomes a second rule which is a bit lower than first
% the following changes the values of UL@height and ULdepth so that the
% calculation done by ulem results in the original values
advanceUL@heightULdepth
advanceULdepth-thr@@UL@height
hskip-fboxsep
uline{hskipfboxsep#3hskipfboxsep}%
hskip-fboxsep
}%
}
letcolorbox@origcolorbox
protecteddefuline
{%
relax
ifmmode
expandafterunderline
else
bgroup
letcolorboxuline@colorbox % this is added compared to the original definition
expandafterULset
fi
}
makeatother

begin{document}

uline{No underlining for colorbox{lightgray}{everything} inside the colorbox.}

end{document}


enter image description here






share|improve this answer


























  • @Jayjayyy if I knew with certainty it wouldn't be necessary to use this ugly value. Seems to be because of the nesting of uline (I'll take another thorough look). .42774ex was determined by trial and error and a big zoom.

    – Skillmon
    Jan 2 at 22:28











  • @Jayjayyy found the issue and fixed it.

    – Skillmon
    Jan 2 at 22:33



















2














Don't underline. Ever.



If you don't want to adhere to the advice above, be aware that when you call uline inside uline the macro adds a further 1.2pt, because it thinks you want to double underline.



documentclass[12pt]{article}
usepackage[T1]{fontenc}
usepackage[utf8]{inputenc}
usepackage{lmodern}
usepackage{xcolor}
usepackage[normalem]{ulem}

letulemulineuline
renewcommand{uline}[1]{%
begingroup
redefinecolorbox
ulemuline{#1}%
endgroup
}
letlatexcolorboxcolorbox
newcommandredefinecolorbox{%
renewcommandcolorbox[2]{%
latexcolorbox{##1}{%
advanceULdepth-1.2pt
kern-fboxsep
ulemuline{hspace{fboxsep}##2hspace{fboxsep}}%
kern-fboxsep
}%
}%
}

begin{document}

uline{No underlining for colorbox{lightgray}{everything} inside the colorbox.}

end{document}


enter image description here






share|improve this answer


























  • @Jayjayyy I mean “don't underline”. At all.

    – egreg
    Jan 6 at 9:37











  • @Jayjayyy Underlining is not considered a typographic device. It used to be common with typewriters lacking any other method for emphasis.

    – egreg
    Jan 6 at 13:34











  • Okay, thanks :-) That's important to know. Could you add that to your answer? I have removed my former comments. Do you have a link to a good explanation on that?

    – finefoot
    Jan 6 at 14:00











  • @Jayjayyy using common sense (so no reference here), it just looks too intrusive when there are other means to emphasize stuff. For the same reason bold should only be used sparsely and not for regular emphasizes, which is the reason why emph doesn't print bold but italic by default. Also it destroys the balanced look of text if used inside of a paragraph. Maybe the most dominant reason: Word processor users tend to underline.

    – Skillmon
    Jan 6 at 14:09











  • @Skillmon I think, I have to say that I agree after hearing both your and egreg's arguments. However, it wasn't obvious to me before. I'm not as familiar with typesetting - even with something as basic as emphasis - so "Using common sense" didn't help me here. I think a reference as to why the statement "Don't underline. Ever." makes sense would improve this answer since I could have just clicked on it instead of bothering you. It might help someone who's in the same shoes as I was a few moments ago. :-)

    – finefoot
    Jan 6 at 14:16











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%2f468307%2fredefine-uline-so-colorbox-is-locally-defined-to-have-underlined-text-too%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









4














Here is a way with tikz and using a node, drawing a line at the bottom of the node. However, this does not work with text - wrapping, i.e. if the text is wider than text width, it will fail.



In principle, underlining is not the best way of typographical markup, in my point of view.



documentclass[12pt]{article}
usepackage[T1]{fontenc}
usepackage[utf8]{inputenc}
usepackage{lmodern}
usepackage{xcolor}
%usepackage[normalem]{ulem}
usepackage{tikz}

newcommand{underlinethis}[3][0.15baselineskip]{%
tikz[remember picture,baseline=(A.base)]{%
node[inner sep=0pt,outer sep=0pt] (A) {#3}; % Place the node and typeset the text
draw[#2] ([yshift=#1]A.south west) -- ([yshift=#1]A.south east); % Draw the line, shifted up by some value
}%
}

begin{document}
underlinethis{blue, line width=1pt}{No underlining for colorbox{lightgray}{everything} inside the colorbox.}

underlinethis{red, line width=1pt,dashed}{No underlining for colorbox{lightgray}{everything} inside the colorbox.}
end{document}


enter image description here






share|improve this answer





















  • 2





    Two wonderful examples of beautiful typography ;-)

    – Christian Hupfer
    Jan 2 at 20:06






  • 1





    This isn't line breakable is it?

    – Skillmon
    Jan 2 at 22:41











  • @Skillmon: Nope, I don't think so... and if I change the text options of the node, it will break, but the underline would occur on the last line only, for the full width of the text, not only for the width of the remainder of the text that is wrapped into there.

    – Christian Hupfer
    Jan 2 at 23:06






  • 1





    I couldn't find the original one, but tex.stackexchange.com/a/417634/117050 does use the same mechanism. Sadly it seems like I couldn't find the original one when I wrote that answer, too, and didn't cite it properly... And I don't know who posted the original code which I modified, so finding it is hard. (the code there is modified from a version I modified for myself of that code)

    – Skillmon
    Jan 3 at 18:39






  • 1





    Found the original ones. They were created by marmot: tex.stackexchange.com/a/411361/117050 and tex.stackexchange.com/a/411655/117050 use the approach.

    – Skillmon
    Jan 3 at 18:43
















4














Here is a way with tikz and using a node, drawing a line at the bottom of the node. However, this does not work with text - wrapping, i.e. if the text is wider than text width, it will fail.



In principle, underlining is not the best way of typographical markup, in my point of view.



documentclass[12pt]{article}
usepackage[T1]{fontenc}
usepackage[utf8]{inputenc}
usepackage{lmodern}
usepackage{xcolor}
%usepackage[normalem]{ulem}
usepackage{tikz}

newcommand{underlinethis}[3][0.15baselineskip]{%
tikz[remember picture,baseline=(A.base)]{%
node[inner sep=0pt,outer sep=0pt] (A) {#3}; % Place the node and typeset the text
draw[#2] ([yshift=#1]A.south west) -- ([yshift=#1]A.south east); % Draw the line, shifted up by some value
}%
}

begin{document}
underlinethis{blue, line width=1pt}{No underlining for colorbox{lightgray}{everything} inside the colorbox.}

underlinethis{red, line width=1pt,dashed}{No underlining for colorbox{lightgray}{everything} inside the colorbox.}
end{document}


enter image description here






share|improve this answer





















  • 2





    Two wonderful examples of beautiful typography ;-)

    – Christian Hupfer
    Jan 2 at 20:06






  • 1





    This isn't line breakable is it?

    – Skillmon
    Jan 2 at 22:41











  • @Skillmon: Nope, I don't think so... and if I change the text options of the node, it will break, but the underline would occur on the last line only, for the full width of the text, not only for the width of the remainder of the text that is wrapped into there.

    – Christian Hupfer
    Jan 2 at 23:06






  • 1





    I couldn't find the original one, but tex.stackexchange.com/a/417634/117050 does use the same mechanism. Sadly it seems like I couldn't find the original one when I wrote that answer, too, and didn't cite it properly... And I don't know who posted the original code which I modified, so finding it is hard. (the code there is modified from a version I modified for myself of that code)

    – Skillmon
    Jan 3 at 18:39






  • 1





    Found the original ones. They were created by marmot: tex.stackexchange.com/a/411361/117050 and tex.stackexchange.com/a/411655/117050 use the approach.

    – Skillmon
    Jan 3 at 18:43














4












4








4







Here is a way with tikz and using a node, drawing a line at the bottom of the node. However, this does not work with text - wrapping, i.e. if the text is wider than text width, it will fail.



In principle, underlining is not the best way of typographical markup, in my point of view.



documentclass[12pt]{article}
usepackage[T1]{fontenc}
usepackage[utf8]{inputenc}
usepackage{lmodern}
usepackage{xcolor}
%usepackage[normalem]{ulem}
usepackage{tikz}

newcommand{underlinethis}[3][0.15baselineskip]{%
tikz[remember picture,baseline=(A.base)]{%
node[inner sep=0pt,outer sep=0pt] (A) {#3}; % Place the node and typeset the text
draw[#2] ([yshift=#1]A.south west) -- ([yshift=#1]A.south east); % Draw the line, shifted up by some value
}%
}

begin{document}
underlinethis{blue, line width=1pt}{No underlining for colorbox{lightgray}{everything} inside the colorbox.}

underlinethis{red, line width=1pt,dashed}{No underlining for colorbox{lightgray}{everything} inside the colorbox.}
end{document}


enter image description here






share|improve this answer















Here is a way with tikz and using a node, drawing a line at the bottom of the node. However, this does not work with text - wrapping, i.e. if the text is wider than text width, it will fail.



In principle, underlining is not the best way of typographical markup, in my point of view.



documentclass[12pt]{article}
usepackage[T1]{fontenc}
usepackage[utf8]{inputenc}
usepackage{lmodern}
usepackage{xcolor}
%usepackage[normalem]{ulem}
usepackage{tikz}

newcommand{underlinethis}[3][0.15baselineskip]{%
tikz[remember picture,baseline=(A.base)]{%
node[inner sep=0pt,outer sep=0pt] (A) {#3}; % Place the node and typeset the text
draw[#2] ([yshift=#1]A.south west) -- ([yshift=#1]A.south east); % Draw the line, shifted up by some value
}%
}

begin{document}
underlinethis{blue, line width=1pt}{No underlining for colorbox{lightgray}{everything} inside the colorbox.}

underlinethis{red, line width=1pt,dashed}{No underlining for colorbox{lightgray}{everything} inside the colorbox.}
end{document}


enter image description here







share|improve this answer














share|improve this answer



share|improve this answer








edited Jan 2 at 20:03

























answered Jan 2 at 19:48









Christian HupferChristian Hupfer

148k14193390




148k14193390








  • 2





    Two wonderful examples of beautiful typography ;-)

    – Christian Hupfer
    Jan 2 at 20:06






  • 1





    This isn't line breakable is it?

    – Skillmon
    Jan 2 at 22:41











  • @Skillmon: Nope, I don't think so... and if I change the text options of the node, it will break, but the underline would occur on the last line only, for the full width of the text, not only for the width of the remainder of the text that is wrapped into there.

    – Christian Hupfer
    Jan 2 at 23:06






  • 1





    I couldn't find the original one, but tex.stackexchange.com/a/417634/117050 does use the same mechanism. Sadly it seems like I couldn't find the original one when I wrote that answer, too, and didn't cite it properly... And I don't know who posted the original code which I modified, so finding it is hard. (the code there is modified from a version I modified for myself of that code)

    – Skillmon
    Jan 3 at 18:39






  • 1





    Found the original ones. They were created by marmot: tex.stackexchange.com/a/411361/117050 and tex.stackexchange.com/a/411655/117050 use the approach.

    – Skillmon
    Jan 3 at 18:43














  • 2





    Two wonderful examples of beautiful typography ;-)

    – Christian Hupfer
    Jan 2 at 20:06






  • 1





    This isn't line breakable is it?

    – Skillmon
    Jan 2 at 22:41











  • @Skillmon: Nope, I don't think so... and if I change the text options of the node, it will break, but the underline would occur on the last line only, for the full width of the text, not only for the width of the remainder of the text that is wrapped into there.

    – Christian Hupfer
    Jan 2 at 23:06






  • 1





    I couldn't find the original one, but tex.stackexchange.com/a/417634/117050 does use the same mechanism. Sadly it seems like I couldn't find the original one when I wrote that answer, too, and didn't cite it properly... And I don't know who posted the original code which I modified, so finding it is hard. (the code there is modified from a version I modified for myself of that code)

    – Skillmon
    Jan 3 at 18:39






  • 1





    Found the original ones. They were created by marmot: tex.stackexchange.com/a/411361/117050 and tex.stackexchange.com/a/411655/117050 use the approach.

    – Skillmon
    Jan 3 at 18:43








2




2





Two wonderful examples of beautiful typography ;-)

– Christian Hupfer
Jan 2 at 20:06





Two wonderful examples of beautiful typography ;-)

– Christian Hupfer
Jan 2 at 20:06




1




1





This isn't line breakable is it?

– Skillmon
Jan 2 at 22:41





This isn't line breakable is it?

– Skillmon
Jan 2 at 22:41













@Skillmon: Nope, I don't think so... and if I change the text options of the node, it will break, but the underline would occur on the last line only, for the full width of the text, not only for the width of the remainder of the text that is wrapped into there.

– Christian Hupfer
Jan 2 at 23:06





@Skillmon: Nope, I don't think so... and if I change the text options of the node, it will break, but the underline would occur on the last line only, for the full width of the text, not only for the width of the remainder of the text that is wrapped into there.

– Christian Hupfer
Jan 2 at 23:06




1




1





I couldn't find the original one, but tex.stackexchange.com/a/417634/117050 does use the same mechanism. Sadly it seems like I couldn't find the original one when I wrote that answer, too, and didn't cite it properly... And I don't know who posted the original code which I modified, so finding it is hard. (the code there is modified from a version I modified for myself of that code)

– Skillmon
Jan 3 at 18:39





I couldn't find the original one, but tex.stackexchange.com/a/417634/117050 does use the same mechanism. Sadly it seems like I couldn't find the original one when I wrote that answer, too, and didn't cite it properly... And I don't know who posted the original code which I modified, so finding it is hard. (the code there is modified from a version I modified for myself of that code)

– Skillmon
Jan 3 at 18:39




1




1





Found the original ones. They were created by marmot: tex.stackexchange.com/a/411361/117050 and tex.stackexchange.com/a/411655/117050 use the approach.

– Skillmon
Jan 3 at 18:43





Found the original ones. They were created by marmot: tex.stackexchange.com/a/411361/117050 and tex.stackexchange.com/a/411655/117050 use the approach.

– Skillmon
Jan 3 at 18:43











4














Redefining uline to include a redefinition of colorbox.



documentclass[12pt]{article}
usepackage[T1]{fontenc}
usepackage[utf8]{inputenc}
usepackage{lmodern}
usepackage{xcolor}
usepackage[normalem]{ulem}

makeatletter
longdefafterelsefi#1else#2fi{fi#1}
longdefafterfi#1fi{fi#1}
defq@mark{q@mark}
newcommanduline@colorbox[3][q@mark]
{%
ifxq@mark#1%
afterelseficolorbox@orig{#2}%
else
afterficolorbox@orig[#1]{#2}%
fi
{%
% nested uline becomes a second rule which is a bit lower than first
% the following changes the values of UL@height and ULdepth so that the
% calculation done by ulem results in the original values
advanceUL@heightULdepth
advanceULdepth-thr@@UL@height
hskip-fboxsep
uline{hskipfboxsep#3hskipfboxsep}%
hskip-fboxsep
}%
}
letcolorbox@origcolorbox
protecteddefuline
{%
relax
ifmmode
expandafterunderline
else
bgroup
letcolorboxuline@colorbox % this is added compared to the original definition
expandafterULset
fi
}
makeatother

begin{document}

uline{No underlining for colorbox{lightgray}{everything} inside the colorbox.}

end{document}


enter image description here






share|improve this answer


























  • @Jayjayyy if I knew with certainty it wouldn't be necessary to use this ugly value. Seems to be because of the nesting of uline (I'll take another thorough look). .42774ex was determined by trial and error and a big zoom.

    – Skillmon
    Jan 2 at 22:28











  • @Jayjayyy found the issue and fixed it.

    – Skillmon
    Jan 2 at 22:33
















4














Redefining uline to include a redefinition of colorbox.



documentclass[12pt]{article}
usepackage[T1]{fontenc}
usepackage[utf8]{inputenc}
usepackage{lmodern}
usepackage{xcolor}
usepackage[normalem]{ulem}

makeatletter
longdefafterelsefi#1else#2fi{fi#1}
longdefafterfi#1fi{fi#1}
defq@mark{q@mark}
newcommanduline@colorbox[3][q@mark]
{%
ifxq@mark#1%
afterelseficolorbox@orig{#2}%
else
afterficolorbox@orig[#1]{#2}%
fi
{%
% nested uline becomes a second rule which is a bit lower than first
% the following changes the values of UL@height and ULdepth so that the
% calculation done by ulem results in the original values
advanceUL@heightULdepth
advanceULdepth-thr@@UL@height
hskip-fboxsep
uline{hskipfboxsep#3hskipfboxsep}%
hskip-fboxsep
}%
}
letcolorbox@origcolorbox
protecteddefuline
{%
relax
ifmmode
expandafterunderline
else
bgroup
letcolorboxuline@colorbox % this is added compared to the original definition
expandafterULset
fi
}
makeatother

begin{document}

uline{No underlining for colorbox{lightgray}{everything} inside the colorbox.}

end{document}


enter image description here






share|improve this answer


























  • @Jayjayyy if I knew with certainty it wouldn't be necessary to use this ugly value. Seems to be because of the nesting of uline (I'll take another thorough look). .42774ex was determined by trial and error and a big zoom.

    – Skillmon
    Jan 2 at 22:28











  • @Jayjayyy found the issue and fixed it.

    – Skillmon
    Jan 2 at 22:33














4












4








4







Redefining uline to include a redefinition of colorbox.



documentclass[12pt]{article}
usepackage[T1]{fontenc}
usepackage[utf8]{inputenc}
usepackage{lmodern}
usepackage{xcolor}
usepackage[normalem]{ulem}

makeatletter
longdefafterelsefi#1else#2fi{fi#1}
longdefafterfi#1fi{fi#1}
defq@mark{q@mark}
newcommanduline@colorbox[3][q@mark]
{%
ifxq@mark#1%
afterelseficolorbox@orig{#2}%
else
afterficolorbox@orig[#1]{#2}%
fi
{%
% nested uline becomes a second rule which is a bit lower than first
% the following changes the values of UL@height and ULdepth so that the
% calculation done by ulem results in the original values
advanceUL@heightULdepth
advanceULdepth-thr@@UL@height
hskip-fboxsep
uline{hskipfboxsep#3hskipfboxsep}%
hskip-fboxsep
}%
}
letcolorbox@origcolorbox
protecteddefuline
{%
relax
ifmmode
expandafterunderline
else
bgroup
letcolorboxuline@colorbox % this is added compared to the original definition
expandafterULset
fi
}
makeatother

begin{document}

uline{No underlining for colorbox{lightgray}{everything} inside the colorbox.}

end{document}


enter image description here






share|improve this answer















Redefining uline to include a redefinition of colorbox.



documentclass[12pt]{article}
usepackage[T1]{fontenc}
usepackage[utf8]{inputenc}
usepackage{lmodern}
usepackage{xcolor}
usepackage[normalem]{ulem}

makeatletter
longdefafterelsefi#1else#2fi{fi#1}
longdefafterfi#1fi{fi#1}
defq@mark{q@mark}
newcommanduline@colorbox[3][q@mark]
{%
ifxq@mark#1%
afterelseficolorbox@orig{#2}%
else
afterficolorbox@orig[#1]{#2}%
fi
{%
% nested uline becomes a second rule which is a bit lower than first
% the following changes the values of UL@height and ULdepth so that the
% calculation done by ulem results in the original values
advanceUL@heightULdepth
advanceULdepth-thr@@UL@height
hskip-fboxsep
uline{hskipfboxsep#3hskipfboxsep}%
hskip-fboxsep
}%
}
letcolorbox@origcolorbox
protecteddefuline
{%
relax
ifmmode
expandafterunderline
else
bgroup
letcolorboxuline@colorbox % this is added compared to the original definition
expandafterULset
fi
}
makeatother

begin{document}

uline{No underlining for colorbox{lightgray}{everything} inside the colorbox.}

end{document}


enter image description here







share|improve this answer














share|improve this answer



share|improve this answer








edited Jan 2 at 22:36

























answered Jan 2 at 20:15









SkillmonSkillmon

21.3k11941




21.3k11941













  • @Jayjayyy if I knew with certainty it wouldn't be necessary to use this ugly value. Seems to be because of the nesting of uline (I'll take another thorough look). .42774ex was determined by trial and error and a big zoom.

    – Skillmon
    Jan 2 at 22:28











  • @Jayjayyy found the issue and fixed it.

    – Skillmon
    Jan 2 at 22:33



















  • @Jayjayyy if I knew with certainty it wouldn't be necessary to use this ugly value. Seems to be because of the nesting of uline (I'll take another thorough look). .42774ex was determined by trial and error and a big zoom.

    – Skillmon
    Jan 2 at 22:28











  • @Jayjayyy found the issue and fixed it.

    – Skillmon
    Jan 2 at 22:33

















@Jayjayyy if I knew with certainty it wouldn't be necessary to use this ugly value. Seems to be because of the nesting of uline (I'll take another thorough look). .42774ex was determined by trial and error and a big zoom.

– Skillmon
Jan 2 at 22:28





@Jayjayyy if I knew with certainty it wouldn't be necessary to use this ugly value. Seems to be because of the nesting of uline (I'll take another thorough look). .42774ex was determined by trial and error and a big zoom.

– Skillmon
Jan 2 at 22:28













@Jayjayyy found the issue and fixed it.

– Skillmon
Jan 2 at 22:33





@Jayjayyy found the issue and fixed it.

– Skillmon
Jan 2 at 22:33











2














Don't underline. Ever.



If you don't want to adhere to the advice above, be aware that when you call uline inside uline the macro adds a further 1.2pt, because it thinks you want to double underline.



documentclass[12pt]{article}
usepackage[T1]{fontenc}
usepackage[utf8]{inputenc}
usepackage{lmodern}
usepackage{xcolor}
usepackage[normalem]{ulem}

letulemulineuline
renewcommand{uline}[1]{%
begingroup
redefinecolorbox
ulemuline{#1}%
endgroup
}
letlatexcolorboxcolorbox
newcommandredefinecolorbox{%
renewcommandcolorbox[2]{%
latexcolorbox{##1}{%
advanceULdepth-1.2pt
kern-fboxsep
ulemuline{hspace{fboxsep}##2hspace{fboxsep}}%
kern-fboxsep
}%
}%
}

begin{document}

uline{No underlining for colorbox{lightgray}{everything} inside the colorbox.}

end{document}


enter image description here






share|improve this answer


























  • @Jayjayyy I mean “don't underline”. At all.

    – egreg
    Jan 6 at 9:37











  • @Jayjayyy Underlining is not considered a typographic device. It used to be common with typewriters lacking any other method for emphasis.

    – egreg
    Jan 6 at 13:34











  • Okay, thanks :-) That's important to know. Could you add that to your answer? I have removed my former comments. Do you have a link to a good explanation on that?

    – finefoot
    Jan 6 at 14:00











  • @Jayjayyy using common sense (so no reference here), it just looks too intrusive when there are other means to emphasize stuff. For the same reason bold should only be used sparsely and not for regular emphasizes, which is the reason why emph doesn't print bold but italic by default. Also it destroys the balanced look of text if used inside of a paragraph. Maybe the most dominant reason: Word processor users tend to underline.

    – Skillmon
    Jan 6 at 14:09











  • @Skillmon I think, I have to say that I agree after hearing both your and egreg's arguments. However, it wasn't obvious to me before. I'm not as familiar with typesetting - even with something as basic as emphasis - so "Using common sense" didn't help me here. I think a reference as to why the statement "Don't underline. Ever." makes sense would improve this answer since I could have just clicked on it instead of bothering you. It might help someone who's in the same shoes as I was a few moments ago. :-)

    – finefoot
    Jan 6 at 14:16
















2














Don't underline. Ever.



If you don't want to adhere to the advice above, be aware that when you call uline inside uline the macro adds a further 1.2pt, because it thinks you want to double underline.



documentclass[12pt]{article}
usepackage[T1]{fontenc}
usepackage[utf8]{inputenc}
usepackage{lmodern}
usepackage{xcolor}
usepackage[normalem]{ulem}

letulemulineuline
renewcommand{uline}[1]{%
begingroup
redefinecolorbox
ulemuline{#1}%
endgroup
}
letlatexcolorboxcolorbox
newcommandredefinecolorbox{%
renewcommandcolorbox[2]{%
latexcolorbox{##1}{%
advanceULdepth-1.2pt
kern-fboxsep
ulemuline{hspace{fboxsep}##2hspace{fboxsep}}%
kern-fboxsep
}%
}%
}

begin{document}

uline{No underlining for colorbox{lightgray}{everything} inside the colorbox.}

end{document}


enter image description here






share|improve this answer


























  • @Jayjayyy I mean “don't underline”. At all.

    – egreg
    Jan 6 at 9:37











  • @Jayjayyy Underlining is not considered a typographic device. It used to be common with typewriters lacking any other method for emphasis.

    – egreg
    Jan 6 at 13:34











  • Okay, thanks :-) That's important to know. Could you add that to your answer? I have removed my former comments. Do you have a link to a good explanation on that?

    – finefoot
    Jan 6 at 14:00











  • @Jayjayyy using common sense (so no reference here), it just looks too intrusive when there are other means to emphasize stuff. For the same reason bold should only be used sparsely and not for regular emphasizes, which is the reason why emph doesn't print bold but italic by default. Also it destroys the balanced look of text if used inside of a paragraph. Maybe the most dominant reason: Word processor users tend to underline.

    – Skillmon
    Jan 6 at 14:09











  • @Skillmon I think, I have to say that I agree after hearing both your and egreg's arguments. However, it wasn't obvious to me before. I'm not as familiar with typesetting - even with something as basic as emphasis - so "Using common sense" didn't help me here. I think a reference as to why the statement "Don't underline. Ever." makes sense would improve this answer since I could have just clicked on it instead of bothering you. It might help someone who's in the same shoes as I was a few moments ago. :-)

    – finefoot
    Jan 6 at 14:16














2












2








2







Don't underline. Ever.



If you don't want to adhere to the advice above, be aware that when you call uline inside uline the macro adds a further 1.2pt, because it thinks you want to double underline.



documentclass[12pt]{article}
usepackage[T1]{fontenc}
usepackage[utf8]{inputenc}
usepackage{lmodern}
usepackage{xcolor}
usepackage[normalem]{ulem}

letulemulineuline
renewcommand{uline}[1]{%
begingroup
redefinecolorbox
ulemuline{#1}%
endgroup
}
letlatexcolorboxcolorbox
newcommandredefinecolorbox{%
renewcommandcolorbox[2]{%
latexcolorbox{##1}{%
advanceULdepth-1.2pt
kern-fboxsep
ulemuline{hspace{fboxsep}##2hspace{fboxsep}}%
kern-fboxsep
}%
}%
}

begin{document}

uline{No underlining for colorbox{lightgray}{everything} inside the colorbox.}

end{document}


enter image description here






share|improve this answer















Don't underline. Ever.



If you don't want to adhere to the advice above, be aware that when you call uline inside uline the macro adds a further 1.2pt, because it thinks you want to double underline.



documentclass[12pt]{article}
usepackage[T1]{fontenc}
usepackage[utf8]{inputenc}
usepackage{lmodern}
usepackage{xcolor}
usepackage[normalem]{ulem}

letulemulineuline
renewcommand{uline}[1]{%
begingroup
redefinecolorbox
ulemuline{#1}%
endgroup
}
letlatexcolorboxcolorbox
newcommandredefinecolorbox{%
renewcommandcolorbox[2]{%
latexcolorbox{##1}{%
advanceULdepth-1.2pt
kern-fboxsep
ulemuline{hspace{fboxsep}##2hspace{fboxsep}}%
kern-fboxsep
}%
}%
}

begin{document}

uline{No underlining for colorbox{lightgray}{everything} inside the colorbox.}

end{document}


enter image description here







share|improve this answer














share|improve this answer



share|improve this answer








edited Jan 6 at 9:45

























answered Jan 2 at 22:05









egregegreg

711k8618913174




711k8618913174













  • @Jayjayyy I mean “don't underline”. At all.

    – egreg
    Jan 6 at 9:37











  • @Jayjayyy Underlining is not considered a typographic device. It used to be common with typewriters lacking any other method for emphasis.

    – egreg
    Jan 6 at 13:34











  • Okay, thanks :-) That's important to know. Could you add that to your answer? I have removed my former comments. Do you have a link to a good explanation on that?

    – finefoot
    Jan 6 at 14:00











  • @Jayjayyy using common sense (so no reference here), it just looks too intrusive when there are other means to emphasize stuff. For the same reason bold should only be used sparsely and not for regular emphasizes, which is the reason why emph doesn't print bold but italic by default. Also it destroys the balanced look of text if used inside of a paragraph. Maybe the most dominant reason: Word processor users tend to underline.

    – Skillmon
    Jan 6 at 14:09











  • @Skillmon I think, I have to say that I agree after hearing both your and egreg's arguments. However, it wasn't obvious to me before. I'm not as familiar with typesetting - even with something as basic as emphasis - so "Using common sense" didn't help me here. I think a reference as to why the statement "Don't underline. Ever." makes sense would improve this answer since I could have just clicked on it instead of bothering you. It might help someone who's in the same shoes as I was a few moments ago. :-)

    – finefoot
    Jan 6 at 14:16



















  • @Jayjayyy I mean “don't underline”. At all.

    – egreg
    Jan 6 at 9:37











  • @Jayjayyy Underlining is not considered a typographic device. It used to be common with typewriters lacking any other method for emphasis.

    – egreg
    Jan 6 at 13:34











  • Okay, thanks :-) That's important to know. Could you add that to your answer? I have removed my former comments. Do you have a link to a good explanation on that?

    – finefoot
    Jan 6 at 14:00











  • @Jayjayyy using common sense (so no reference here), it just looks too intrusive when there are other means to emphasize stuff. For the same reason bold should only be used sparsely and not for regular emphasizes, which is the reason why emph doesn't print bold but italic by default. Also it destroys the balanced look of text if used inside of a paragraph. Maybe the most dominant reason: Word processor users tend to underline.

    – Skillmon
    Jan 6 at 14:09











  • @Skillmon I think, I have to say that I agree after hearing both your and egreg's arguments. However, it wasn't obvious to me before. I'm not as familiar with typesetting - even with something as basic as emphasis - so "Using common sense" didn't help me here. I think a reference as to why the statement "Don't underline. Ever." makes sense would improve this answer since I could have just clicked on it instead of bothering you. It might help someone who's in the same shoes as I was a few moments ago. :-)

    – finefoot
    Jan 6 at 14:16

















@Jayjayyy I mean “don't underline”. At all.

– egreg
Jan 6 at 9:37





@Jayjayyy I mean “don't underline”. At all.

– egreg
Jan 6 at 9:37













@Jayjayyy Underlining is not considered a typographic device. It used to be common with typewriters lacking any other method for emphasis.

– egreg
Jan 6 at 13:34





@Jayjayyy Underlining is not considered a typographic device. It used to be common with typewriters lacking any other method for emphasis.

– egreg
Jan 6 at 13:34













Okay, thanks :-) That's important to know. Could you add that to your answer? I have removed my former comments. Do you have a link to a good explanation on that?

– finefoot
Jan 6 at 14:00





Okay, thanks :-) That's important to know. Could you add that to your answer? I have removed my former comments. Do you have a link to a good explanation on that?

– finefoot
Jan 6 at 14:00













@Jayjayyy using common sense (so no reference here), it just looks too intrusive when there are other means to emphasize stuff. For the same reason bold should only be used sparsely and not for regular emphasizes, which is the reason why emph doesn't print bold but italic by default. Also it destroys the balanced look of text if used inside of a paragraph. Maybe the most dominant reason: Word processor users tend to underline.

– Skillmon
Jan 6 at 14:09





@Jayjayyy using common sense (so no reference here), it just looks too intrusive when there are other means to emphasize stuff. For the same reason bold should only be used sparsely and not for regular emphasizes, which is the reason why emph doesn't print bold but italic by default. Also it destroys the balanced look of text if used inside of a paragraph. Maybe the most dominant reason: Word processor users tend to underline.

– Skillmon
Jan 6 at 14:09













@Skillmon I think, I have to say that I agree after hearing both your and egreg's arguments. However, it wasn't obvious to me before. I'm not as familiar with typesetting - even with something as basic as emphasis - so "Using common sense" didn't help me here. I think a reference as to why the statement "Don't underline. Ever." makes sense would improve this answer since I could have just clicked on it instead of bothering you. It might help someone who's in the same shoes as I was a few moments ago. :-)

– finefoot
Jan 6 at 14:16





@Skillmon I think, I have to say that I agree after hearing both your and egreg's arguments. However, it wasn't obvious to me before. I'm not as familiar with typesetting - even with something as basic as emphasis - so "Using common sense" didn't help me here. I think a reference as to why the statement "Don't underline. Ever." makes sense would improve this answer since I could have just clicked on it instead of bothering you. It might help someone who's in the same shoes as I was a few moments ago. :-)

– finefoot
Jan 6 at 14:16


















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%2f468307%2fredefine-uline-so-colorbox-is-locally-defined-to-have-underlined-text-too%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

Human spaceflight

Can not write log (Is /dev/pts mounted?) - openpty in Ubuntu-on-Windows?

張江高科駅