# \hbox

Low-level boxing of short text fragments inside math expressions.

https://texform.dev/latex/commands/hbox

## Metadata

| Field | Value |
| --- | --- |
| Topic | [Boxes and text](https://texform.dev/latex/topics/boxes-text) |
| Packages | base |
| Allowed mode | both |
| Tags | decoration, discouraged |
| Commonality | low |
| Kind | prefix |

## Syntax

### base

Argument specification: `m:T`

Low-level boxing of short text fragments inside math expressions.

## Common tasks

### How to insert a horizontal text box in math

Legacy TeX box; prefer \text in LaTeX documents.

```latex
x = 0 \hbox{ otherwise}
```

[Open in Playground](https://play.texform.dev/?input=x+%3D+0+%5Chbox%7B+otherwise%7D)

### How to freeze the size of a label

```latex
a_{\hbox{min}}
```

[Open in Playground](https://play.texform.dev/?input=a_%7B%5Chbox%7Bmin%7D%7D)

## Examples

```latex
\hbox{a}
```

[Open in Playground](https://play.texform.dev/?input=%5Chbox%7Ba%7D)

```latex
\hbox b
```

[Open in Playground](https://play.texform.dev/?input=%5Chbox+b)

```latex
\raisebox{1ex}{\hbox{$x^2$}}
```

[Open in Playground](https://play.texform.dev/?input=%5Craisebox%7B1ex%7D%7B%5Chbox%7B%24x%5E2%24%7D%7D)

## Renderer support

| Package | MathJax | KaTeX | XeTeX |
| --- | --- | --- | --- |
| base | full | full | partial |

## Usage frequency

0.41% of formulas in the measured corpus contain this entry, rank 70 of 263 entries with frequency data.

## In TeXForm

TeXForm parses this entry as prefix syntax; the package determines its argument specification.

### Discouraged in base

Plain-TeX low-level boxing command; LaTeX source usually prefers higher-level interfaces for text in math.

```latex
\hbox{$1} -> \mbox{$1}
```

Higher-level LaTeX interface; in MathJax base it is an exact alias with the same parse method and argument structure.

```latex
\hbox{$1} -> \text{$1}
```

Clearer high-level command for ordinary text in math, and the form most LaTeX users expect in amsmath-style source.

## Equivalent forms

```latex
\mbox{#1}
```

exact. In MathJax base, both map to BaseMethods.HBox with style 0.

## See also

- [\\mbox](https://texform.dev/latex/commands/mbox)
- [\\text](https://texform.dev/latex/commands/text)
- [\\textbf](https://texform.dev/latex/commands/textbf)
- [\\textit](https://texform.dev/latex/commands/textit)
- [\\textnormal](https://texform.dev/latex/commands/textnormal)
- [\\textrm](https://texform.dev/latex/commands/textrm)
- [\\textsf](https://texform.dev/latex/commands/textsf)
- [\\texttt](https://texform.dev/latex/commands/texttt)
- [\\textup](https://texform.dev/latex/commands/textup)

## Test cases

### base

| Input | Case | MathJax | KaTeX | XeTeX |
| --- | --- | --- | --- | --- |
| \hbox{a} | Positive: baseline | Pass | Pass | Pass |
| \hbox a | Positive: bare[0] | Pass | Pass | Fail |
| \hbox{a^2} | Negative: neg:T[0] | Pass | Fail | Fail |
