How to use a roman font for capital letters in math mode when using plain TeX

frenchplain-tex

The French style (see the frenchstyle option of the LaTeX kpfonts package) is to typeset capital letters in math mode in roman rather than in italic.

How can I achieve that in plain TeX without having to manually input \rm everywhere? That is, I would the second one to look like the first in:

  • Let $\rm V$ be a vector space.
  • Let $V$ be a vector space.

Best Answer

You need to change the mathcode of the capital letters. In plain.tex you find

% INITEX sets up \mathcode x=x, for x=0..255, except that
% \mathcode x=x+"7100, for x = `A to `Z and `a to `z;
% \mathcode x=x+"7000, for x = `0 to `9.

but you want "7000, the second digit denotes the default math family to take the character from, and 0 is for the upright text font.

How to do this with as less work as possible?

\count255=`A
\count8="7000
\advance\count255 by -1
\loop\ifnum\count255<`Z
  \advance\count255 by 1
  \advance\count8 by 1
  \mathcode\count255=\count8
\repeat
% cover your tracks
\count8=0

$A+B+\Gamma+Z+a+b+z$

${\mit A}+A$

\bye

enter image description here

If you use pdftex, this can be shortened to

\count255=`A
\advance\count255 by -1
\loop\ifnum\count255<`Z
  \advance\count255 by 1
  \mathcode\count255=\numexpr\count255+"7000\relax
\repeat

Even shorter with expl3 (also requires pdftex):

\input expl3-generic
\ExplSyntaxOn
\int_step_inline:nnn { `A } { `Z }
  {
   \mathcode #1 = \int_eval:n { #1 + "7000 }
  }
\ExplSyntaxOff