\_ underscore (_) in LaTeX
| Command | \_ |
|---|---|
| Mode | text and math |
| Package | none, part of LaTeX |
| Unicode | _ U+005F |
| Kind | Text symbols and special characters |
\_ typesets the symbol “underscore” (_). It is a text symbol.
Example
\documentclass{article}
\begin{document}
my\_file.tex
\end{document}Compiled with pdfLaTeX from TeX Live 2023.
How to use it
\_ works in normal text and in math mode. The command is part of LaTeX; you need no package.
An unescaped _ in text raises Missing $ inserted, because it marks a subscript in math mode.
About text symbols and special characters
Ten characters have a job in LaTeX source and do not print when typed alone: # $ % & _ { } ~ ^ \. Seven of them print with a backslash in front; tilde, caret and backslash need a longer command. Most other characters, such as €, § or ß, can be typed directly in a UTF-8 file.