mathjax / MathJax

Beautiful and accessible math in all browsers
http://www.mathjax.org/
Apache License 2.0
10.14k stars 1.16k forks source link

Enforce \sideset behavior compatible with LaTeX #1202

Open rgaiacs opened 9 years ago

rgaiacs commented 9 years ago

From amsmath documentation

Note: this command is not designed to be applied to anything other than sum-class symbols.

So,

$ cat example.tex 
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{equation}
  \sideset{_*^*}{_*^*}\prod
\end{equation}
\end{document}
$ latexmk -pdf example.tex

works.

screen shot 2015-06-07 at 10 31 34

But

$ cat bug.tex 
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{equation}
  \sideset{_*^*}{_*^*}X
\end{equation}
\end{document}
$ latexmk -pdf bug.tex    
Latexmk: This is Latexmk, John Collins, 5 February 2015, version: 4.43a.
Latexmk: applying rule 'pdflatex'...
Rule 'pdflatex': Rules & subrules not known to be previously run:
   pdflatex
Rule 'pdflatex': The following rules & subrules became out-of-date:
      'pdflatex'
------------
Run number 1 of rule 'pdflatex'
------------
------------
Running 'pdflatex  -recorder  "bug.tex"'
------------
This is pdfTeX, Version 3.14159265-2.6-1.40.15 (TeX Live 2014) (preloaded format=pdflatex)
 restricted \write18 enabled.
entering extended mode
(./bug.tex
LaTeX2e <2014/05/01>
Babel <3.9l> and hyphenation patterns for 21 languages loaded.
(/usr/local/texlive/2014/texmf-dist/tex/latex/base/article.cls
Document Class: article 2014/09/29 v1.4h Standard LaTeX document class
(/usr/local/texlive/2014/texmf-dist/tex/latex/base/size10.clo))
(/usr/local/texlive/2014/texmf-dist/tex/latex/amsmath/amsmath.sty
For additional information on amsmath, use the `?' option.
(/usr/local/texlive/2014/texmf-dist/tex/latex/amsmath/amstext.sty
(/usr/local/texlive/2014/texmf-dist/tex/latex/amsmath/amsgen.sty))
(/usr/local/texlive/2014/texmf-dist/tex/latex/amsmath/amsbsy.sty)
(/usr/local/texlive/2014/texmf-dist/tex/latex/amsmath/amsopn.sty)) (./bug.aux)
! Limit controls must follow a math operator.
<argument> X\nolimits 
                      _*^*
l.5   \sideset{_*^*}{_*^*}X

?

Unfortunately, MathJax isn't compatible with this behavior of LaTeX.

screen shot 2015-06-07 at 10 35 48

This creates problems when users have to create a PDF using LaTeX from a webpage that uses MathJax. Can MathJax be more compatible with LaTeX?

dpvc commented 9 years ago

If you want to make \sideset more strict, you can put

<script type="text/x-mathjax-config">
MathJax.Hub.Config({
  TeX: {Macros: {
    sideset: ["\\mathop{\\vphantom{#3}}\\nolimits#1\\!#3\\nolimits#2",3]
  }}
});
</script>

just before the script that loads MathJax.js itself. That will cause the same type of error that LaTeX does for \sideset{^*_*}{^*_*}X.

There are several other places where MathJax is less strict than LaTeX (e.g., \raise and \lower don't actually require boxes but will operate on an argument enclosed in braces), and a few places where there are differences (e.g., the \color macro takes an argument for what is colored rather than acting on everything that follows). There are also some macros that are MathJax extensions that aren't in LaTeX (e.g., the \style, \class, and \cssId macros for manipulating the attributes of the underlying MathML). So there are a number of things that could still cause problems when MathJax TeX code is inserted into LaTeX directly.

It might be nice to have a "strict-LaTeX" extension that would reduce the number of such cases.