Hash Symbol in LaTeX: \#

Use \# to print a literal hash (number sign / pound sign) in LaTeX.

Quick Answer

latex
The hashtag symbol is written as \# in LaTeX.

Why You Must Escape #

In LaTeX, the # character has a special meaning — it refers to parameters in macro definitions. If you type a bare # in your document, LaTeX will throw an error:

latex
% This causes an error:
The social media # symbol.

% This is correct:
The social media \# symbol.
Error message you'll see: ! You can't use `macro parameter character #' in horizontal mode.

Writing your thesis in LaTeX?

MonsterWriter's LaTeX Workspace gives you real-time PDF preview with no compile limits — at a fraction of Overleaf's price. Works just like Overleaf, costs 11× less.

Try MonsterWriter free

Full Example

latex
\documentclass{article}
\begin{document}

The number sign \# is also called a hashtag.

Set cardinality: $\#A = 5$ means set A has 5 elements.

The issue tracker reference is \#42.

\end{document}

Hash in Math Mode

Inside math mode, you can also write \#. This is commonly used in combinatorics and set theory to denote cardinality (the number of elements in a set).

latex
$\#A$ denotes the cardinality of set $A$.

\begin{equation}
  \#\{x \in \mathbb{N} : x < 10\} = 9
\end{equation}

Other Special Characters

LaTeX reserves several characters that need escaping:

CharacterCommandNotes
#\#Hash / number sign
$\$Dollar sign
%\%Percent sign
&\&Ampersand
_\_Underscore
{\{Opening brace
}\}Closing brace
~\textasciitilde{}Tilde (text mode)
^\textasciicircum{}Caret
\\textbackslash{}Backslash

Related Topics