Redefine `uline` so `colorbox` is locally defined to have underlined text, too
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.}
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.}
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
add a comment |
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.}
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.}
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
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
1 hour 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
1 hour 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
1 hour ago
add a comment |
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.}
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.}
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
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.}
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.}
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
macros formatting ulem underline colorbox
asked 1 hour 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
1 hour 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
1 hour 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
1 hour ago
add a comment |
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
1 hour 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
1 hour 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
1 hour 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
1 hour 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
1 hour 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
1 hour 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
1 hour 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
1 hour 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
1 hour ago
add a comment |
2 Answers
2
active
oldest
votes
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}
1
Two wonderful examples of beautiful typography ;-)
– Christian Hupfer
58 mins ago
add a comment |
For reasons beyond my understanding the depth of the underline in the colorbox
doesn't work out automatically, so the following is using a rather ugly ULdepth=.42774ex
.
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
{%
ULdepth=.42774ex % this is dirty
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}
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "85"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%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
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
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}
1
Two wonderful examples of beautiful typography ;-)
– Christian Hupfer
58 mins ago
add a comment |
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}
1
Two wonderful examples of beautiful typography ;-)
– Christian Hupfer
58 mins ago
add a comment |
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}
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}
edited 1 hour ago
answered 1 hour ago
Christian Hupfer
148k14193387
148k14193387
1
Two wonderful examples of beautiful typography ;-)
– Christian Hupfer
58 mins ago
add a comment |
1
Two wonderful examples of beautiful typography ;-)
– Christian Hupfer
58 mins ago
1
1
Two wonderful examples of beautiful typography ;-)
– Christian Hupfer
58 mins ago
Two wonderful examples of beautiful typography ;-)
– Christian Hupfer
58 mins ago
add a comment |
For reasons beyond my understanding the depth of the underline in the colorbox
doesn't work out automatically, so the following is using a rather ugly ULdepth=.42774ex
.
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
{%
ULdepth=.42774ex % this is dirty
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}
add a comment |
For reasons beyond my understanding the depth of the underline in the colorbox
doesn't work out automatically, so the following is using a rather ugly ULdepth=.42774ex
.
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
{%
ULdepth=.42774ex % this is dirty
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}
add a comment |
For reasons beyond my understanding the depth of the underline in the colorbox
doesn't work out automatically, so the following is using a rather ugly ULdepth=.42774ex
.
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
{%
ULdepth=.42774ex % this is dirty
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}
For reasons beyond my understanding the depth of the underline in the colorbox
doesn't work out automatically, so the following is using a rather ugly ULdepth=.42774ex
.
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
{%
ULdepth=.42774ex % this is dirty
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}
answered 49 mins ago
Skillmon
21.1k11941
21.1k11941
add a comment |
add a comment |
Thanks for contributing an answer to TeX - LaTeX Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
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
1 hour 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
1 hour 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
1 hour ago