6

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

  • 5
    \textit{\$} works. – Bernard Apr 27 '16 at 21:33
  • What you can't straightforwardly get is a maths mode italic dollar symbol. But is that really a problem? – cfr Apr 27 '16 at 21:40
  • 1
    ${\emph \$}$ and ` $\emph \$$` both work. – A Feldman Apr 27 '16 at 23:07
  • 1
    @AFeldman Yes, but presumably because it switches to text so it is essentially \textit{} ? – cfr Apr 28 '16 at 0:11
  • Yes, I think you are right. – A Feldman Apr 28 '16 at 0:35
2

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

0

Hm, we have to get a little sketchy when we want to have an italic dollar sign in math mode. My plan is to:

  1. use \mathrm in mathmode ($$ that is)
  2. call \textit inside \mathrm
  3. typle \$ inside \textit

Let's see if this works:

\documentclass[a4paper]{report}

\usepackage{amsmath}
\usepackage[utf8]{inputenc}

\begin{document}

Here we have an equation: $x + \mathrm{\textit{\$}} = \pounds$.

\end{document}

enter image description here Turns out it does! No fancy coding or setting new commands, but it is somewhat long to type each time, especially if you will use it a lot in your document. So here, I do it the smart way; I set a new command altogether:

\documentclass[a4paper]{report}

\usepackage{amsmath}
\usepackage[utf8]{inputenc}

\newcommand{\dollarit}{\mathrm{\textit{\$}}}

\begin{document}

Here we have an equation: $x + \dollarit = \pounds$.

\end{document}

Now typing your document will be much easier as instead of typing the horror that is \mathrm{\textit{\$}} every time, you just write \dollarit and you're set!

Just a quick note: you don't necessarily have to write \dollarit, you can specify your own command so it will fit you the best (just replace \dollarit in the first curly brackets after newcommand with anything you want).

I wish you a good day. Cheers.

EDIT: You can also just put \textit{\$} in math mode and it will work. However, because of some deficiencies that come with mixing raw text mode with math environment I chose to suggest you the longer, but safer way to achieve result - when not using roman letters always surround \text environment with \mathrm; it saves lives. Here is an example of a problem that arises in the opposite case.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.