# How does \_ work if OT1 is default encoding for LaTeX?

Fair warning: I know approximately zero things about fonts and font encodings, so this is perhaps another naive question on my part.

Recently, I asked about the behavior of \detokenize{_}, as one needs to specify \usepackage[T1]{fontenc} for it to work as expected.

Apparently, the default font encoding for LaTeX is OT1, and there is no _ in OT1. Thus, for something like \detokenize{_} or \string_ to render as _ and not ˙, one must specify T1 font encoding.

Yet, as @egreg points out in a comment on that question and as we all are likely aware, \_ renders as _ in LaTeX without having to do anything to the font encoding.

So, my question is how can LaTeX actually render \_ as _ if there is no _ in OT1, which is the default encoding?

-

plain.tex includes

\def\_{\leavevmode \kern.06em \vbox{\hrule width.3em}}

latex.ltx includes

\DeclareTextCommandDefault{\textunderscore}{%
\leavevmode \kern.06em\vbox{\hrule\@width.3em}}

and

\DeclareRobustCommand{\_}{%
\ifmmode\nfss@text{\textunderscore}\else\textunderscore\fi}

but t1enc.def includes

\DeclareTextSymbol{\textunderscore}{T1}{95}

so that the actual underscore from the font is used if T1 is loaded. In that case, the \DeclareTextSymbol from t1enc.def overrides the default meaning of \textunderscore from latex.ltx and, hence, of \_. If T1 is not loaded, of course, and OT1 is used, the default definition is not overridden and TeX essentially fakes the underscore when \textunderscore or \_ is typeset.

-