My tags are as follow:

\documentclass{book}
\usepackage[T1]{fontenc}
\usepackage{txfonts}
\begin{document}

Test \quad $a,b$\quad \textit{a, b}\quad a, b


\end{document}

In this, I need to get the comma character to be in italic font within both inline and display equations. Any suggestions?

  • 6
    Why should it? I see no reason. – egreg Jul 11 at 11:39
  • 9
    You deserve my sympathy. ;-) – egreg Jul 11 at 11:51
  • 5
    @MadyYuvi you are allowed to say no, and point to more or less any published math work, which does not do that. – David Carlisle Jul 11 at 11:56
  • 2
    Honestly, would any reasonable person even notice, let alone care about, the difference? – David Richerby Jul 11 at 12:56
  • 1
    @ChrisH You may very well think this professor is completely unreasonable. I couldn’t possibly comment. – David Richerby Jul 11 at 15:33
up vote 9 down vote accepted

You can redeclare the comma in math mode.

With newtx (to be preferred over txfonts)

\documentclass{article}
\usepackage{newtxtext,newtxmath} % no txfonts, please

\makeatletter
\DeclareSymbolFont{italic}{\tx@enc}{\rmdefaultB}{m}{it}
\SetSymbolFont{italic}{bold}{\tx@enc}{\rmdefaultB}{\bold@wt}{it}
\DeclareSymbolFontAlphabet{\mathit}{italic}
\DeclareMathSymbol{,}{\mathpunct}{italic}{`,}
\makeatother

\begin{document}

Test \quad $a,b$\quad \textit{a, b}\quad a, b

\end{document}

enter image description here

With txfonts

\documentclass{article}
\usepackage{txfonts}

\DeclareSymbolFont{italic}{OT1}{txr}{m}{it}
\SetSymbolFont{italic}{bold}{OT1}{txr}{bx}{it}
\DeclareSymbolFontAlphabet{\mathit}{italic}
\DeclareMathSymbol{,}{\mathpunct}{italic}{`,}

\begin{document}

Test \quad $a,b$\quad \textit{a, b}\quad a, b

\end{document}

enter image description here

Some explanations

The newtxmath package defines a math alphabet

\DeclareMathAlphabet{\mathit}{\tx@enc}{\rmdefaultB}{m}{it}
\SetMathAlphabet{\mathit}{bold}{\tx@enc}{\rmdefaultB}{\bold@wt}{it}

but we want to borrow the comma from this font as a math symbol. So instead we declare a symbol font with the same parameters (encoding, family, weight and shape) and redeclare \mathit with \DeclareSymbolFontAlphabet. Then the declaration of the comma is straightforward.

Simply adding \textit{} around a comma will make the comma character italic in math mode. So:

$a\textit{,}b$
  • thanks for your advise, it is any way to achieve this without doing the manual thing? – MadyYuvi Jul 11 at 11:38
  • Not that I know of. You could make a custom command for this but then you would still have to replace your commas by that custom command. At that point you would probably just save time by typing the comma and pressing Ctrl+I in your editor. – Flexo013 Jul 11 at 11:41
  • 1
    @Flexo013 You don't know what editor I'm using, so you don't know what ctrl+I will do... – David Richerby Jul 11 at 12:55
  • @DavidRicherby that is correct. You can simply find the equivalent shortcut for your editor of choice. I was merely providing a commonly used shortcut for italicizing text. – Flexo013 Jul 11 at 13:19

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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