MathJax and PHP

60 views
Skip to first unread message

valer...@gmail.com

unread,
Jul 21, 2017, 6:56:16 AM7/21/17
to MathJax Users
If I use a file with extension .php on my local webserver (on Mac), MathJax works fine. But if I put it on a remote server, then MathJax  no longer works. But, if I change the file extension from .php to .html, then MathJax on the remote server works fine (but of course I have no php functionality). I tried this with two different remote servers. So on the remote server, I either get MathJax to work or php, but not both, but on my Mac local server they both work.

These are the links to the two files (one is .php and one is .html) on my institution's server:

How could I get both php and MathJax to work?
Thanks for any help


William F Hammond

unread,
Jul 21, 2017, 2:42:03 PM7/21/17
to mathja...@googlegroups.com
Could you make a minimal example?

--
You received this message because you are subscribed to the Google Groups "MathJax Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mathjax-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

valer...@gmail.com

unread,
Jul 23, 2017, 5:55:23 PM7/23/17
to MathJax Users
Thanks for the suggestion.
The two links take to two identical test web sites on two different servers that use php and MathJax and have very little content.



I made some more testing and I have found that the problem is related to the browser cache. With Google Chrome on a Mac, if I do a clear browsing data, then the first time I load the web site from a remote server the MathJax will work fine. But as soon as I do a  reload, it will not work. I also found that the first remote server works better than the other (in the sense that it is more likely the MathJax will be interpreted on reloading), and the browser will also make a difference. Google Chrome is the worst, Firefox the best. FireFox on a Mac almost always works on reloading (but it still fails a few times). FireFox on Lubuntu has never failed to work on reloading so far. Google Chrome on a Mac almost never works on reloading.


On Friday, July 21, 2017 at 1:42:03 PM UTC-5, William F Hammond wrote:
Could you make a minimal example?
On Fri, Jul 21, 2017 at 3:56 AM, <valer...@gmail.com> wrote:
If I use a file with extension .php on my local webserver (on Mac), MathJax works fine. But if I put it on a remote server, then MathJax  no longer works. But, if I change the file extension from .php to .html, then MathJax on the remote server works fine (but of course I have no php functionality). I tried this with two different remote servers. So on the remote server, I either get MathJax to work or php, but not both, but on my Mac local server they both work.

These are the links to the two files (one is .php and one is .html) on my institution's server:

How could I get both php and MathJax to work?
Thanks for any help


--
You received this message because you are subscribed to the Google Groups "MathJax Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mathjax-user...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Davide Cervone

unread,
Jul 24, 2017, 2:08:06 PM7/24/17
to mathja...@googlegroups.com
Your page loads MathJax several times, once explicitly via the script 

<script type="text/javascript" async
  src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>

and once implicitly via

<script src="css/latexmathjax.js"></script>

since this script injects a script call to load MathJax.

This is made a bit more complicated by the fact that latexmathjax.js loads MathJax from the old CDN, and that copy of MathJax in turn injects another script to load MathJax from cdnjs.

All of these injected scripts load asynchronously, as does your explicit one, since you have "async" specified in the script tag.  That means that the order in which they run will vary from page load to page load, and may be affected by caching, as you have noticed.

I have not investigated the issue closely, but I do note that during the times that the math is processed, the latexmathjax.js file seems to run first, and when it doesn't, the MathJax copy seems to run first.  This makes sense, because the original latexmathjax content is in a <pre> script, which MathJax would skip (if it ran first), but latexmathjax replaces those <pre> tags with their (modified) contents so that MathJax can process them later.  But when MathJax runs first, it skips the <pre> tags entirely (so no math in them is processed), and then latexmathjax runs replacing the <pre> tags, and loads MathJax.js again.  But MathJax.js does not run twice, even if loaded a second time.

So the order in which things run makes a big difference, but you have no control over that when using the async attribute and script injection, so you get one result sometimes and another result other times.

I would recommend removing your explicit <script> tag that loads MathJax.js, and let latexmathjex do it, as that will make sure MathJax doesn't run until after latexmathjax has done its job.  But you might want to modify your copy of latexmathjax.js in order to load from cdnjs.cloudflare.com version rather than cdn.mathjax.org, since the latter may be removed in the future.

See if that doesn't resolve your problem.

Davide

valer...@gmail.com

unread,
Jul 25, 2017, 8:10:08 AM7/25/17
to MathJax Users
This absolutely solves the problem, and everything works very well now on all servers and with all browsers. With a page with a lot of content, there is sometimes a fraction of a second when the LaTeX code is displayed before MathJax interprets it but it really does not cause any problem. Thank you Davide Cervone for outstanding help and crystal clear explanations. 
Reply all
Reply to author
Forward
0 new messages