TeX - LaTeX Asked by Strong Nole on November 27, 2020
These two commands seem identical, and I haven’t found enough materials on underbar
.
The TeX command underline
is a math mode primitive which places a line under a character or subformula without changing the math style; in text mode it throws a Missing $ inserted
error. Furthermore, plain TeX defines
defunderbar#1{$setboxz@hbox{#1}dpz@z@
m@th underline{boxz@}$}
which is basically the "text mode version" of underline
but sets the depth of its argument to zero, which means that the underline will interfere with letters with descenders (g
, p
, q
, y
...). The snippet
underbar{abpq}
$underline{abpq}$
% underline{abpq} % gives `Missing $ inserted.' error.
bye
yields
LaTeX changes things a bit: first it makes a copy of the original primitive under the name @@underline
, and then underline
is redefined as a wrapper around this saved primitive which enters math mode if necessary, such that it works both in text and math mode:
let@@underlineunderline
defunderline#1{%
relax
ifmmode@@underline{#1}%
else $@@underline{hbox{#1}}m@th$relaxfi}
Therefore, in math mode you'll get the usual result, but the macro will now work also in text mode, drawing a line lower than all letters.
The macro underbar
is defined to have a similar effect as its plain TeX variant but keeping the modification of underline
in mind
defunderbar#1{underline{sboxtw@{#1}dptw@z@boxtw@}}
Quoting from source2e
Due to LaTeX's redefinition of
underline
plain TeX'sunderbar
can be done in a simpler fashion (but do we need it at all?).
and in fact is a rather undocumented command.
underbar
again sets the depth of the box to zero and will clash with descenders:
documentclass{article}
begin{document}
underline{abc} vs underbar{abc}
underline{abp} vs underbar{abp}
end{document}
Note that underbar
can be used also in math mode but puts its content in a box, so in restricted horizontal mode. If you want to use underbar
with e.g. gamma
and of course they'll clash) you need to enter explicitly math mode again: underbar{$gamma$}
.
Answered by campa on November 27, 2020
underbar
:
underbar{$alpha$}
.g
and $gamma$).underline
:
documentclass{article}
begin{document}
$underline{alphabetagamma}$ underbar{$alphabetagamma$}
$underline{effg}$ $underbar{effg}$
end{document}
Answered by Mico on November 27, 2020
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP