-
Notifications
You must be signed in to change notification settings - Fork 853
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
Math rendering problem #645
Comments
Hi, I looked into more details for the issue and I found the problem but I am not able to correct it (my javascript is not good enough for this 😢). For instance, suppose that the code markdown contains: 1. This is a product \\(x_1 \times x_2\\) which works!
2. This is a product \\(x_1 \times x_{12}\\) which doesn't work! The HTML output by remark.js is the following: <ol>
<li>This is a product \(x_1 \times x_2\) which works!</li>
<li>This is a product \(x<em>1 \times x</em>{12}\) which doesn't work!</li>
</ol> and so the second math formula cannot be displayed correctly! I hope it helps in correcting the bug. Best, |
Hi Mathieu, Thanks for your insight about the issue. An (ugly) workaround is to add a backslash to escape each underscore. For example, the following works for me.
I do hope someone can fix the original issue. |
Hi Fred, Thanks a lot for the tip!!! My goal would be to write latex formulas without escaping anything. As a first step is, I modified my html file (I can't even compile the project so I cannot try to modify the source code of remark) in order to avoid to escape every underscore and every $$\begin{array}{ll}
\max & x_1 + 3x_2\\
s.t & 6x_1 + 7 x_2 \leq 18\\
& 3x_{34} + 3x_{23} \leq 27\\
& x \geq 0
\end{array}
$$ and it works! If for some reason, you have trouble with this preprocessing, you just need to delimit your formulas with Here is my code to add in the html file (at the beginning of the scipt, before function replaceBsInline(match, p1, offset, string){
return "\\\\(" + p1.replaceAll("_", "\\_") + "\\\\)";
}
function replaceBs(match, p1, offset, string){
p1 = p1.replaceAll("\\\\", "\\\\\\\\");
s = "\\\\[" + p1.replaceAll("_", "\\_") + "\\\\]";
return s;
}
s = document.body.innerHTML;
s = s.replaceAll(/\$\$([^]+?)\$\$/g, replaceBs);
s = s.replaceAll(/\$(.+?)\$/g, replaceBsInline);
document.body.innerHTML = s; I only tried with two formulas so I cannot guarantee the results in any case! Best, |
Hi Mathieu, Your solution works for me w.r.t. not having to escape However, it is not displaying curly brackets now. For example, without your script, I can display the
I don't fully understand what you did in the script to fix it. But I thought you might be interested :) Thanks! |
Hi Fred, You're right, there's some problem! function replaceBsInline(match, p1, offset, string){
p1 = p1.replaceAll("\\", "\\\\");
return "\\\\(" + p1.replaceAll("_", "\\_") + "\\\\)";
}
function replaceBs(match, p1, offset, string){
p1 = p1.replaceAll("\\", "\\\\");
s = "\\\\[" + p1.replaceAll("_", "\\_") + "\\\\]";
return s;
}
s = document.body.innerHTML;
s = s.replaceAll(/\$\$([^]+?)\$\$/g, replaceBs);
s = s.replaceAll(/\$(.+?)\$/g, replaceBsInline);
document.body.innerHTML = s; Now, you can juste write Best, |
Hi Mathieu, This new version works perfectly with the curly bracket. Thank you! Now, here's the rabbit hole. I often use the following line to highlight a formula.
But now MathJax does not render the formula and simply displays the following (for the in-line case).
Using The problem seems to have to do with the inner dollar signs. Highlighting a formula is something that I use quite often, and it'd be nice if this fix still supports it. But no worries if you don't have time to look into it. |
Hi Mathieu, Just to document another thing that stopped working is like the example below, where the
|
One more thing that stops working is the following:
It is now rendered as "This is a variable (x)." |
The following stopped working as well. Any inline underscore inside a
|
Hi Fred, Sorry for the delay, I do not have much time right now. I do not know how to solve the different problems. It mainly comes from the fact that $$ \text{This is $ \alpha $.} $$
\\[ \text{This is $ \alpha $.} \\]
$$ \text{This is \\( \alpha \\).} $$
\\[ \text{This is \\( \alpha \\).} \\] the first 3 formulas are correctly rendered but not the last one (considering that you remove my code). I do not know enough to find a solution because I do not understand why there is no equivalence between the delimiters. Right now, I think it is preferable I think to remove my code and add backslashs everywhere! Best, |
Hi Mathieu, Thank you for the insights. I think I might have made it work (at least on my machine)*. But first, all the four formulas in your previous reply render correctly on my machine without your code. Below are my configurations for your reference. <script src="https://remarkjs.com/downloads/remark-latest.min.js"></script>
<script src="https://cdn.bootcss.com/mathjax/2.7.1/MathJax.js?config=TeX-MML-AM_HTMLorMML&delayStartupUntil=configured"></script>
MathJax.Hub.Config({
tex2jax: {
skipTags: ['script', 'noscript', 'style', 'textarea', 'pre'],
inlineMath: [['$','$'], ['\\(','\\)']]
},
}); So I made some changes to your code (see below). And now all the issues that I described in my previous replies were gone (Edit: I just found it actually creates some new issues*. See the bottom) One main thing I found is that your regex pattern for the inline Below is what I used. function replaceBsInline(match, p1, offset, string){
return "$" + p1.replaceAll("_", "\\_") + "$";
}
s = document.body.innerHTML;
s = s.replaceAll(/\$(.+?)\$/g, replaceBsInline);
document.body.innerHTML = s;
<!-- this works -->
$$\sum_{i = 1}^n \sum_{j = 1}^n x_{ij} = 0$$
<!-- this doesn't work -->
$$
\sum_{i = 1}^n \sum_{j = 1}^n x_{ij} = 0
$$ |
Ok, so here's what works best for me. First, I will not attempt to solve the issue of having to escape So I'll only try to solve the original issue raised in this post, that is, having to escape the function replaceBsInline(match, p1, offset, string){
p1 = p1.replaceAll("\\_", "_"); // this is to avoid replacing "_" twice with nested delimiters (e.g., $$\text{I'm $x_1$}$$)
return "$" + p1.replaceAll("_", "\\_") + "$";
}
function replaceBs(match, p1, offset, string){
return "$$" + p1.replaceAll("_", "\\_") + "$$";
}
s = document.body.innerHTML;
s = s.replaceAll(/\$\$([^]*?)\$\$/g, replaceBs);
s = s.replaceAll(/\$(.*?)\$/g, replaceBsInline);
document.body.innerHTML = s; Hope this is helpful for other people. |
Hi Fred, Thank you for your configuration. Actually, I use katex instead of mathjax but maybe I will switch if I can't configure katex correctly (I have not tried yet). I agree it is a difficult problem :) ! |
Hi,
Remark.js is really great for generating slides but I have problem to integrate math formula in slides (with katex or mathjax).$$e^{i\pi} + 1 = 0$$ by $$\sum_{i = 1}^n \sum_{j = 1}^n x_{ij} = 0$$ does not work anymore.
The examples given in the wiki work well but many formula cannot be correctly displayed. For instance, using double \sum symbol does not work. In the examples, changing
Is there a way to include more complex formula in the slides? The problem does not come from mathjax and katex in general because they can display such kind of formulas (with double sum for instance).
Best,
Mathieu
The text was updated successfully, but these errors were encountered: