barrysteyn / pelican_plugin-render_math

A plugin for the pelican blog to allow it render mathematics in Latex.
67 stars 25 forks source link

Uncaught SyntaxError: Unexpected token < #18

Closed loggerhead closed 9 years ago

loggerhead commented 9 years ago
<script type="text/javascript">if (!document.getElementById('mathjaxscript_pelican_#%@#$@#')) {
    var align = "center",
        indent = "0em",
        linebreak = "false";

    if (false) {
        align = (screen.width < 768) ? "left" : align;
        indent = (screen.width < 768) ? "0em" : indent;
        linebreak = (screen.width < 768) ? 'true' : linebreak;
    }

    var mathjaxscript = document.createElement('script');
   // BUG is HERE
    <a href="http://mathjaxscript.id">mathjaxscript.id</a> = 'mathjaxscript_pelican_#%@#$@#';
    mathjaxscript.type = 'text/javascript';
    mathjaxscript.src = '//<a href="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML';">cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML';</a>
    mathjaxscript[(window.opera ? "innerHTML" : "text")] =
        "MathJax.Hub.Config({" +
        "    config: ['MMLorHTML.js']," +
        "    TeX: { extensions: ['AMSmath.js','AMSsymbols.js','noErrors.js','noUndefined.js','color.js','mhchem.js'], equationNumbers: { autoNumber: 'AMS' } }," +
        "    jax: ['input/TeX','input/MathML','output/HTML-CSS']," +
        "    extensions: ['tex2jax.js','mml2jax.js','MathMenu.js','MathZoom.js']," +
        "    displayAlign: '"+ align +"'," +
        "    displayIndent: '"+ indent +"'," +
        "    showMathMenu: true," +
        "    tex2jax: { " +
        "        inlineMath: [ ['\\\\(','\\\\)'] ], " +
        "        displayMath: [ ['$$','$$'] ]," +
        "        processEscapes: true," +
        "        preview: 'TeX'," +
        "    }, " +
        "    'HTML-CSS': { " +
        "        styles: { '.MathJax_Display, .MathJax .mo, .MathJax .mi, .MathJax .mn': {color: 'inherit ! important'} }," +
        "        linebreaks: { automatic: "+ linebreak +", width: '90% container' }," +
        "    }, " +
        "}); ";
    (document.body || document.getElementsByTagName('head')[0]).appendChild(mathjaxscript);
}
</script>

The content blow is the source markdown and its output html.

$x^2$

$\varepsilon$

$$\varepsilon$$

<p><span class="math">\(x^2\)</span></p>
<p><span class="math">\(\varepsilon\)</span></p>
<div class="math">$$\varepsilon$$</div>
barrysteyn commented 9 years ago

Hi

I just pushed another version - so try it and tell me if your problem goes away. I am going to close the issue, but please open it again if the problem persists.

loggerhead commented 9 years ago

Nothing change after replace with last version...

barrysteyn commented 9 years ago

Can you please point me to your site? Just put the URL here.

loggerhead commented 9 years ago

http://loggerhead.coding.io/tmp.html

barrysteyn commented 9 years ago

Can I also have a list of the plugins that you are using on your site please.

loggerhead commented 9 years ago

I just closed all my plugins, but ,still, nothing changes.

This is my config


# THEME = "themes/sundown"

# MD_EXTENSIONS = ['linkify', 'del_ins', 'fenced_code', 'codehilite(css_class=highlight)', 'tables']
# MATH_JAX = {
#     'tex_extensions': [
#         'color.js',
#         'mhchem.js',
#     ]
# }

PLUGIN_PATHS = ["plugins"]
PLUGINS = [
    # "gzip_cache",
    # "cjk-auto-spacing",
    # "pelican-md-yaml",
    # "sitemap",
    # "assets",
    "render_math",
    # "minify",
]
loggerhead commented 9 years ago

I published my blog code if this can help you : )

barrysteyn commented 9 years ago

Okay, I am looking at it now...

barrysteyn commented 9 years ago

Okay, I have cloned your site. Firstly, tmp.md does not conform to the pelican markdown protocol. The metadata section must not start with ----, so delete the first line.

Also, just for testing purposes, delete everything except the content file tmp.md. Also, delete your cache, and make sure that you pass --ignore-cache when rendering your files. Once you have your site working like you want it to work, then you can turn on the cache again.

Other than that, I am sorry to say that your site is working just fine on my side. Other than using the latest version of pelican, there is nothing else I can recommend. If it is still not working for you, then it is your setup. My suggestion would be to install a virtualenv and just install stuff for pelican so that no other library pollutes.

As far as I can tell, this is not a problem with the plugin.

loggerhead commented 9 years ago

Thank you! The problem is gone after deleted cache directory.

loggerhead commented 9 years ago

I have figure out that the bug will appear when blow line is added to pelicanconf.py. Just remind you.

MD_EXTENSIONS = ['linkify']
barrysteyn commented 9 years ago

Yeah, that makes more sense. You see, that is also a markdown extension, and it is therefore conflicting with math render, which (as you may have guessed) is also a markdown extension. If you really want linkify and render math to work together, then you should dive into the markdown api extension, and you will come accross the ordered dict section. Either render math or linkify has to change their order so that they don't conlict. This assumes that it is even possible to enact the change...