Is it possible to detect cases where the second argument of \frac
is much smaller than the first argument, and split it? Namely (I'm using a new macro name \wfrac
to simplify things),
\wfrac{x}{2} % => \frac{x}{2}
\wfrac{x+y}{2} % => \frac{1}{2}\left(x+y\right)
\wfrac{\sum_{i=1}^{N} i^3}{x+y+z+t}
% => \frac{1}{x+y+z+t} \left(\sum_{i=1}^{N} i^3\right)
% => or \left(\sum_{i=1}^{N} i^3\right) / \left(x+y+z+t\right)
\wfrac{\sum_{i=1}^{N} i^3}{\sum_{i=1}^{N} i}
% => \frac{...}{...} (unchanged)
Feel free to tell me that this is a bad idea.
EDIT: As David notes in his comment, it is not clear what I define as bigger/smaller. The third example in particular features a case where the numerator is taller, but the denominator is wider. he also notes that \wfrac{x}{y}
could become (x)/(y)
. I am building the requirements as I write the question, so feel free to tweak them at your will.
\wfrac{x}{y}
should become one of \frac{x}{y}
, or \frac{1}{y}(x)
, or (x)/(y)
, with ()/
scaling as appropriate. Here is one scheme that could give nice results. Denote hx
, hy
the heights (plus depths) of x
and y
; wx
, wy
their widths; h0
and w0
customizable thresholds for what is considered "small", for instance the dimensions of the formula $a+b$
, but probably the threshold should depend on the \mathstyle
.
-
If
hy < h0
andwy < w0
,- If
hx < h0
andwx < max(w0, 2 * wy)
, use\frac{x}{y}
. - Otherwise use
\frac{1}{y}(x)
.
- If
-
Otherwise use
(x)/(y)
.
Best Answer
I though this was an interesting question, so I gave it a try.
Let me start off with the result:
main.tex
:And it looks like this:
Options:
text
: compare to the equation in\textstyle
.display
: compare to the equation in\displaystyle
.none
: compare to the equation in whatever style is currently active.noparen
: no parenthesessmall
: small maximum height and widthbig
: big maximum height and widthhuge
: huge maximum height and widthlparen
: set left paren, eg:lparen=\left[
rparen
: set right paren, eg:rparen={\right]}
div
: set division mark, eg:div=\div
Commands
\wfrac
: fraction following 'less' rules.\efrac
: fraction following 'less or equal' rules.\setmax
: set the maximum size.\setmaxeq
: set the maximum size using a reference equation.\getmax
: get the maximum size.\getsize
: get the size from an equation.\setparen
: set the parentheses, takes two arguments.\setdiv
: set the division mark.And here is
wfrac.sty
: