2

What is the difference between \hbox and \mbox?

What are these commands intended to do?

I cannot see what they do from my code alone without a word explanation...

user2925716
  • 1,940

1 Answers1

6

As mentioned in a comment, \mbox leaves vertical mode before employing an \hbox. But the question also seemed to encompass "what is a box"?

So, this answer tries to answer both issues. The first three examples compare boxed text to unboxed text. The last example addresses when leaving vertical mode makes a difference.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\parindent0pt
\begin{document}

Mbox Meaning: \meaning\mbox

\hrulefill

\textbf{BOXES ARE UNBREAKABLE}

This is a texting piece of text. This is a texting piece of text.
This is a texting piece of text.

\mbox{This is a texting piece of text. This is a texting piece of text.
This is a texting piece of text.}

\hrulefill

\textbf{BOXES ARE UNHYPHENATABLE}

This is a texting piece of text. This is texting piece of text.
This is an hyphenatable piece of text.

This is a texting piece of text. This is texting piece of text.
This is an \mbox{hyphenatable} piece of text.

\hrulefill

\textbf{BOXES ARE UNSTRETCHABLE}

This is a texting piece of text. This is the texting piece of text.
This is a texting piece of text.

This is a texting \mbox{piece of text. This is the texting piece of text.}
This is a texting piece of text.

\hrulefill

\textbf{WHEN LEAVING VERTICAL MODE MAKES A DIFFERENCE}
\parskip 1ex

blah

\mbox{Regular line space with mbox}

\hbox{Irregular line space with hbox}

blah
\end{document}

enter image description here

  • I actually do not understand what difference makes leaving vertical mode in this example: \textbf{WHEN LEAVING VERTICAL MODE MAKES A DIFFERENCE}... – user2925716 Feb 16 '19 at 17:43
  • 1
    @user2925716 The vertical gap above the line "Irregular line space..." is less than a normal paragaph break. Why? Because that line (an \hbox) was set in vertical mode, so all the close-out-the-one-paragraph-and-begin-the-next-paragraph instructions were never executed. – Steven B. Segletes Feb 16 '19 at 17:51