Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve MathJax support by enabling $$ for math equations #400

Open
azerupi opened this issue Aug 10, 2017 · 16 comments
Open

Improve MathJax support by enabling $$ for math equations #400

azerupi opened this issue Aug 10, 2017 · 16 comments
Labels
A-MathJax Area: MathJax C-enhancement Category: Enhancement or feature request C-papercut Category: A small usability bug E-Medium Experience: Medium S-Wishlist Status: Wishlist

Comments

@azerupi
Copy link
Contributor

azerupi commented Aug 10, 2017

Currently, Mathjax is a little akward to use because we only support the \( ... \) and \[ ... \]method to indicate inline and block equations respectively. On top of that, backslashes need to be escaped so that the markdown parser doesn't remove them. Thus, equations need to be written like:

\\[ \mu = \frac{1}{N} \sum_{i=0} x_i \\]

So when mathjax support is enabled in the configuration, it would be great to add a preprocessor that rewrites the \[ ... \] forms to \\[ ... \\] and add support for the $$ ... $$ math delimiters.

@azerupi azerupi added E-Medium Experience: Medium S-Wishlist Status: Wishlist C-enhancement Category: Enhancement or feature request C-papercut Category: A small usability bug labels Aug 10, 2017
@subthedubdub
Copy link

Couldn't this be implemented entirely in JavaScript (see the MathJax Docs)?

@azerupi
Copy link
Contributor Author

azerupi commented Aug 13, 2017

Ah thanks for reminding me, I forgot the most important part of this issue!

Currently, math expressions will collide with markdown syntax. If you write a*b*c=d the markdown parser will emphasise b, which is not what we want.

So to make mathjax fully usable, we need to preprocess the equations and replace it with something that will be skipped by the markdown parser. The solution in my first post will therefore not work.

What I propose is to wrap the math equations with html tags. For inline <span class="inline-math">...</span> and for blocks <div class="math"></div>. The markdown parser will recognise this as raw HTML and will leave it as is.

@dvberkel
Copy link
Contributor

I would like to look into this. Will start a branch and send in a WIP pull request

dvberkel added a commit to dvberkel/mdBook that referenced this issue Feb 17, 2018
First commit in a branch dedicated to improving MathJax support. See issue rust-lang#400.
@brendanzab
Copy link
Member

brendanzab commented Apr 26, 2018

I'm wondering if it would be better to switch to using code-fences for embedded markup languages, as suggested in this thread on the CommonMark forums, eg:

```{latex}
\begin{tikzpicture}
\node[inner sep=0pt] (russell) at (0,0)
    {\includegraphics[width=.25\textwidth]{bertrand_russell.jpg}};
\node[inner sep=0pt] (whitehead) at (5,-6)
    {\includegraphics[width=.25\textwidth]{alfred_north_whitehead.jpg}};
\draw[<->,thick] (russell.south east) -- (whitehead.north west)
    node[midway,fill=white] {Principia Mathematica};
\end{tikzpicture}
```

This would also have the advantage of making the github previews look much nicer. We might have to wait for this to go through the pipeline of standardization though. :/

@ghost
Copy link

ghost commented Aug 9, 2019

I'll naively plug tectonic. It is a full LaTeX engine partially written in rust that could potentially integrate with mdBook for advanced formatting needs.

@vadixidav
Copy link

Does anyone happen to be working on this right now? If not, the Rust ML WG is interested in picking this task up.

@ehuss
Copy link
Contributor

ehuss commented Apr 22, 2020

@vadixidav I doubt anyone is looking at it. Feel free to take a look, though I'm not up to speed with what the problems are (I think maybe mathjax needs to be a preprocessor?).

@ghost
Copy link

ghost commented Apr 22, 2020

I am not @vadixidav.

@jeanm
Copy link

jeanm commented Apr 22, 2020

I'm not working on this, but I'll leave two pointers here which are hopefully useful to people who are:

@bytesnake
Copy link

bytesnake commented Apr 22, 2020

Hey, I created recently a small plugin for scientific mdbook. This adds support for latex, gnuplot, and bibtex rendering. Equations are rendered to SVG without KaTeX or MathJax, but I'm planing to support them later on. I also added support for referencing/citations across the book. A sample can be found here and the github repository here.

@Yang-Xijie
Copy link

This is exactly a great feature to be considered.

@pesho-ivanov
Copy link

Github seems to have no problem of using MathJax over Markdown using the obvious Latex syntax $...$ and $$...$$. What is the reason this is not the case for mdBook and can't the same approach as for Github be used?

@ehuss
Copy link
Contributor

ehuss commented Mar 23, 2023

I think this is overall blocked on pulldown-cmark/pulldown-cmark#622.

@expikr
Copy link
Contributor

expikr commented Apr 13, 2023

mdbook-katex is now quite feature-complete, capable of producing completely static outputs. It is also capable of rendering inside <detail></detail> blocks with no issue (@your-diary 's #1926), and uses the $...$ and $$...$$ delimiter by default and can add custom delimiters.

See https://github.com/SichangHe/mdbook_katex_static_css/

Any reason why the CDN-delivered MathJax must have the exclusive privilege of being the "default"?

@0xPhaze
Copy link

0xPhaze commented Apr 17, 2023

Since I got lost in this and a few other open issues: https://github.com/lzanini/mdbook-katex works well.

@sanmai-NL
Copy link

@ehuss Would you consdier, also from a maintainability viewpoint, to drop MathJax and recommend users to use an extension such as mdbook-katex?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-MathJax Area: MathJax C-enhancement Category: Enhancement or feature request C-papercut Category: A small usability bug E-Medium Experience: Medium S-Wishlist Status: Wishlist
Projects
None yet
Development

No branches or pull requests