MathJax is not rendering on all portion of article page

Hi,

I am using OJS 2.4.2.0. I installed MathJax on my journal website. I have created a sidebar block for MathJax script.

My problem is that the MathJax is rendering the LaTeX code in “Abstract” part only. LaTeX code of “Reference” portion is not rendering (screenshot attached)

What should I do?

Thank you.

GKS

You’ll probably need to ask the MathJax community for support here:
https://groups.google.com/forum/#!forum/mathjax-users

Hi GKS
Did you find an answer to that problem?
Regards
Niels Erik

I have produced a workaround for this issue in OJS 2.4.8.1.
The original issue is caused by the differences in the articles.citations field, and the citations.raw_citation field.
The editor mode shows the contents of articles.citations while the view mode show the contents of the citations.raw_citation field.
The citations.raw_citation field is produced by running the contents of articles.citations through the _cleanCitationString() function which will run stripslashes() on the text to unquote it.
This causes the removal of the \ used in the MathJax markup thus breaking it.

Here is a workaround which just doublequotes the MathJax markup before it is passed through stripslashes()

--- a/lib/pkp/classes/citation/Citation.inc.php
+++ b/lib/pkp/classes/citation/Citation.inc.php
@@ -258,7 +258,10 @@ class Citation extends DataObject {
                    $citationString = String::utf8_normalize($citationString);
            }
            // 2) Strip slashes and whitespace
-               $citationString = trim(stripslashes($citationString));
+               // but do not touch MathJax macros of the form $\macro args$
+               // this is done by doublequoting them before sending the string through stripslashes
+               // note regexp_replace requires further quoting to represent \
+               $citationString = trim(stripslashes(String::regexp_replace('/\$\\\\(\w+)/', '$\\\\\\\\\\\\${1}', $citationString)));
 
            // 3) Normalize whitespace
            $citationString = String::regexp_replace('/[\s]+/', ' ', $citationString);

This will allow the MathJax markup to pass through unharmed into the citations.raw_citation field.

After a bit more thinking I’ve improved on this to ensure that even complex expressions with multiple \macro invocations within a $$ pair are quoted correctly.
The new version:

--- a/lib/pkp/classes/citation/Citation.inc.php
+++ b/lib/pkp/classes/citation/Citation.inc.php
@@ -258,7 +258,12 @@ class Citation extends DataObject {
                        $citationString = String::utf8_normalize($citationString);
                }
                // 2) Strip slashes and whitespace
-               $citationString = trim(stripslashes($citationString));
+               // but do not touch MathJax macros of the form $\macro args$
+               // this is done by doublequoting them before sending the string through stripslashes
+               // with a callback we can ensure that all \ within each $macro$ are quoted so even complex
+               // expressions like $\sum_{i=0}^n i^2 = \frac{(n^2+n)(2n+1)}{6}$ will pass through correctly
+               $citationString = trim(stripslashes(String::regexp_replace_callback('/\$\\\\[^$]+\$/',
+                   function($match){return preg_replace('/\\\/','\\\\\\\\\\\\',$match[0]);}, $citationString)));
 
                // 3) Normalize whitespace
                $citationString = String::regexp_replace('/[\s]+/', ' ', $citationString);

(edit: forgot a couple of backspaces)

1 Like