MathJax - Neuron

Welcome to the Functional Programming Zulip Chat Archive. You can join the chat here.

felko

I was trying to use MathJax in neuron and it appears that inline LaTeX isn't working properly.
I can use $$ just fine but single $ for inline formulas isn't rendered, which is weird given this line:
https://github.com/srid/rib/blob/master/src/Rib/Parser/MMark.hs#L119

Haskell static site generator based on Shake. Contribute to srid/rib development by creating an account on GitHub.
felko

Alright I managed to figure it out by reading the MMark docs, apparently it has to be in a code span. It would be nice to explain this in neuron.srid.ca maybe? It's not really obvious for someone that has never used MMark.

Sridhar Ratnakumar

I'm not familiar with mathjax. If you could give me an example I'll add it

felko

I'm writting a zettel to explain how to use mathjax but I think I found a bug in MMark when typing ^ in $$ ... $$ blocks
Also it seems that MMark doesn't handle escapes very well

Sridhar Ratnakumar

Does escaping it like \^ work?

Sridhar Ratnakumar

Looks like maybe it is worth switching to Pandoc after all ...

Sridhar Ratnakumar

(fwiw, mmark is parsing using megaparsec, so if there is a bug in the parser it can be fixed easily in mmark; but I don't know enough about mathjax syntax to make a call)

felko

Sridhar Ratnakumar said:

Does escaping it like \^ work?

Yeah escaping ^ works but latex already has enough \ lol, I think mmark has a special syntax with ^ for typing superscripts but it's not handled by the mathjax parser, which would need to have "higher precedence" somehow

Sridhar Ratnakumar

The extension is here: https://github.com/mmark-md/mmark-ext/blob/master/Text/MMark/Extension/MathJax.hs

Commonly useful extensions for the MMark markdown processor - mmark-md/mmark-ext
felko

can pandoc manage custom markdown extensions?

Sridhar Ratnakumar

Oh they may operate on Pandoc's parsed structure rather than close to Markdown ... don't know. Will need investigation. I probably won't get to doing anything substantial in neuron for a while.

Sridhar Ratnakumar

But... I wonder if one can somehow make mmark behave properly.

Sridhar Ratnakumar

Maybe to support "raw" math thingy, we could do it as:

Some text and `$$math formulat$$`
Sridhar Ratnakumar

(Assuming those backticks prevent use of markdown syntax inside)

Sridhar Ratnakumar

Perhaps you can fork mmark-ext and play with it

Sridhar Ratnakumar

Wait, the extension already supports fenced code blocks?

felko

Yeah this works, the issue is for ... ... blocks

felko

sorry, \$\$ ... \$\$

Sridhar Ratnakumar

Don't $$..$$ and the fenced code version render the same?

Sridhar Ratnakumar

At least in neuron, $$...$$ renders as a block (not inline).

felko

yeah $ ... $ is inline and $$ ... $$ renders as a centered block, a fenced code with 1 line behaves as $$ ... $$ though

felko

anyway here is the zettel i started writing:

---
title: Writing LaTeX in your zettels
---

You can type LaTeX code in zettels in three ways:

- Inline: by surrounding your code with \`\$ ... \$\`
- Block: LaTeX can be displayed in a centered block when surrounded with $$
- Multiple lines at once: \`\`\`mathjax ... \`\`\`

Warning: the `mathjax` code block will treat each line as a separate LaTeX
expression. Thus you can't write `\begin{...}` and `\end{...}` on separate
lines.

This last point about each line being treated as a separate expression feels quite unnatural to me

Sridhar Ratnakumar

Aha, $...$ need to be inside ticks

Sridhar Ratnakumar

@felko Where did you gather that "$$" is supported? I don't see it reading the extension source.

felko

Sridhar Ratnakumar said:

felko Where did you gather that "$$" is supported? I don't see it reading the extension source.

It's a common notation in discord LaTeX bots or in math forums so i tried it and it worked (at least partially)

felko

Maybe the bug is actually the fact that $$ ... $$ works at all

Sridhar Ratnakumar

This mmark extension does not follow any hardcoded convention like that; it allows the user to customize the fencers for inline text.

The extension takes a character as parameter, and rib passes $ (cf. Ext.mathJax (Just '$')).

Sridhar Ratnakumar

Maybe the bug is actually the fact that ... ... works at all

Ah

Sridhar Ratnakumar

You are right, so that's point 2 in your zettel.

Sridhar Ratnakumar

@felko Maybe it is the JavaScript include that is doing it. Not mmark-ext.

felko

Yeah that's possible

Sridhar Ratnakumar

You can simply note this limitation in your point 2, I guess. And then recommend people opt for point 3.

felko

good idea, do you want me to write the thing and do a PR on the guide zettelkasten?

Sridhar Ratnakumar

As a PR, sure. You can put it under Guide -> Zettel Markdown -> Math support

felko

https://github.com/srid/neuron/pull/63

Add documentation about mathjax support from zettel markdown. This is needed because MMark uses unconventional notation for LaTeX input. Some features also have unexpected bugs as $$ ... $$ blocks ...