These two commands seem identical, and I haven't found enough materials on \underbar.

  • What's the difference?
  • and which doc/book has covered that?
  • 1
    Welcome to TeX.SE. – Mico Oct 23 '20 at 9:31

Plain TeX

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

  \m@th \underline{\box\z@}$}

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

% \underline{abpq} % gives `Missing $ inserted.' error.
% $\underbar{abpq}$ % gives `Missing $ inserted.' error.


enter image description here


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:

  \else $\@@underline{\hbox{#1}}\m@th$\relax\fi}

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


Quoting from source2e

Due to LaTeX's redefinition of \underline plain TeX's \underbar can be done in a simpler fashion (but do we need it at all?).

and in fact is a rather undocumented command.

As in plain TeX, \underbar sets the depth of the box to zero and will clash with descenders. \underbar can be used both in text and 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$}.



\underline{abpq} vs \underbar{abpq}

$\underline{abpq}$ vs $\underbar{abpq}$

% both the following work:
$\underline{\gamma}$ or \underline{$\gamma$}

% this works

% this givese a `Missing $ inserted' error


enter image description here

  • \underbar:

    • Its argument is processed in text mode by default. You need to enter math mode explicitly to process, say, \underbar{$\alpha$}.
    • The horizontal line is set very close to the baseline, and will therefore intersect any parts of letters and symbols that have descenders, i.e., portions that fall below the baseline (e.g., g and $\gamma$).
  • \underline:

    • Its argument respects the surrounding (text or math) mode
    • The horizontal line is shifted down, as needed, to avoid collisions with descender portions of any characters

enter image description here

$\underline{\alpha\beta\gamma}$ \underbar{$\alpha\beta\gamma$}

$\underline{effg}$ $\underbar{effg}$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.