-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Tell MathJax to only process specific nodes #2118
Comments
You can use
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
elements: document.getElementsByTagName("article")
});
</script>
(and it must be placed BEFORE the script that loads MathJax.js itself). This will restrict MathJax typesetting operations to the contents of the specified elements. It is a global property because it applied to ALL preprocessors.
|
Awesome! I've been waist-deep in docs about Queues and pre processors for the past hour. The Google results on this topic really seemed to suggest there was no way of doing it other than |
The problem with @dpvc solution is that if no elements are found, then mathjax will fallback to the default behaviour of trying to process the entire DOM. |
Is there a way around that? |
Sure, a hack like passing an array of a single dummy node (i.e
[document.createElement('div')) if there are no matches (i.e nodes.length
=== 0). But mathjax could make passing null mean don't process anything to
make this less hackish, without a breaking change (altough a better api
would do the opposite, null process all and empty array process nothing).
My 2c
|
One possible way to handle the case where there might be no elements of the given type is the following:
|
How is this to be done with the v3 config? |
MathJax = {
startup: {
elements: ['article']
}
}; See the Startup Options documentation for details. |
Only certain HTML nodes in my site actually contain LaTeX, so I'd like to be able to tell MathJax to only process those. What I'd like to be able to do is something like this:
But instead, the only way I could get the result I want is
<body>
- "nomathjax" or something.ignoreClass
property to exclude the whole page.<article>
tags like "yesmathjax".processClass
property to include those tags back in.It's steps (2) and (4) that bother me. My HTML is mine. I'm finicky about it. I've got it nice and clean and minimal, just the way I like it. I don't want to have to add meaningless CSS classes to it just because a library I'm using needs me to. Actually, in my particular use case, it's impossible for me to do that - I can't modify the page body, all I can do is insert <script> tags into the head.
I don't want to modify my markup, but what I do know - what absolutely anybody who ever wants to restrict MathJax to certain parts of their site knows - is which tags I want to apply MathJax to, and how to get a list of them with Javascript. That should be enough.
Perhaps there's a way of doing this that I'm missing?
The text was updated successfully, but these errors were encountered: