-
Notifications
You must be signed in to change notification settings - Fork 42
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
[Question] Importing the RegExp that MathJax uses to select Latex in Content? #37
Comments
MathJax doesn't use a RegExp for this. But it does have a module that will find the delimited math in an array of strings, and you can call on that. const {FindTeX} = require('./js/input/tex/FindTeX.js');
const md = `Some latex $$\\frac{\\sum_{i=1}}^n$$ and some more latex $$MAD = \\frac{\\sum_{i=1}^n | x_i - \\bar{x} |} n$$`;
const find = new FindTeX({
//
// These are the default options, so not really needed, but are used as an example
//
inlineMath: [['\\(','\\)']] ,
displayMath: [['$$', '$$'], ['\\[', '\\]']],
processEscapes: true,
processEnvironments: true,
processRefs: true
});
console.log(find.findMath([md])); will produce
(I added a missing brace in your first expression.) The return value is an array of objects describing the math that has been identified. The properties give the open and close delimiters ( So matches = find.findMath([md]).map(item => item.math);
console.log(matches); should get you what you describe above. |
@dpvc THANK YOU! That's AWESOME! I have it working now. I'm so happy about this. I was trying to use RegEx for this and I think I was getting more gray hair by the hour. Thanks again! |
Yes, regular expressions really don't work for this (the nesting of braces make it very difficult, in particular). |
I have Latex expressions in Markdown and I need to select them.
They look something like this:
I was wondering if MathJax exposes the RegExp it uses to select the expressions so I could import it. Something like:
const regexp = require('MathJax').regexp
Then the selection could be performed like this:
Thoughts?
The text was updated successfully, but these errors were encountered: