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

MathJax delimiters #124

Open
ronnodas opened this issue Aug 14, 2024 · 5 comments
Open

MathJax delimiters #124

ronnodas opened this issue Aug 14, 2024 · 5 comments

Comments

@ronnodas
Copy link

It would be convenient if there was a compile option to have math delimited by \( \) and \[ \] (for inline and display respectively) instead of <code class="language-math math-*">. This is what MathJax uses by default for TeX input.

@wooorm
Copy link
Owner

wooorm commented Aug 14, 2024

a) if you want those delimiters, you can also actually write them, instead of using the $ math syntax?
b) It’s not difficult for you to do that? Or to call mathjax yourself?
c) I think it’s not good, what they do, in HTML there are elements, and semantically TeX is code?

@ronnodas
Copy link
Author

a) Yes I could write those delimiters in the markdown (and in fact I would mildly prefer them over $'s because of the asymmetry) but the slashes require escaping, which makes it harder to compose/edit.

b) Possibly with a separate script, but instead of recreating what MathJax already does with a different set of delimiters it makes more sense to me pass it a thing it knows about. But maybe I don't understand what you want me to do exactly. Currently I'm using replace_all on the output of to_html, which is indeed not difficult but feels silly.

c) I agree with this in principle, and ideally I would want to tell MathJax to use the code tag + math-* class as delimiters. But that seems not possible: it specifically disallows tags in delimiters for apparently good reasons.

@wooorm
Copy link
Owner

wooorm commented Aug 14, 2024

but the slashes require escaping, which makes it harder to compose/edit.

Right, good point!

Currently I'm using replace_all on the output of to_html, which is indeed not difficult but feels silly.

I don’t think that’s too silly.
But, you are including mathjax in the browser right?
So why not include browser code to a) turn <code class="language-math"> into wrappers, b) call the mathjax API?
This seems relating to your c) response too.
It’s sad that the mathjax docs are not done, but it should be possible?
I also use the API in Node.js or browsers: https://github.com/remarkjs/remark-math/blob/main/packages/rehype-mathjax.

@ronnodas
Copy link
Author

I mean passing <code ...> to mathjax as in https://docs.mathjax.org/en/latest/options/input/tex.html#tex-inlinemath does not work.

Note that the delimiters can’t look like HTML tags (i.e., can’t include the less-than sign), as these would be turned into tags by the browser before MathJax has the chance to run. You can only include text, not tags, as your math delimiters.

Using browser code to call the mathjax api should work and I will consider the example you linked, but it seems better to me to change the generated html than to reimplement something mathjax is already doing. The only reason it feels silly to use replace_all is because it's (mildly) reparsing html that is freshly compiled from much more structured data and it would be more sensible to compile it the "way I want it" directly.

If your main objection to this potential feature is the loss of html semantics, would you be fine with keeping the tags but also adding the \( etc inside them? That is, generate something like <span ...> \( a = b \) </span>? I changed the code to span since MathJax does not process anything specifically inside code tags and this behavior seems to be undocumented, so not sure how easy it is to change it. I'm also not asking for this to be the default, but for an added compile option.

@wooorm
Copy link
Owner

wooorm commented Aug 14, 2024

You can still write several lines of JavaScript code in a browser to find code elements, and change them, by changing <code> to \(\). Essentially what you are doing with replace_all, but then in a browser.

My main objections are that:
a) that alternative sounds viable (use the DOM, which is basically an AST, to generate what you want),
b) different HTML output, as an alternative to regex, is more something for ASTs and plugins (#32)
c) for a rust project, it seems more sensical to go in the direction of using rust to do syntax highlighting and math rendering instead of javascript

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants