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












2














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
    3 hours ago










  • @ChristianHupfer Thanks for the feedback. However, I'm not sure what you mean. You mean "vertically" below the line, right? I don't think it looks too bad. In the complete documents it looks like someone highlighted certain words with a marker. If you would highlight by hand on a real sheet of paper, you wouldn't care about marking below the line either, would you? Maybe I'm misunderstanding you? :-) I'm open to suggestions how to improve the code.
    – Jayjayyy
    3 hours ago










  • Yes, 'vertically' below (below implies vertical, doesn't it? ;-) ... Well, marking up by hand is done most time without rulers, so it is not very precise, but in a printed document, we can achieve better look, I think.
    – Christian Hupfer
    2 hours ago
















2














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
    3 hours ago










  • @ChristianHupfer Thanks for the feedback. However, I'm not sure what you mean. You mean "vertically" below the line, right? I don't think it looks too bad. In the complete documents it looks like someone highlighted certain words with a marker. If you would highlight by hand on a real sheet of paper, you wouldn't care about marking below the line either, would you? Maybe I'm misunderstanding you? :-) I'm open to suggestions how to improve the code.
    – Jayjayyy
    3 hours ago










  • Yes, 'vertically' below (below implies vertical, doesn't it? ;-) ... Well, marking up by hand is done most time without rulers, so it is not very precise, but in a printed document, we can achieve better look, I think.
    – Christian Hupfer
    2 hours ago














2












2








2


1





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 3 hours ago









Jayjayyy

1939




1939












  • 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
    3 hours ago










  • @ChristianHupfer Thanks for the feedback. However, I'm not sure what you mean. You mean "vertically" below the line, right? I don't think it looks too bad. In the complete documents it looks like someone highlighted certain words with a marker. If you would highlight by hand on a real sheet of paper, you wouldn't care about marking below the line either, would you? Maybe I'm misunderstanding you? :-) I'm open to suggestions how to improve the code.
    – Jayjayyy
    3 hours ago










  • Yes, 'vertically' below (below implies vertical, doesn't it? ;-) ... Well, marking up by hand is done most time without rulers, so it is not very precise, but in a printed document, we can achieve better look, I think.
    – Christian Hupfer
    2 hours ago


















  • 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
    3 hours ago










  • @ChristianHupfer Thanks for the feedback. However, I'm not sure what you mean. You mean "vertically" below the line, right? I don't think it looks too bad. In the complete documents it looks like someone highlighted certain words with a marker. If you would highlight by hand on a real sheet of paper, you wouldn't care about marking below the line either, would you? Maybe I'm misunderstanding you? :-) I'm open to suggestions how to improve the code.
    – Jayjayyy
    3 hours ago










  • Yes, 'vertically' below (below implies vertical, doesn't it? ;-) ... Well, marking up by hand is done most time without rulers, so it is not very precise, but in a printed document, we can achieve better look, I think.
    – Christian Hupfer
    2 hours ago
















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
3 hours ago




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
3 hours ago












@ChristianHupfer Thanks for the feedback. However, I'm not sure what you mean. You mean "vertically" below the line, right? I don't think it looks too bad. In the complete documents it looks like someone highlighted certain words with a marker. If you would highlight by hand on a real sheet of paper, you wouldn't care about marking below the line either, would you? Maybe I'm misunderstanding you? :-) I'm open to suggestions how to improve the code.
– Jayjayyy
3 hours ago




@ChristianHupfer Thanks for the feedback. However, I'm not sure what you mean. You mean "vertically" below the line, right? I don't think it looks too bad. In the complete documents it looks like someone highlighted certain words with a marker. If you would highlight by hand on a real sheet of paper, you wouldn't care about marking below the line either, would you? Maybe I'm misunderstanding you? :-) I'm open to suggestions how to improve the code.
– Jayjayyy
3 hours ago












Yes, 'vertically' below (below implies vertical, doesn't it? ;-) ... Well, marking up by hand is done most time without rulers, so it is not very precise, but in a printed document, we can achieve better look, I think.
– Christian Hupfer
2 hours ago




Yes, 'vertically' below (below implies vertical, doesn't it? ;-) ... Well, marking up by hand is done most time without rulers, so it is not very precise, but in a printed document, we can achieve better look, I think.
– Christian Hupfer
2 hours ago










3 Answers
3






active

oldest

votes


















3














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
    2 hours ago










  • This isn't line breakable is it?
    – Skillmon
    5 mins ago



















2














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























  • Hey, thanks. :-) I'll test this as soon as possible. Where does the value .42774ex come from? And why isn't it necessary in the initial workaround solution?
    – Jayjayyy
    1 hour ago










  • @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
    19 mins ago










  • @Jayjayyy found the issue and fixed it.
    – Skillmon
    14 mins ago



















0














Don't underline.



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





















    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









    3














    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
      2 hours ago










    • This isn't line breakable is it?
      – Skillmon
      5 mins ago
















    3














    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
      2 hours ago










    • This isn't line breakable is it?
      – Skillmon
      5 mins ago














    3












    3








    3






    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 2 hours ago

























    answered 2 hours ago









    Christian Hupfer

    148k14193388




    148k14193388








    • 2




      Two wonderful examples of beautiful typography ;-)
      – Christian Hupfer
      2 hours ago










    • This isn't line breakable is it?
      – Skillmon
      5 mins ago














    • 2




      Two wonderful examples of beautiful typography ;-)
      – Christian Hupfer
      2 hours ago










    • This isn't line breakable is it?
      – Skillmon
      5 mins ago








    2




    2




    Two wonderful examples of beautiful typography ;-)
    – Christian Hupfer
    2 hours ago




    Two wonderful examples of beautiful typography ;-)
    – Christian Hupfer
    2 hours ago












    This isn't line breakable is it?
    – Skillmon
    5 mins ago




    This isn't line breakable is it?
    – Skillmon
    5 mins ago











    2














    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























    • Hey, thanks. :-) I'll test this as soon as possible. Where does the value .42774ex come from? And why isn't it necessary in the initial workaround solution?
      – Jayjayyy
      1 hour ago










    • @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
      19 mins ago










    • @Jayjayyy found the issue and fixed it.
      – Skillmon
      14 mins ago
















    2














    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























    • Hey, thanks. :-) I'll test this as soon as possible. Where does the value .42774ex come from? And why isn't it necessary in the initial workaround solution?
      – Jayjayyy
      1 hour ago










    • @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
      19 mins ago










    • @Jayjayyy found the issue and fixed it.
      – Skillmon
      14 mins ago














    2












    2








    2






    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 11 mins ago

























    answered 2 hours ago









    Skillmon

    21.1k11941




    21.1k11941












    • Hey, thanks. :-) I'll test this as soon as possible. Where does the value .42774ex come from? And why isn't it necessary in the initial workaround solution?
      – Jayjayyy
      1 hour ago










    • @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
      19 mins ago










    • @Jayjayyy found the issue and fixed it.
      – Skillmon
      14 mins ago


















    • Hey, thanks. :-) I'll test this as soon as possible. Where does the value .42774ex come from? And why isn't it necessary in the initial workaround solution?
      – Jayjayyy
      1 hour ago










    • @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
      19 mins ago










    • @Jayjayyy found the issue and fixed it.
      – Skillmon
      14 mins ago
















    Hey, thanks. :-) I'll test this as soon as possible. Where does the value .42774ex come from? And why isn't it necessary in the initial workaround solution?
    – Jayjayyy
    1 hour ago




    Hey, thanks. :-) I'll test this as soon as possible. Where does the value .42774ex come from? And why isn't it necessary in the initial workaround solution?
    – Jayjayyy
    1 hour ago












    @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
    19 mins ago




    @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
    19 mins ago












    @Jayjayyy found the issue and fixed it.
    – Skillmon
    14 mins ago




    @Jayjayyy found the issue and fixed it.
    – Skillmon
    14 mins ago











    0














    Don't underline.



    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


























      0














      Don't underline.



      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
























        0












        0








        0






        Don't underline.



        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.



        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










        answered 42 mins ago









        egreg

        709k8618833166




        709k8618833166






























            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%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

            Le Mesnil-Réaume

            Bundesstraße 106

            Ida-Boy-Ed-Garten