Making math behaving like \mathit
It depends on several factors. If your math formulas are all built like that, then you might be justified in changing the mathcodes for the letters, although I recommend you not to do it.
Prefer a semantic markup: multiletter identifiers denote either variables or functions; define two commands, say \var
and \func
and type your formula as
\[
\var{offer}=\var{surface}\cdot\func{force}(\var{now})
\]
(don't use \times
, please!). Now you have the freedom of choosing whatever representation for variables and functions you need, for instance
\newcommand{\var}[1]{\mathit{#1}}
\newcommand{\func}[1]{\mathit{#1}}
When your supervisor or a journal copy editor will tell you “Nice, but functions should be typeset in upright letters”, you'll answer “Wait a minute“, change the second line into
\newcommand{\func}[1]{\mathrm{#1}}
and recompile. Would it be the same with the change to the math codes?
Is it harder to type? I don't think so, particularly if you are an Emacs expert who's able to define a couple of shorthands.
Changing the math code of all letters is quite easy, as the code is repetitive. Don't forget to redeclare \mathit
with \DeclareSymbolFontAlphabet
in order not to waste a math family.
\DeclareSymbolFont{italics}{\encodingdefault}{\rmdefault}{m}{it}
\DeclareSymbolFontAlphabet{\mathit}{italics}
\makeatletter
\count@=`a \advance\count@\m@ne
\@whilenum{\count@<`z}\do{%
\advance\count@\@ne
\begingroup\lccode`A=\count@
\lowercase{\endgroup
\DeclareMathSymbol{A}{\mathalpha}{italics}{`A}%
}%
}
\count@=`A \advance\count@\m@ne
\@whilenum{\count@<`Z}\do{%
\advance\count@\@ne
\begingroup\lccode`A=\count@
\lowercase{\endgroup
\DeclareMathSymbol{A}{\mathalpha}{italics}{`A}%
}%
}
\makeatother
The loops can be simplified with expl3
:
\usepackage{expl3}
\DeclareSymbolFont{italics}{\encodingdefault}{\rmdefault}{m}{it}
\DeclareSymbolFontAlphabet{\mathit}{italics}
\ExplSyntaxOn
\int_step_inline:nnnn { `A } { 1 } { `Z }
{
\group_begin:
\char_set_lccode:nn { `A } { #1 }
\char_set_lccode:nn { `B } { #1 + 32 }
\tl_to_lowercase:n
{
\group_end:
\DeclareMathSymbol{A}{\mathalpha}{italics}{`A}
\DeclareMathSymbol{B}{\mathalpha}{italics}{`B}
}
}
\ExplSyntaxOff
The main problem, which requires using the \lowercase
trick, is that it's the only way to generate a character token knowing its character code.
With a recent version of expl3
(released after 2015-09-09), one can avoid the \lowercase
trick using \char_generate:nn
.
\documentclass{article}
\usepackage{expl3}
\DeclareSymbolFont{italics}{\encodingdefault}{\rmdefault}{m}{it}
\DeclareSymbolFontAlphabet{\mathit}{italics}
\ExplSyntaxOn
\int_step_inline:nnnn { `A } { 1 } { `Z }
{
\exp_args:Nf \DeclareMathSymbol{\char_generate:nn{#1}{11}}{\mathalpha}{italics}{#1}
}
\int_step_inline:nnnn { `a } { 1 } { `z }
{
\exp_args:Nf \DeclareMathSymbol{\char_generate:nn{#1}{11}}{\mathalpha}{italics}{#1}
}
\ExplSyntaxOff
\begin{document}
\[
offer=surface\cdot force(now)
\]
\end{document}
The reason why the global reassigning the letters in math mode is not good idea was mentioned in another answer and comments. But if you really need this, then you can do:
\everymath{\it}\everydisplay{\it}
at beginning of the document. If you need to keep the numbers in roman style, then you can set:
\def\mathcodes#1{\mathcode`#1=\numexpr\mathcode`#1-"7000\relax
\ifx#10\else\expandafter\mathcodes\fi}
\mathcodes1234567890
This means, for example:
\documentclass[12pt]{article}
\everymath{\it}\everydisplay{\it}
\def\mathcodes#1{\mathcode`#1=\numexpr\mathcode`#1-"7000\relax
\ifx#10\else\expandafter\mathcodes\fi}
\mathcodes1234567890
\begin{document}
$offer = surface \times force(now) + 1$
\end{document}
If you are using plain TeX then you can use \itvariables
command which is provided after \input ams-math
or \input opmac
. This command sets mathcodes of all letters to the text italic math family (as default). For example:
\input ams-math \itvariables
$offer = surface \times force(now) + 2$
\bye
I would agree with egreg that it is far better to make the markup match the meaning here and mark up each identifier separately. The math markup in TeX, as well as the default fonts, are designed on the idea that adjacent letters are separate variables, typically with implied multiplication or concatenation operators.
However if you are not convinced and want to default to the text italic font there is no need to allocate a new math font for this, it is already set up for use with \mathit
you just need to make it escape the implied grouping that \mathit
implies.
\documentclass{article}
\let\v\mathit
\begin{document}
$\mathit{offer = surface \times force(now)}$
$\v{offer} = \v{surface} \times \v{force}(\v{now})$%%%USE THIS
\everymath{\mathit{\xdef\tmp{\fam\the\fam\relax}}\tmp}
$offer = surface \times force(now)$
\end{document}