• \textit is canceled by \textup
  • \itshape is canceled by \upshape
  • \textbf is canceled by \textmd
  • \bfseries is canceled by \mdseries
  • \normalfont cancels everything

What cancles \underline?


\textit{Some italic and some \textup{upright} text.}\\
{\itshape Some italic and some {\upshape upright} text.}\\
\textbf{Some bold and some \textmd{non-bold} text.}\\
{\bfseries Some bold and some {\mdseries non-bold} text.}\\
\underline{Some underlined and some {\normalfont non-underlined} text.}

enter image description here

Inspired by question “How to set not italic or not bold?”

  • You may want to consider the \emph command, which works in a "nested" way: In abc \emph{def \emph{ghi} jkl} mno, the "inner" emphasized string ("ghi") is typeset using the upright font shape by default. The ulem ("underline emphasis"?) package does something interesting to \emph (unless the option normalem is set): an "outer" \emph generates underlined text, and an "inner" \emph generates double-underlined text. One could probably hack the package so that inner \emph material is typeset without underlining; this might look weird, though. – Mico May 2 '18 at 14:09
  • 2
    The ulem package also provides the command \uline, which is much more useful than underline: The former command allows line-breaking between words (but not hyphenation within words), whereas the latter doesn't allow any line-breaking. – Mico May 2 '18 at 14:12
  • 1
    See this answer and the link therein where it explains \underline is a quick fix added in LaTeX that uses \hbox and the math underbar. The box doesn't end until the braces are closes, so everything in between is underlined (and linebreaks are prevented.) – erik May 2 '18 at 14:13
  • 2
    your examples with fonts are not really related to the \underline question, if you switch fonts you can easily switch to a different font within that region. But \underline is more like \fbox if you box a run of text there is no particularly easy way to break out of that box, so you would have to redefine the underlining command to just underline your outer phrases and not underline the middle section. You can't from inside \underline stop the rule being drawn. – David Carlisle May 2 '18 at 14:45
  • Thanks, @all. I solved the my current intricate problem, which gave rise to this question, with l3regex/expl3. – st12 May 2 '18 at 17:23

In TeX \underline is a math-mode primitive, meaning that


yields an underlined abc, while


raises an error.

LaTeX makes a wrapper around this (latex.ltx lines 5043-5047)

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

Here, first the original primitive is stored under the name \@@underline, and then \underline is redefined to work also in text mode by putting its content in an \hbox (say goodbye to line breaks :-)) and then calling the (original) \@@underline in inline math $...$. So the short answer to your question is: there is nothing which cancels \underline.

One might hack e.g. into the ulem package to obtain something like what you want with \uline, but that's a quite different story.

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.