The following example produces
${\rm\char"5}$
\end
Why does it not produce the following instead?
The TeXbook p. 289 explains how \char〈8-bit number〉 can form a 〈character〉, and that a 〈character〉 is a particular case of a 〈math symbol〉. What a 〈math symbol〉 found in math mode does is explained on page 291, but let's get back to page 289 about 〈character〉:
When TeX is in math mode or display math mode, a 〈character〉 command takes on added significance: It specifies a number between 0 and 32767 = 215 − 1. This is done by replacing the character number by its
\mathcodevalue. If the\mathcodevalue turns out to be32768="8000however, the 〈character〉 is replaced by an active character token having the original character code (0 to 255); TeX forgets the original 〈character〉 and expands this active character according to the rules of Chapter 20.
So, what matters when finding \char〈8-bit number〉 in math mode is the \mathcode of the specified character. In your case, the character is number 5, i.e. `\^^E. Line 59 of plain.tex reads:
\mathcode`\^^E="023A % \lnot
Therefore \char"5 in math mode is a 〈math symbol〉 with \mathcode "023A. It specifies class 0 (ordinary, cf. TeXbook p. 154), family 2 and position "3A in the corresponding font.
The font in question is thus \textfont2, because your \rm does nothing here, AFAICT:
\rm:
macro:->\fam \z@ \tenrm
\fam has an effect on symbols of class 7 (variable), but here the symbol has class 0; besides, \tenrm affects the text font and has no effect in math mode, AFAIK (except of course if you temporarily leave math mode using, for instance, an \hbox command inside the dollar signs).
You may query what this font is with:
\tracingonline=1
\showthe\textfont2
which outputs:
> \tensy .
l.3 \showthe\textfont2
and confirms what can be seen with \tracingoutput=1:
Completed box being shipped out [1]
\vbox(667.20255+0.0)x469.75499
(...)
.\vbox(643.20255+0.0)x469.75499, glue set 633.20255fill
..\glue(\topskip) 5.69446
..\hbox(4.30554+0.0)x469.75499, glue set 443.0883fil
...\hbox(0.0+0.0)x20.0
...\mathon
...\tensy :
...\mathoff
(...)
: indeed has ASCII code "3A. So, the character you get in the output is found in position "3A of font \tensy. The TeXbook p. 350 (plain.tex) declares:
\font\tensy=cmsy10
You can verify with texdoc encguide (page 33 here) that character "3A of font cmsy10 is indeed the \lnot we see on your screenshot.
Note: this is not directly related to the question, but since its crux is the \mathcode and the paragraph I quoted from the TeXbook explains what happens with the special case of a \mathcode equal to "8000, I'll seize the opportunity and point our dear readers to this answer of egreg where the "8000 special case is put to good use (cf. function \__hs_cls_activate_comma: in his answer).
\charis also described on top of p.155 in TeXbook. – Igor Liferenko Aug 02 '19 at 02:32<character>has not been defined - then mathcode is taken to be equal to charcode – Igor Liferenko Aug 02 '19 at 03:02$\mathcode"5=0 \char"5$so thatПwould be printed, instead ofГ. – Igor Liferenko Aug 02 '19 at 03:29\mathcode, and the top of page 155 says that INITEX starts in a state where the\mathcodefor every possible character code (256 values in Knuth's TeX) is defined. And beware, one doesn't have\mathcodex = x for digits and letters in this case: it's x +"7000for the 10 digits and x +"7100for the 52 letters. This makes in-math digits in roman type by default, and in-math letters in italic type by default (and can be overriden with\fam). To get yourП, simply point to position 5 of\textfont0which is by defaultcmr10. – frougon Aug 02 '19 at 06:37\mathcode"5="0005 $\char"5$ \end. You could set up many\mathcodeentries like that in a file you\inputor in a custom format. Note that this treats the character as a mathematical entity (a 〈math symbol〉). If it's really text inside a formula,$\hbox{\char"5}$seems more appropriate and needs no particular font or\mathcodesetup (of course,\char"5also works in horizontal mode without needing dollar signs nor\hbox: it causes a character box to be appended to the horizontal list). – frougon Aug 02 '19 at 07:22