Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

up vote 14 down vote accepted

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.