In this revised solution, there is a 2pt gap above the bar and a 4 pt gap below it, as specified in the optional arguments to \stackon
and \stackunder
respectively. Obviously, those numbers can be tweaked (even to the point of being made negative) to deal with the specific characteristics of your font. If you want the division bar raised relative to the horizontal math axis, then the .5ex
argument of \raisebox
can be changed.
EDITED to load \ifthen
package explicitly, since it is no longer done automatically by stackengine
.
\documentclass{article}
\usepackage{stackengine}
\usepackage{ifthen}
\newlength\testwida
\newlength\testwidb
\newlength\mywidth
\newcommand\newfrac[2]{%
\setlength\testwida{\widthof{$#1$}}%
\setlength\testwidb{\widthof{$#2$}}%
\ifthenelse{\lengthtest{\testwida>\testwidb}}%
{\mywidth=\testwida}%
{\mywidth=\testwidb}%
\raisebox{.5ex}{%
\stackunder[4pt]{\stackon[2pt]{\rule{\mywidth}{.4pt}}{$#1$}}{$#2$}}%
}
\parskip 1ex
\begin{document}
\(x^3 \, \newfrac{x + y^2}{\sqrt{xy}}\)
\end{document}
ORIGINAL SOLUTION:
If I am understanding your problem, your font is causing "unnatural" vertical spacing. If that is so, you can use the stackengine
package to stack the items with any particular gap (above and below the crossline). In this example, I show the gap as the default (3pt), then as 1pt, and finally as 4pt. EDITED the answer to get the math axis correct.
\documentclass{article}
\usepackage[oldsyntax]{stackengine}
\usepackage{ifthen}
\newlength\testwida
\newlength\testwidb
\newlength\mywidth
\newcommand\newfrac[2]{%
\setlength\testwida{\widthof{$#1$}}%
\setlength\testwidb{\widthof{$#2$}}%
\ifthenelse{\lengthtest{\testwida>\testwidb}}%
{\mywidth=\testwida}%
{\mywidth=\testwidb}%
\raisebox{.5ex}{%
\stackunder{\stackon{\rule{\mywidth}{.4pt}}{$#1$}}{$#2$}}%
}
\parskip 1ex
\begin{document}
\(x^3 \, \newfrac{x + y^2}{\sqrt{xy}}\)
\Sstackgap=1pt
\(x^3 \, \newfrac{x + y^2}{\sqrt{xy}}\)
\Sstackgap=4pt
\(x^3 \, \newfrac{x + y^2}{\sqrt{xy}}\)
\end{document}
[EDIT: The second MWE uses obsolete stackengine syntax for setting stackgap lengths (e.g., \Sstackgap=1ex), which prevented scalable lengths from scaling under a fontsize change. Version 2 of the package (submitted 7/11/13) remedies the problem with a small syntax change.]
Best Answer
This is the most simple way to produce what you want without using a graphical interface. As mentioned by @ach in the comments, you should replace the
$$
by\[
and\]
or\begin{equation}
and\end{equation}
.