Open SteelWagstaff opened 5 years ago
Regex: "/\\$\\$.+\\$\\$|\\\\\\[.+\\\\\\]|\\\\\\(.+\\\\\\)/"
This is how MathJax itself searches: https://github.com/mathjax/MathJax-src/blob/master/ts/input/tex/FindTeX.ts
For #1
above, I think we'd want to set up MathJax to use a local configuration file (see http://docs.mathjax.org/en/v2.7-latest/configuration.html#using-a-configuration-file) and use the following configs settings:
MathJax.Hub.Config({
tex2jax: {
inlineMath: [ ['\\(','\\)'] ]
displayMath: [ ['$$','$$'], ['\[','\]'] ]
}
});
This would cause \( ... \)
to act as inline math delimiters, and `$$...$$
and \[ ... \]
to act as display math delimiters.
For #2
above, we could also add a setting to the config menu that allows authors to use $ globally in the book as a math delimiter. If checked, the setting would result in a config statement that looked like this:
MathJax.Hub.Config({
tex2jax: {
inlineMath: [ ['$','$'], ['\\(','\\)'] ]
displayMath: [ ['$$','$$'], ['\[','\]'] ]
processEscapes: true
}
});
@connerbw recommended looking at how Jetpack handles $latex
as a model for what we’ll need to do to get other delimiters working for various export formats. See https://github.com/Automattic/jetpack/blob/master/projects/plugins/jetpack/modules/latex.php
See our current method for supporting $latex
as a delimiter here: https://github.com/pressbooks/pressbooks/blob/4cdee460dcc1800c7437297c9c45574650b6d814/inc/class-mathjax.php#L326-L426
See also https://github.com/pkra/mathjax-node-page/blob/master/lib/tex.js (for v2 of MathJax)
There is a GPL-licensed WordPress MathJax plugin that supports several kinds of delimiters: https://github.com/phillord/mathjax-latex
Many advanced math users, especially those who spend time writing in LaTeX, are used to
\( ... \)
,\[...\]
or the$
character behaving as special math delimiters. Other solutions, like WP QuickLaTeX, give users an advanced feature option to declare a page as a latexpage with a shortcode, and furthermore lets them declare$
as a math delimiter (when activated, they can use$.
to denote a 'regular' dollar sign). MathJax 3.0 permits similar behavior through the use of custom delimiters: https://docs.mathjax.org/en/latest/options/input/tex.html#tex-options.Proposed:
We should add support for
\( ... \)
and\[...\]
as valid delimiters in our LaTeX/MathJax plugin.We should allow users to choose whether or not to treat single dollar signs as math delimiters. To do so, we should add an option to the MathJax settings page that allows users to treat dollar signs as math delimiters. When selected we should add the inline math and process escapes configuration options described in the MathJax documentation. This would allow them to use additional delimiters (like those described here: i.e.
$
as a math delimiter and\$
to create a 'regular' dollar sign) throughout the book.