\char9 (supposedly a horizontal tab) displays as a Ψ (Greek psi)

This is about font encoding: the standard OT1 font encoding developed by Knuth uses all of the slots in the font, not just those you might normally think of as printable. Most famously, \char0 is used in this encoding and used to cause issues for some PDF viewers.

The idea that there is one 'universal' encoding has arisen with the adoption of Unicode, but this simply doesn't apply to older material. There are lots of encodings for fonts, both 'standard' and entirely non-standard (think pifonts).

What you have have to bear in mind is that the input codepoint doesn't have to match the output codepoint: the key is that it shows the correct information. That's perhaps most easily understood with something like \alpha: clearly the output (a single glyph) is different from the input, and in a 'classical' encoding such as Latin-1 there is no alpha.

Probably the easiest way to see the full font table for an (8-bit) font is to use the LaTeX package fonttable:

\documentclass{article}
\usepackage{fonttable}
\begin{document}

\fonttable{cmr10}

\end{document}

There's nothing strange: \char<8 bit number> prints the character in slot <8 bit number> in the current font. It does not generate a character token, as you seem to believe.

If you want a tab character token, with its current category code, type ^^I or ^^09, where ^ must have category code 7.

With XeTeX and LuaTeX you have available \Uchar that expandably generates a character token, so \Uchar 9 will do what you need. XeTeX also provides \Ucharcat that generates a character token with a given number and a given category code: for instance

\Ucharcat 9 10

is the same as \Uchar 9 with the standard category code. Not all category codes are available, notably 13 (active) isn't. The primitive \Ucharcat is not defined in LuaTeX, but it can be emulated (see the ucharcat.sty LaTeX package).


The other (excellent) answers address what \char does and how to input a literal horizontal tab character using ^^ but they don't mention why TeX treats a tab as a space. Admittedly, this is only tangentially related to your question, but it may help explain TeX's behavior.

By default, tab has a category code of 10 (space). One interesting aspect of category code 10 characters is that when TeX encounters them in the input while it is not ignoring spaces, it produces a space token which has category code 10 and character code 32 (ASCII space). In essence, TeX doesn't really know anything about tab characters. As far as it's concerned, since character 9 has category code 10, it's just a space.

Tags:

Characters