Skip to main content
v2026.11,858 entries · CC-BY 4.0
LAC HealthMedical Supply Distributor100,000+ medical supplies. 48-hour critical dispatch.Ships from 8 regional U.S. hubs. Net-30 terms for verified institutional accounts.Shop lac.us CodeCASRAIlac.us

Underscore in LaTeX: How to Type _ and Other Special Characters

How to type an underscore in LaTeX with _, plus the escapes for all ten reserved characters and where _ still fails.

Written and maintained by CASRAI Editorial Board

Last updated

Short answer: in LaTeX, type \_ (backslash, underscore) to print an underscore in ordinary text. A bare _ is a reserved character, and in math mode it creates a subscript. This guide is for researchers and analysts who get an error or a vanished underscore in a manuscript, thesis, table caption or bibliography and need the correct fix for the place where it occurs.

Underscore in LaTeX: type \_, not _

The Not So Short Introduction to LaTeX 2e (lshort) lists # $ % ^ & _ { } ~ \ as reserved characters that “have a special meaning under LaTeX”, and says that typing them directly “will normally not print, but rather coerce LaTeX to do things you did not intend.” The fix it gives is a prefix backslash. For the underscore that is \_.

The file is named my\_data\_final.csv

This renders as “The file is named my_data_final.csv”. The same command covers the variants people search for: latex underscore, underscore in latex and underscores in latex are all the same task.

What it is used for in research

Underscores turn up constantly in research writing: variable and column names from analysis code, file and dataset names, identifiers and accession-style labels, and URLs or DOIs pasted into a reference list. In each case the character has to survive LaTeX’s processing as a visible underscore. The rest of this guide covers the plain-text fix, the math-mode behaviour, and the arguments (file names, citation keys, labels) where an escape is not enough.

How to input _ in LaTeX? Is _ an underscore?

Yes, the character _ is the underscore. LaTeX gives it a job of its own: in math mode the lshort chapter on mathematical notation describes ^ and _ as typesetting superscripts and subscripts (for example \( A_x = G_{a\times c} \)). That is why a bare underscore in running text fails, and why an underscore you want to see in a formula needs the same escape.

  • Literal underscore in text: \_
  • Subscript in a formula: \( x_i \), or \( x_{ij} \) when the subscript has more than one character (lshort’s examples group multi-character subscripts in braces, as in G_{a\times c}).
  • Literal underscore inside a formula: \_, the same escape as in text.

Install or access (official source only)

The \_ escape is part of LaTeX itself, so nothing extra needs installing: it works in any LaTeX installation or hosted LaTeX editor. Obtain LaTeX from a TeX distribution or a hosted editor you trust. The two documents this guide relies on are published on CTAN, the Comprehensive TeX Archive Network: lshort at tobi.oetiker.ch/lshort/lshort.pdf and the optional underscore package at ctan.org/pkg/underscore. Download packages from CTAN or through your distribution’s package manager, not from third-party mirrors.

Step-by-step: print an underscore

  1. Find the text containing the underscore, for example my_data_final.csv.
  2. Decide where it sits: ordinary text, a formula, or a file name, citation key or label.
  3. In ordinary text or a formula where you want the character itself, put a backslash in front of each underscore: my\_data\_final.csv.
  4. If you want a subscript inside a formula, leave the underscore bare and group multi-character subscripts in braces: \( x_{ij} \).
  5. If the underscore is in a file name, citation key or label, rename it with a hyphen or camelCase, or use the underscore package routes below.
  6. Recompile and check the output.

Output and how to read it

With my\_data\_final.csv the PDF shows the visible underscores: my_data_final.csv. If the underscore disappears, or a “missing $ inserted” style error appears, a bare _ remains somewhere in text mode. If a formula shows a lowered character instead of an underscore, the underscore was read as a subscript; escape it as \_ if you wanted the character. If an underscore looks like a drawn rule rather than a font character, the package notes below explain that the font encoding has no underscore glyph.

Reserved characters and their escapes

The underscore is one of ten reserved characters. The table is taken from section 1.3.3 of lshort (CTAN nightly build, read 2026-11-07) and covers the related searches for percent sign, dollar sign, ampersand, backslash and tilde in one place.

Character Name What to type
# hash \#
$ dollar sign \$
% percent sign \%
^ caret \^{}
& ampersand \&
_ underscore \_
{ left brace \{
} right brace \}
~ tilde \~{}
\ backslash \textbackslash{}

LaTeX backslash

The backslash cannot be typed by doubling it. lshort states that the backslash “can not be entered by adding another backslash in front of it (\\); this sequence is used for line breaking. Use the \textbackslash command instead.”

LaTeX percent sign, dollar sign and ampersand

Use \%, \$ and \&. For the percent sign in particular, see the CASRAI guide on writing the percent sign in LaTeX.

LaTeX tilde symbol

lshort gives \~{}. The community-maintained Wikibooks page on LaTeX special characters (read 2026-11-07) gives the alternative \textasciitilde{} and notes that a bare tilde is a non-breaking space.

Special characters inside formulas

What does \( do in LaTeX?

\( opens an inline formula and \) closes it. lshort: “To typeset an inline formula, put it between \( and \) commands, while \[ and \] typesets it in display mode.” Inside that math mode, _ and ^ work as subscript and superscript, which is the behaviour that clashes with a literal underscore.

How to get a negation symbol in LaTeX?

In math mode use \lnot, the logical-negation command shown in lshort’s quantifier example, \( \lnot\forall_{q} P(q) \iff \exists_{q}\lnot P(q) \). Note that this example uses _ for subscripts, so it also shows the underscore doing its math-mode job.

Where \_ still breaks: file names, citation keys and URLs

The documentation for the CTAN underscore package (Donald Arseneau, version 1.0, 13 September 2006, read 2026-11-07) lists the places an underscore cannot simply be typed or escaped. It says to avoid _ in file names and in \cite or \ref tags, and names the arguments that are “moving” in this sense: \cite/\ref tags, \input, \include, \includegraphics, environment names and counter names.

  • Safest approach: use hyphens or camelCase in file names, citation keys and label names so that no escape is needed. See the CASRAI guide to the BibTeX file format for how keys are used.
  • When you cannot rename a file: the package documentation gives \include{file\string_name} as an occasional-use workaround.
  • With the package loaded: it offers a [strings] option for underscores in these arguments.

Using the underscore package

Load it with \usepackage{underscore}. According to its documentation, a simple _ then “acts just like \_ in text mode, but makes a subscript in maths mode”, so pasted text such as variable names no longer needs escaping outside formulas. It also changes how _ hyphenates: hyphenation of the constituent words is unaffected and a break is allowed after the underscore, and the [nohyphen] option breaks without a hyphen. Both forms print an underscore character if the font encoding has one (for example with \usepackage[T1]{fontenc} or typewriter fonts) and otherwise draw a rule.

Free alternatives and other routes

LaTeX and the CTAN package are free to use. The table compares the routes described in the sources above.

Route Where it works Source
\_ escape Ordinary text and formulas, one underscore at a time lshort, section 1.3.3
\usepackage{underscore} Text mode, so bare _ prints an underscore; subscripts still work in math mode CTAN underscore package documentation
[strings] package option Underscores in file names, \cite/\ref tags and similar arguments CTAN underscore package documentation
\include{file\string_name} One-off underscore in an include argument CTAN underscore package documentation
Rename to hyphens or camelCase File names, citation keys, labels (editorial recommendation: no escape needed) CASRAI editorial advice

Troubleshooting

  • Error or missing text where a name contains underscores: escape each one as \_, or load the underscore package for text-mode use.
  • Underscore in a citation key, label or file name: rename, or use the \string_ and [strings] routes above.
  • Underscore shows as a subscript in a formula: escape it with \_ if you want the character itself.
  • Underscore looks like a rule rather than a character: check the font encoding, as in the package notes above.

Working in an editor or online service? The CASRAI guides to Overleaf and TeXstudio cover the tools themselves; the escapes above are the same in any LaTeX engine. For other symbol tasks, see Greek symbols in LaTeX and vertical lines in LaTeX.

FAQ

How do I type an underscore in LaTeX?

Type \_ in text or in math mode. A bare _ is reserved (lshort, section 1.3.3).

Why does a bare underscore cause an error?

Because _ is a reserved character; lshort says reserved characters typed directly will normally not print and can make LaTeX do things you did not intend, and in math mode _ means “subscript”.

Can I stop escaping underscores in text altogether?

Load the underscore package, with the file-name and citation-key limits described above.

How do I print a backslash?

Use \textbackslash{}, not \\.

Sources

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · free to try

Ask about Underscore in LaTeX: How to Type _ and Other Special Characters

Ask your first 2 questions free below. Subscribers get 150 a day for $29 a month.

An AI assistant specialized in research administration. It cites the sources behind every answer, labels web answers and says when it can't answer.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays free to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →