-
-
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
Latex Array is not rendering on website, but works locally. #2377
Comments
That main problem is that the newlines have been stripped out of the page when it is being served at the https://www.mateuszdorobek.pl site. If you look at the two source windows in your images, the live site has no line breaks, while the local one does. The reason this matters is because jekyll (I think) is preprocessing the math on the page to insert MathJax v2-style So you either need to tell your server not to remove newlines, or tell Jekyll not to insert the Alternatively, you could install a TeX input filter to remove the <script type="text/x-mathjax-config">
MathJax.Hub.Register.StartupHook('TeX Jax Ready', function () {
MathJax.InputJax.TeX.prefilterHooks.Add(function (data) {
data.math = data.math.replace(/^% <!\[CDATA\[/, '').replace(/%\]\]>$/, '');
});
});
</script> used before the script that loads MathJax's Note, that you are not using MathJax v3 but rather MathJax v2.7.4 (see the press release for v2.7.6 for why you are not getting the latest version of mathJax any longer). You actually are loading both v2 and v3 (not very efficient), but because the page has v2-style In any case, you don't want to load both. Also, your v2 configuration will not work with v3, as it has a different means of configuration. There is a configuration converter that can help you convert your old configuration to v3 form. But again, you might not have access to that, as Jekyll is probably putting that in place for you. So you might need to get an updated version of whatever plugin you are using to include MathJax in Jekyll output. I don't know if there is a v3 one or not; you'll have to look. |
Thank you for such a detailed answer.
I'm hosting it on github pages, so I have no control over the server.
Wow
I've done so and this FIXED THE PROBLEM for me.
Yeah you're right, I thought that is another This Is my <script type="text/x-mathjax-config">
MathJax.Hub.Register.StartupHook('TeX Jax Ready', function () {
MathJax.InputJax.TeX.prefilterHooks.Add(function (data) {
data.math = data.math.replace(/^% <!\[CDATA\[/, '').replace(/%\]\]>$/, '');
});
});
</script>
<script type="text/javascript" id="MathJax-script" async src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.6/latest.js"></script> My page looks OK now. Thank you very much. That was really sick error, but your preprocessing code did the job, thank you again ;) |
Glad you were able to get it to work. Thanks for letting us know. |
Great answer, thanks, this tells me exactly what the problem is! I can't seem to figure out how to access "data.math" inside ready(). There doesn't seem to be any InputJax.TeX.prefilterHooks arrangement either. Any help would be great. |
For v3 it is a little more complicated, since the comment strings are removed before the TeX input jax runs, so a pre-filter doesn't work in that case. So you have to modify the code that collects the DOM strings to make sure the CDATA comments are included. Here is one possible solution: <script>
MathJax = {
startup: {
ready: function() {
var HTMLDomStrings = MathJax._.handlers.html.HTMLDomStrings.HTMLDomStrings;
var handleTag = HTMLDomStrings.prototype.handleTag;
HTMLDomStrings.prototype.handleTag = function (node, ignore) {
if (this.adaptor.kind(node) === '#comment') {
var text = this.adaptor.textContent(node);
if (text.match(/^\[CDATA\[(?:\n|.)*\]\]$/)) {
this.string += '<!'
this.extendString(node, text);
this.string += '>';
return this.adaptor.next(node);
}
}
return handleTag.call(this, node, ignore);
}
MathJax.startup.defaultReady();
MathJax.startup.document.inputJax[0].preFilters.add(function (data) {
data.math.math = data.math.math.replace(/^% <!\[CDATA\[/, '').replace(/%\]\]>$/, '');
});
}
}
};
</script> This should come before the script that loads the MathJax component you are using, and if you already have other configuration, it needs to me merged into that. |
@aseemrb, did you get this to work? I got a notification of a post from you, but it seems to have been deleted. |
@dpvc sorry for the late response, the snippet you provided didn't work; but I ended up with the following, which works: <script>
document.addEventListener('DOMContentLoaded', function(){
function stripcdata(x) {
if (x.startsWith('% <![CDATA[') && x.endsWith('%]]>'))
return x.substring(11,x.length-4);
return x;
}
document.querySelectorAll("script[type='math/tex']").forEach(function(el){
el.outerHTML = "\\(" + stripcdata(el.textContent) + "\\)";
});
document.querySelectorAll("script[type='math/tex; mode=display']").forEach(function(el){
el.outerHTML = "\\[" + stripcdata(el.textContent) + "\\]";
});
}, false);
window.MathJax = {
options: {
renderActions: {
findScript: [9, function (doc) {
for (const node of document.querySelectorAll('script[type^="math/tex"]')) {
const display = !!node.type.match(/; *mode=display/);
const math = new doc.options.MathItem(node.textContent, doc.inputJax[0], display);
const text = document.createTextNode('');
node.parentNode.replaceChild(text, node);
math.start = {node: text, delim: '', n: 0};
math.end = {node: text, delim: '', n: 0};
doc.math.push(math);
}
doc.findMath();
}, '']
}
}
};
</script> Here the latter half comes from the official documentation, while in the first half I'm simply stripping the dom content of all I see that github needs to allow |
OK, thanks for sharing your solution. I suspect you don't need to the |
Hi, I've tried both of the presented solutions but neither has worked. I am using V2 and I noticed that OP's website is not rendering the maths, so I'm assuming that solution may be outdated. Website: https://moribots.github.io/project/ekfslam Here is my
The last script is for mathjax to render any math that was missed in the first pass since I'm using a dynamic jekyll site. |
@moribots, you are using Try using
od use '$$...$$' around your displayed equations instead of '[...]'. |
Thanks for the quick response! Here is an example of an array I use, delimited by
If I understood correctly I think this fits your description of what should be working. |
@moribots, the arrays on the link you provided above are not delimited by The issue on the page for which you provided a link is the inconsistency between the configured delimiters ( |
I just noticed something odd based on your comment: This array delimited as you described by For reference, it looks like this offline: Edit: I also tried adding changing the display config as you suggested but this did not change the live site. However, now the offline build is also unrendered. Thanks again, I hope I've given you enough information. |
@moribots, whatever content management system you are using to create your pages (Jekyll?) is probably identifying the math (so that it doesn't further process the math itself) and inserting it into the page after creating the HTML needed for it. It may change the delimiters to the standard LaTeX ones in that process. So your solution is to change the configuration as I suggested above so that it will work both with your original delimiters and the ones that Jekyll uses. |
Thanks! When I tried to add the backslash delimiter option it actually stopped rendering all of the maths instead of just the arrays like before. Does that give you any clues? Yes I am using Jekyll |
That suggests that you made a syntax error in your configuration and MathJax couldn't process it. Were there any errors in your browser console window? |
When I run
I hope that helps. |
When I run bundle exec jekyll serve I get no errors.
I wasn't asking about running Jekyll, I was asking about when you load the page in the browser, do you get any errors in the browser's console window.
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: {
inlineMath: [ ['$','$'], ["\\(","\\)"] ],
displayMath: [ ['$$','$$'] ],
processEscapes: true,
skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
}
});
</script>
While you have set the inline math to include \(...\) as delimiters, you have not changed the disoplayMath to include \[...\] as delimiters, which is what you need in order to resolve the problem you are seeing, since the displayed equations are delimited by \[...\] not $$...$$ in the final page produced by Jekyll.
<script type="text/javascript" async
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?config=TeX-MML-AM_CHTML">
</script>
<script type="text/javascript">
MathJax.Hub.Queue(
["resetEquationNumbers",MathJax.InputJax.TeX],
["Typeset",MathJax.Hub]
);
</script>
The last script is probably not needed, and is in the wrong place in any case. At the point it runs, MathJax will likely not be available yet (since your previous script has the ASYNC attribute), so likely will generate an error about MathJax not being defined (it does for me). Also, it doesn't really do anything since it used a typeset right after the initial typeset, and that probably won't find any new math since your page will not have had time to load any in between typesets. I'd try leaving that out entirely, since it is likey not actually running in any case.
|
Thanks for the detailed response! I've gotten rid of the last script. If I include On the live site, nothing has changed. |
you have the quotation marks in the wrong place. Try
instead. Your way, the configuration failed to be processed, and so MathJax couldn't run. You should probably see an error message in the browser console. |
Thank you so much, that was it! |
I come across this thread while struggling finding a solution to why all of the line break delimiter The website is at https://lhoangan.github.io/camera-params/, Equation (3) <script type="text/x-mathjax-config">
MathJax.Hub.Register.StartupHook('TeX Jax Ready', function () {
MathJax.InputJax.TeX.prefilterHooks.Add(function (data) {
data.math = data.math.replace('<br/>', '\\');
});
});
</script>
</script>
<script type="text/javascript" async
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-MML-AM_CHTML">
</script> |
@lhoangan, Equation 3 renders properly for me in the page you link to. Does that link not work for you? Also note that v2.7.1 of MathJax is three and a half years old, so you may want to update to a more recent version. The highest version of 2.x is 2.7.9. |
It turns out that the problem lies with Kramdown 2.3.0 (or Jekyll 3.9.0).
My old version at local does not have problem with triple backslashes at
the end of line (1 extra for espace character), but the current version
used by GitHub page keeps interprete and convert double backslashes as hard
line-break (<br/>).
So I added an extra space behind the backslashes and now it is solved.
Thanks you for your time and for the info. I'll check it out.
…On Sat, Sep 19, 2020, 20:50 Davide P. Cervone ***@***.***> wrote:
Equation 3 renders properly for me in the page you link to. Does that link
not work for you?
Also note that v2.7.1 of MathJax is three and a half years old, so you may
want to update to a more recent version. The highest version of 2.x is
2.7.9.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#2377 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACHG2TS6JWHV2NP2LWNQ7W3SGT4QFANCNFSM4LRPPESA>
.
|
Issue Summary
I'm trying to write Latex array using MathJax, it works fine locally when I render it with
bundle exec jekyll liveserve
but when I push it to my GitHub pages repo it doesn't render. Simple equations work on the website, but I have a problem with arrays.Steps to Reproduce:
Technical details:
Supporting information:
My config files:
\includes\_lib\mathjax.html
\asserts\js\MathJaxLocal.js
My web Page: https://www.mateuszdorobek.pl/posts/2020/03/Numerical-linear-algebra-notes
The text was updated successfully, but these errors were encountered: