[Tex/LaTex] need italic dollar sign

italicmath-mode

I want to have not only italic numbers but also italic dollar sign in Latex math mode.

I found that some people get this with the \pounds symbol, however I do not achieve to do it and anyways this seems to be an undesired effect:
Special sign \pounds changed to dollar sign in alignment surrounding

So what is the proper way to get an italic dollar sign? If numbers can be italic, sure the dollar sign can be, right?

Added a minimal working example:

\documentclass[]{article}
\usepackage[T1]{fontenc}
\begin{document}
\begin{tabular}{lll}
\verb+\$+ & \$ & as expected\\
\verb+\textit{\$}+ & \textit{\$} & as expected\\
\verb+$\$$+ & $\$$ & as expected\\
\verb+$\mathit\$$+ & $\mathit\$$ & not expected\\
\verb+$\mathit{\mathchar"0024}$+ & $\mathit{\mathchar"0024}$ & not expected\\
\verb+$\mathit{\mathdollar}$+ & $\mathit{\mathdollar}$ & not expected\\
\end{tabular}
\end{document}

enter image description here

Best Answer

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.

enter image description here