As long as you only use letters and numbers in \mathit
(no Greek uppercase, in particular), just change \mathdollar
to respect the math group, adding "7000
to the math code.
\documentclass{article}
\usepackage[T1]{fontenc}
\begingroup\edef\x{\endgroup
\mathchardef\mathdollar=\the\numexpr"7000+\the\mathdollar\relax
}\x
\DeclareMathAlphabet{\mathit}{T1}{cmr}{m}{it}
\begin{document}
\begin{tabular}{lll}
\verb+\$+ & \$ & as expected\\
\verb+\textit{\$}+ & \textit{\$} & as expected\\
\verb+$\$$+ & $\$$ & as expected\\
\verb+$\mathit{\$}$+ & $\mathit\$$ & as expected\\
\end{tabular}
\end{document}
This requires changing the font associated to \mathit
into one that's T1 encoded.
A different strategy is to redefine \mathdollar
to use \text
for the \mathit
case.
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\AtBeginDocument{\sbox0{$\mathit{\xdef\mathitgroup{\the\fam}}$}}
\mathchardef\latexmathdollar=\mathdollar
\protected\def\mathdollar{%
\ifnum\mathgroup=\mathitgroup
\text{\normalfont\itshape\textdollar}%
\else
\latexmathdollar
\fi
}
\begin{document}
\begin{tabular}{lll}
\verb+\$+ & \$ & as expected\\
\verb+\textit{\$}+ & \textit{\$} & as expected\\
\verb+$\$$+ & $\$$ & as expected\\
\verb+$\mathit{\$}$+ & $\mathit\$$ & as expected\\
\end{tabular}
\end{document}
The output is the same for both codes.
I don't know if an approach like this would cover all bases?
I tell LaTeX to make math letters
using the {cmr}{m}{n}
font style. However, this screws up Greek letters, so I have to define a special greeksymbols
class that uses {cmm}{m}{it}
and then, for each Greek symbol, point it to the greeksymbols
font style.
EDITED to take campa's suggestion to add additional symbols to the mix, such as harpoons, \imath
(upright style), \wp
, and \vec
(accent).
The key in adding such symbols is to look at the cm font tables in the TeXbook, (Appendix F), to determine the slot number and font family of the desired glyph. You also need to know the functional category of glyph, such as \mathrel
, \mathbin
, \mathchar
, \mathord
, etc. and add all that information into the \DeclareMathSymbol
declaration.
EDITED to make the greek letters \mathord
category, per egreg's recommendation.
\documentclass{article}
\DeclareSymbolFont{letters}{OT1}{cmr}{m}{n}
\DeclareSymbolFont{greeksymbols}{OML}{cmm}{m}{it}
%GREEKS
\DeclareMathSymbol{\alpha}{\mathord}{greeksymbols}{"0B}
\DeclareMathSymbol{\beta}{\mathord}{greeksymbols}{"0C}
\DeclareMathSymbol{\gamma}{\mathord}{greeksymbols}{"0D}
\DeclareMathSymbol{\delta}{\mathord}{greeksymbols}{"0E}
\DeclareMathSymbol{\epsilon}{\mathord}{greeksymbols}{"0F}
\DeclareMathSymbol{\zeta}{\mathord}{greeksymbols}{"10}
\DeclareMathSymbol{\eta}{\mathord}{greeksymbols}{"11}
\DeclareMathSymbol{\theta}{\mathord}{greeksymbols}{"12}
\DeclareMathSymbol{\iota}{\mathord}{greeksymbols}{"13}
\DeclareMathSymbol{\kappa}{\mathord}{greeksymbols}{"14}
\DeclareMathSymbol{\lambda}{\mathord}{greeksymbols}{"15}
\DeclareMathSymbol{\mu}{\mathord}{greeksymbols}{"16}
\DeclareMathSymbol{\nu}{\mathord}{greeksymbols}{"17}
\DeclareMathSymbol{\xi}{\mathord}{greeksymbols}{"18}
\DeclareMathSymbol{\pi}{\mathord}{greeksymbols}{"19}
\DeclareMathSymbol{\rho}{\mathord}{greeksymbols}{"1A}
\DeclareMathSymbol{\sigma}{\mathord}{greeksymbols}{"1B}
\DeclareMathSymbol{\tau}{\mathord}{greeksymbols}{"1C}
\DeclareMathSymbol{\upsilon}{\mathord}{greeksymbols}{"1D}
\DeclareMathSymbol{\phi}{\mathord}{greeksymbols}{"1E}
\DeclareMathSymbol{\chi}{\mathord}{greeksymbols}{"1F}
\DeclareMathSymbol{\psi}{\mathord}{greeksymbols}{"20}
\DeclareMathSymbol{\omega}{\mathord}{greeksymbols}{"21}
\DeclareMathSymbol{\varepsilon}{\mathord}{greeksymbols}{"22}
\DeclareMathSymbol{\vartheta}{\mathord}{greeksymbols}{"23}
\DeclareMathSymbol{\varpi}{\mathord}{greeksymbols}{"24}
\DeclareMathSymbol{\rho}{\mathord}{greeksymbols}{"25}
\DeclareMathSymbol{\varsigma}{\mathord}{greeksymbols}{"26}
\DeclareMathSymbol{\varphi}{\mathord}{greeksymbols}{"27}
%SYMBOLS
\DeclareMathSymbol{\leftharpoonup}{\mathrel}{greeksymbols}{"28}
\DeclareMathSymbol{\leftharpoondown}{\mathrel}{greeksymbols}{"29}
\DeclareMathSymbol{\rightharpoonup}{\mathrel}{greeksymbols}{"2A}
\DeclareMathSymbol{\rightharpoondown}{\mathrel}{greeksymbols}{"2B}
\DeclareMathSymbol{\wp}{\mathord}{greeksymbols}{"7D}
%OTHERS
\DeclareMathSymbol{\imath}{\mathalpha}{letters}{"10}
\DeclareMathAccent{\vec}{\mathaccent}{greeksymbols}{"7E}
\begin{document}
\[
z = \alpha x + \beta y^2
\]
\[
x \leftharpoonup y \leftharpoondown z \rightharpoonup \imath \rightharpoondown i
\]
\[
A = \wp(\vec B)
\]
\end{document}
Best Answer
You can try with
in your preamble and use
\mathbbmsl{A}
to get an A as "blackboard bold slanted". There's no Type1 version of the font, though, so a bitmap will be generated.