Feature Request: Support for \nicefrac in Discourse Math (\KaTeX/\MathJax)

AI-generated summary

Ethsim2 has submitted a feature request to add support for the \nicefrac{a}{b} command in Discourse’s math rendering systems (KaTeX or MathJax). This command produces compact, diagonal fractions (e.g., \nicefrac{1}{2}) that are visually cleaner than 1/2 and less disruptive to line spacing than \dfrac{1}{2}. The request includes implementation guidance: for MathJax, enabling the nicefrac.js extension via config may suffice; for KaTeX, which lacks native support, a macro workaround or third-party extension like katex-extension could be used. Currently, attempting to render \nicefrac results in parse errors in both engines unless configured. The feature is motivated by its widespread use in LaTeX, especially in STEM contexts, to improve inline math readability. References are provided to relevant GitHub issues and MathJax documentation. This enhancement aims to reduce user confusion and improve math formatting consistency across Discourse communities.

:puzzle_piece: Feature Request: Add Support for \nicefrac in Discourse Math Rendering

Summary

Please add support for the \nicefrac{a}{b} command in Discourse math rendering. This diagonal-style fraction is compact and ideal for inline expressions, improving readability without disrupting line spacing.


:test_tube: Why \nicefrac?

  • Produces clean, diagonal (slashed) fractions like $ \nicefrac{1}{2} $
  • More elegant than 1/2 and less bulky than \dfrac{1}{2}
  • Common in physics, statistics, and mathematical writing

:package: Implementation Notes

Discourse might be able to support math via KaTeX or MathJax, depending on the installed plugin. This feature request outlines implementation for both:

:white_check_mark: MathJax

MathJax might support \nicefrac if an extension is loaded:

MathJax.Hub.Config({
  TeX: {
    extensions: ["AMSmath.js", "nicefrac.js"]
  }
});

This could mean no core changes are needed — so you could just update the plugin config to enable the extension.

:wrench: KaTeX

KaTeX does not support \nicefrac natively. It might be possible that the following workaround macro can be added:

macros: {
  "\\nicefrac": "\\raisebox{.5ex}{\\footnotesize #1}/\\raisebox{-.25ex}{\\footnotesize #2}"
}

Alternatively, it might be worth investigating support through third-party KaTeX extensions such as katex-extension.


:magnifying_glass_tilted_left: Reproduction

Try rendering the following:

$\nicefrac{3}{4}$

Result in KaTeX:

`KaTeX parse error: Undefined control sequence: \nicefrac

Result in MathJax (if extension not loaded):

LaTeX Error: Command \nicefrac undefined `MathJax parse error: Undefined control sequence: \nicefrac


:white_check_mark: Expected Behavior

  • $ \nicefrac{3}{4} $ renders a proper diagonal fraction
  • Might be able to work consistently across both KaTeX and MathJax installs providers
  • Hopefully, No parse errors or user confusion

:speech_balloon: Motivation

  • \nicefrac is widely used in LaTeX documents and teaching materials
  • Inline fractions appear more naturally in text
  • Improves math formatting in STEM-heavy Discourse communities

:link: References

Thank you for considering this small but valuable improvement to math rendering in Discourse!