General\string command behavior - Plain TeX

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
User avatar
renyalvarado
Posts: 3
Joined: Mon Jun 04, 2012 6:16 pm

\string command behavior - Plain TeX

Post by renyalvarado »

Hi, I would like to learn Plain TeX and I'm reading Knuth's "The TeXBook".At Chapter 7, Knuth talks about the \string command and how it converts control sequences into lists of characters tokens. Why when I typed \string\TeX I got "TeX, but when I wrote {\tt \string\TeX} I got \TeX?

I guess it's something related to \escapechar, because when I changed this control sequence the output changed too:

Code: Select all

\escapechar=`^
\string\TeX
generates
^TeX

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

User avatar
Stefan Kottwitz
Site Admin
Posts: 10359
Joined: Mon Mar 10, 2008 9:44 pm

\string command behavior - Plain TeX

Post by Stefan Kottwitz »

Run this code (or click Open in writeLaTeX), and you can see that the backslash \ from the typewriter font is replaced by " in the font table of the roman font - at place '134 (92):

Code: Select all

\documentclass{article}
\usepackage{fonttable}
\begin{document}
\fonttable{cmr8}
\fonttable{cmtt8}
\end{document}
cmr.png
cmr.png (21.84 KiB) Viewed 6673 times
cmtt.png
cmtt.png (16.63 KiB) Viewed 6673 times
You may notice further differences regarding special symbols. In typewriter font, most used special symbols are different to those required in standard text.

Stefan
LaTeX.org admin
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

\string command behavior - Plain TeX

Post by cgnieder »

See also the same question on TeX.sx with currently two answers.

Regards
site moderator & package author
Post Reply