MathJax icon indicating copy to clipboard operation
MathJax copied to clipboard

Support nicefrac

Open akerbos opened this issue 10 years ago • 8 comments

Please support the command \nicefrac as the one from package nicefrac.

This one allows for much nicer inline fractions (as long as (de)nominator stay short).

akerbos avatar Mar 05 '15 19:03 akerbos

Thanks for making a feature request. These kinds of requests usually work best by writing an extension and making a PR to https://github.com/mathjax/MathJax-third-party-extensions.

If you want a starting point, see http://docs.mathjax.org/en/latest/extension-writing.html#more-advanced-extensions and https://github.com/mathjax/MathJax-docs/wiki/Beveled-fraction-like-sfrac,-nicefrac-bfrac for quick workarounds.

pkra avatar Mar 05 '15 20:03 pkra

Would suggest xfrac instead of nicefrac: http://www.bakoma-tex.com/doc/latex/mh/xfrac.pdf It's basically the same, but plays nice with more fonts than the default Computer Modern. No downsides as far as I can see, just newer.

gandalfsaxe avatar Jun 13 '18 08:06 gandalfsaxe

Note that MathJax only supports a limited number of fonts, and doesn't support mixing fonts, so the font support in xfrac is unlikely to be transferable to MathJax.

On the other hand, you could get something like these macros using MathML's bevelled fractions. You can use

<script type="text/x-mathjax-config">
MathJax.Hub.Config({
  TeX: {Augment: {
    Definitions: {macros: {xfrac: 'XFrac'}},
    Parse: {prototype: {
      XFrac: function (name) {
        var num = this.ParseArg(name);
        var den = this.ParseArg(name);
        this.Push(MathJax.ElementJax.mml.mfrac(num,den).With({bevelled: true}));
      }
    }}
  }}
});
</script>

just before the script that loads MathJax.js in order to implement a simple bevelled fraction.

dpvc avatar Jun 25 '18 08:06 dpvc

This would be really helpful for people on Lyx.

Notify me if it's added :)

BarbzYHOOL avatar Nov 01 '18 21:11 BarbzYHOOL

Registering interest in an xfrac extension for use with PreTeXt. We have long-time built-in historical support for an \sfrac macro which has been downgraded before and which I may severly curtail since it is a real headache. We would gracefully support slanted fractions for authors if such an extension providing \sfrac existed. Thanks.

(Yes, we had the MathML solution above for some time, and had to remove it. I forget the exact reason provoking that.)

rbeezer avatar Oct 18 '23 18:10 rbeezer

@rbeezer, v4 adds a units package that includes \nicefrac, which does bevelled fractions. Perhaps that will fit the bill?

dpvc avatar Oct 18 '23 19:10 dpvc

Thanks! Yes, that could be a workable long-term solution. I'm just now working on a graceful "regression" that will put a small burden on authors on the LaTeX side. That will still mean changes on the HTML side, so moving to \nicefrac could mean a clean break, even.

Thanks again, I'll test as we migrate to v4.

rbeezer avatar Oct 18 '23 19:10 rbeezer

@rbeezer, you might be able to do something like

\newcommand{\sfrac}[2]{\mathchoice{\textstyle\nicefrac{#1}{#2}}{\nicefrac{#1}{#2}}{\nicefrac{#1}{#2}}{\nicefrac{#1}{#2}}}

to define \sfrac.

dpvc avatar Oct 18 '23 20:10 dpvc