Underline in LaTeX: \underline, ulem, soul and Math

November 11, 2026 · 9 min read

Underline in LaTeX: \underline, ulem, soul and \underbrace

To underline in LaTeX, wrap a word or short phrase in \underline{...}. It needs no package and works in text and math. For a sentence that has to wrap onto the next line, load ulem and use \uline, or load soul and use \ul. In equations, \underbrace puts a labeled brace under a group of terms.

How Do You Underline in LaTeX With \underline?

\underline is part of the LaTeX kernel, so it works in any document without loading anything. Put the text in braces and LaTeX draws a rule beneath it.

Read the \underline{whole} contract before you sign.
Compare \underline{gym} with \underline{axe}.

The first line prints "whole" with a line under it. The second line shows a quirk you'll notice in real documents. According to the LaTeX2e reference manual, the line always sits completely below the text, taking descenders into account. So the rule under "gym" drops lower than the rule under "axe", and a sentence with several underlined words looks uneven.

The same command works inside math, as in $\underline{x+y}$, and it nests inside other formatting, so \textbf{\underline{Note}} gives bold underlined text. Some engineering texts use an underlined letter to mark a vector. You'll also see \underline{\hspace{4cm}} used to draw a fill-in blank on printed forms.

Why a Long \underline Runs Past the Margin

\underline packs its whole argument into one rigid box. TeX can't break a line inside a box, and it can't hyphenate the words in it either. A short phrase is fine. A long one pushes straight through the right margin.

This sentence ends with \underline{a long underlined phrase that keeps
going well past the right margin of the page without wrapping}.

In our pdfLaTeX test with the article class, the log reported an Overfull \hbox about 210pt too wide, and the underlined text ran off the edge of the page. Nothing you do inside the braces fixes this. You need a package that underlines word by word, which is exactly what ulem and soul do.

Underline Paragraphs With ulem: \uline, \uuline and \uwave

The ulem package gives you underlines that break between words, plus four extra styles. Load it with the normalem option.

\usepackage[normalem]{ulem}
...
\uline{a single underline that can wrap onto the next line}
\uuline{double underline}
\uwave{wavy underline}
\dashuline{dashed underline}
\dotuline{dotted underline}

Each command draws what its name says. ulem puts every word in its own underlined box, so lines break at spaces. The trade-off, per the package documentation, is that automatic hyphenation is switched off inside the argument, though a manual \- still works.

Why normalem? Without it, ulem redefines \emph so that emphasis prints as underlined upright text instead of italics. The same package also provides strike-out commands such as \sout and \xout.

ulem also lets you set the position and weight of the line.

\setlength{\ULdepth}{2pt}
\renewcommand{\ULthickness}{0.8pt}

\ULdepth is a length, so you change it with \setlength. \ULthickness is a macro (default 0.4pt in ulem.sty), and the documentation says to use \renewcommand, not \setlength. By default the depth comes from the current font, not from each word, so \uline also avoids the uneven "gym" and "axe" problem from the first section.

Line-Breaking Underlines With soul's \ul

The soul package takes a different route. Its CTAN entry says it runs TeX's own hyphenation algorithm, so underlined words can split at a hyphen like ordinary text. That makes it the better fit when you underline LaTeX text in narrow columns or long passages.

\usepackage{xcolor}
\usepackage{soul}
...
\setul{0.5ex}{0.2ex}
\setulcolor{red}
\ul{an underlined passage that soul can hyphenate and break across lines}

\setul takes the depth first and the thickness second. Its defaults in the soul source are 0.65ex and 0.1ex. \setulcolor needs the color or xcolor package. Without one, soul silently ignores the command in the document body. Call it in the preamble instead and the first \ul stops pdfLaTeX with an undefined control sequence error.

soul reads its argument token by token, so some commands confuse it. It already knows standard font commands such as \textbf and \texttt, and \soulregister teaches it others. References break it: \ul{see Section~\ref{sec:one}} fails under pdfLaTeX with an extra-brace error. The soul manual's fix for awkward material is to protect it, so write \mbox{\ref{sec:one}} inside the underline.

If you build with LuaLaTeX, the lua-ul package offers \underLine, which hyphenates and accepts arbitrary commands inside the argument. It needs LuaTeX 1.12.0 or newer.

ulem vs soul: Which LaTeX Underline Package Fits?

Here's how the four options compare for a LaTeX underline in running text.

PackageCommandBreaks linesHyphenatesExtra stylesWatch out for
Kernel\underlineNoNoNoneLong text overflows the margin
ulem\ulineAt spacesManual \- onlyDouble, wavy, dashed, dottedTurns \emph into underlines unless you load [normalem]
soul\ulYesYesColor, depth and thickness\ref and unknown commands inside the argument
lua-ul\underLineYesYesStrike-through and highlightingLuaLaTeX only

Our pick for most papers and reports is ulem. \uline copes with mixed content, and the double, wavy, dashed and dotted styles come in the same package. Choose soul when underlined text sits in a narrow column and gaps at the line end would look bad. If your project already builds with LuaLaTeX, lua-ul avoids the restrictions of both.

Underlining in Math Mode: \underbrace, \underset and Friends

Math has its own underline commands, and none of them need ulem or soul. Our Markdown equation guide covers general math syntax, so this section sticks to what goes under an expression. For the _ and ^ syntax that attaches a label to a brace, see our LaTeX subscript and superscript guide.

\usepackage{amsmath} % for \underset and \text
...
\[ \underline{x+y} \qquad \underline{\underline{x}} \]
\[ \underbrace{a+b+c}_{\text{three terms}} = s \]
\[ x \underset{\text{def}}{=} y \]

The first line shows a plain underline and a nested double underline. \underbrace draws a horizontal brace and places the subscript beneath it as a label. You can attach a superscript too, but the reference manual warns that it sits on top of the expression and can look unconnected to the brace. Braced labels add height, so they read best in display math rather than in the middle of a sentence.

\underset puts any small expression under a symbol, here "def" under an equals sign. Unlike \underline and \underbrace, it isn't in the kernel, so compiled LaTeX needs amsmath. For a square bracket instead of a curly one, mathtools adds \underbracket. \overline and \overbrace are the mirror images that draw above. If you write \uline inside math, ulem simply falls back to \underline.

Which Underline Commands Render in Markdown Math and KaTeX?

Markdown editors, wikis and notebooks usually render math with KaTeX or MathJax, not a full TeX engine. There's no preamble, so \usepackage doesn't exist, and package commands like \uline are undefined. The math-mode commands are a different story. We checked each one against the KaTeX supported functions list and rendered it with KaTeX 0.16.

CommandCompiled LaTeXKaTeX (Markdown math)
\underlineBuilt inYes
\underbraceBuilt inYes
\undersetNeeds amsmathYes
\underrightarrow, \underleftarrowNeeds amsmathYes
\underbracketNeeds mathtoolsOnly KaTeX 0.16.42 and later
\uline, \uuline, \uwaveNeeds ulemNo
\ulNeeds soulNo

KaTeX also has \utilde for a wide tilde under a group. \underbracket arrived in KaTeX 0.16.42 in March 2026, so older builds still show a parse error for it. Our KaTeX vs LaTeX comparison covers what else KaTeX leaves out.

In our editor, math goes between $...$ for inline and $$...$$ for display. One limitation to know: of the LaTeX commands here, the preview renders only the math-mode ones. ulem and soul text underlines need a compiled LaTeX document. If you want underlined prose in Markdown itself, that's an HTML question, covered in our Markdown underline guide.

Edit the demo below and the preview updates as you type.

Underlines in math

Inline: x+y‾\underline{x+y} and a double underline x‾‾\underline{\underline{x}}

Annotated sum:

a+b+c⏟three terms=s\underbrace{a+b+c}_{\text{three terms}} = s

A label under a symbol: x=defyx \underset{\text{def}}{=} y

Arrow and tilde under a group: AB→\underrightarrow{AB} and AB~\utilde{AB}

34 words293 characters11 lines
Markdown

To turn one of these into an image for slides or a document, build it in the LaTeX equation editor. It renders with KaTeX in your browser and exports PNG or SVG.

Underline in LaTeX: Quick Answers

To underline in LaTeX, pick the command by where the line goes. Use \underline for a word or two, and ulem or soul when the text has to wrap. Reach for \underbrace or \underset when the underline belongs to an equation. Only those math-mode commands work in Markdown math. Paste them into the editor to check the result next to your notes, or read our bold and italic guide for the Markdown side of emphasis.