# Changing font family in latex (math mode)

I am using the mathptmx package to type math equations. After going through many font packages, I like this the most, except the infinity symbol. The infinity symbol produced by this package is very small and narrow, I have tried as follows to fix but couldn't get the desired one.

\documentclass[12pt,fleqn]{book}
\usepackage{exscale,relsize,tikz,avant,microtype,titletoc,fancyhdr}
\usepackage{amsmath,mathrsfs,amsfonts,bm,amssymb,mathtools,amsthm,,mathptmx}

\newcommand{\inftyy}{\mathlarger{\infty}}
\newcommand{\inftyyy}{\Large{\text{$\infty$}}}

\begin{document}
$$x \in (-\inftyyy,+\infty), y\in (-\inftyy,+\infty)$$
\end{document}


In both cases (\inftyyy and \inftyy), the symbol gets lifted from the normal horizontal line alignment, making an awkward look. The other possibility that I could try is to define a new command such that amsfonts overwrites mathptmx's infinity symbol, but I am not sure how to achieve that. Anybody to the rescue? Also new idea would be highly appreciated.

P.S. Please do not suggest using other packages because I have already tried many.

Thank you in advance

• Surely you can delete amsmath and amsfonts. – Sebastiano May 19 '20 at 19:57
• To fix the vertical positioning in \inftyyy you could use \raisebox, as in e.g. \newcommand{\inftyyy}{\text{\raisebox{-1.8pt}{\Large$\infty$}}} – steve May 19 '20 at 20:04
• @Sebastiano , of course but I kept there in case if I can overwrite with these fonts. – stochastic learner May 19 '20 at 20:06

Since the font is scalable, you don't need relsize. The main problem is in coercing the symbol to be at the correct height, particularly in subscripts.

\documentclass{article}
\usepackage{amsmath}
\usepackage{mathptmx,graphicx}

\makeatletter
\let\original@infty\infty
\DeclareRobustCommand{\infty}{\mathord{\mathpalette\scale@infty\relax}}
\newcommand\scale@infty[2]{%
\vcenter{\m@th\hbox{\scalebox{1.3}{$\lower@infty{#1}$}}}%
}
\newcommand\lower@infty[1]{%
\sbox\z@{$\original@infty$}%
\dimen0=\dimexpr\ht\z@-2\fontdimen22\style@font{#1}2\relax
\dimen2=\dimexpr\ht\z@+\dimen0\relax
\raisebox{\dimen0}[\dimen2][0pt]{$#1\original@infty$}%
}
\def\style@font#1{%
\ifx#1\displaystyle\textfont\else\ifx#1\textstyle\textfont
\else\ifx#1\scriptstyle\scriptfont\else\scriptscriptfont\fi\fi\fi
}
\makeatother

\begin{document}

$$x \in (-\infty,+\infty)\quad \infty_{+\infty_{+\infty}}$$

\end{document}


On the other hand, you get a properly sized symbol out of the box with newtx.

\documentclass{article}
\usepackage{amsmath}
\usepackage{newtxtext,newtxmath}

\begin{document}

$x\in(-\infty,+\infty)\quad \infty_{+\infty_{+\infty}}}$

\end{document}


I hope to have understood your question using a old question of the very nice user @egreg: Make \infty symbol horizontal align with 8 EXACTLY. Here there my result with any improvements for your question. I have increased the size of the infinity symbol and you can take it either up or down with tha scale parameter -0.1 (to take the symbol lower) or +0.1 above.

\documentclass[12pt,fleqn]{book}
\usepackage[T1]{fontenc}

\usepackage{exscale,relsize,tikz,avant,microtype,titletoc,fancyhdr}
\usepackage{mathrsfs,bm,amssymb,mathtools,amsthm,,mathptmx}

\newcommand{\inftyy}{\mbox{\larger$\infty$}}
\newcommand{\inftyyy}{\mbox{\larger$\inftyy$}}
\makeatletter
\newcommand{\hinfty}{\raisebox{-0.1\height}{$\m@th\inftyy$}}
\newcommand{\hinftyy}{\raisebox{-0.22\height}{$\m@th\inftyyy$}}
\makeatother
\begin{document}
$$x \in (-\hinfty,+\hinfty), y\in (-\hinftyy,+\hinftyy)$$
\end{document}