pelican-plugins / render-math

Pelican plugin that renders mathematics via the MathJax JavaScript engine
Other
30 stars 7 forks source link

render-math with 4.9.1 has no attribute "register" #23

Closed cppgent0 closed 8 months ago

cppgent0 commented 9 months ago

Using pelican 4.9.1, and a slightly modified theme "pelican-twitchy"

Used this version of render_math: git clone https://github.com/getpelican/pelican-plugins plugins

Added the missing CDN line:

<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script> mathjax works just fine with the plugin when I use with $$ and ones like this: \begin{equation} x^2 \end{equation}

Note the single $ do not work: $x^2$

But... I tried to roll over to this repo since it is recommended to do so.

updated pelicanconf.py to use the dash version:

PLUGIN_PATHS = ['plugins']
PLUGINS = ['render-math']

Now, with no other changes I get:

   ERROR    Cannot register plugin `render-math`               log.py:94
                   module 'render-math' has no attribute 'register'

Any suggestions?

justinmayer commented 9 months ago

Hi John. I’m going to respond here, and once we resolve your issue, I’m going to post the resolution to your Stack Overflow question and ask you to mark it as answered.

As mentioned in the docs related to Pelican Plugins, the canonical method for installing namespace plugins such as this one is to install them via Pip:

python -m pip install pelican-render-math

Next, comment out your PLUGIN_PATHS and PLUGINS settings in your Pelican settings file. Those settings are not necessary unless (1) you need to selectively disable certain namespace plugins, or (2) you are mixing namespace + legacy plugins in the same project.

You can then see which plugins have been successfully registered via:

pelican-plugins

… which should display:

Plugins found:
pelican.plugins.render_math

If (and only if) you need to explicitly specify plugins for one of the two aforementioned reasons, you must use the plugin name as displayed above — that is, with an underscore and not a dash:

PLUGIN_PATHS = ['plugins']
PLUGINS = ['render_math']

Does the above give you the information you need to resolve this issue?

(In the future, please don’t cross-post to both GitHub and Stack Overflow, as it creates unnecessary noise for maintainers. Thanks for your cooperation.)

cppgent0 commented 9 months ago

please don’t cross-post to both GitHub and Stack Overflow,

Understood. I didn't do that on purpose. I posted to stack overflow first and then saw the note that I should post here.

ask you to mark it as answered. will do.

Here's what I did:

deleted the plugin settings

# PLUGIN_PATHS = ['plugins']
# PLUGINS = ['render-math']

deleted the plugins directory (I currently don't use any other plugins) rm -rf plugins

Added pip for render-math python3 -m pip install "pelican-render-math"

confirmed render_math was installed:

Successfully installed pelican-render-math-1.0.3 smartypants-2.0.1 typogrify-2.0.7
[14:00:07] INFO     Plugins found:                                                                                                                                              _utils.py:38
                    pelican.plugins.render_math

restarted pelican service

refreshed the page, both $$ and $ work okay, \begin{equation} x^2 \end{equation} worked okay too.

refreshed the page, stopped working, get plain text

refreshed the page, it works okay again.

If I'm not mistaken, it could be related this setting? I use it for dev/debug convenience: LOAD_CONTENT_CACHE = False

cppgent0 commented 9 months ago

Okay. The page then went into an infinite loop. Chrome was running at 100% CPU. I killed the tab/page. Went back to the site from another tab. And it works. Refreshed it many times. And it works each time.

Wait...

I navigated from here back to that tab. And it failed. refreshed it a few times. It worked quite a few times and then it failed. refreshed it a few more times. It failed each time and then it worked. Going from tab to tab seems to fix it but not 100% sure about that.

justinmayer commented 9 months ago

I'm not sure what you mean by "Pelican service" (perhaps you mean pelican -r?), but when troubleshooting I recommend generating your site without any regeneration or automation wrappers. In other words, if you generate your site via plain commands like pelican -s pelicanconf.py content, do you get the expected result in the output every time?

cppgent0 commented 9 months ago

"Pelican service" I use a Linux (Ubuntu 22.04) server instance running in a VirtualBox VM. Inside of that I run Pelican as a Linux service kicked off by systemctl start pelican.service where pelican.service is a typical linux service file. And I kick off nginx to run a proxy that communicates with that service.

Inside the service I run pelican via a bash script:

# --autoreload: watch for mods
# --listen    : starts the pelican server
pelican --autoreload --listen

The reason I do this, is that when my site is ready to roll out, I can buy a VM on a provider and run all of this exactly the same way it is running on my local machine with VBox.

To confirm all of if it working correctly, I have reset the VBX to a clean, initial installation of Ubuntu Server 22.04 and reinstalled and restarted the website repeatedly. That works.

plain commands like pelican -s pelicanconf.py content No, not yet. I'm changing things so often that the --autoreload makes more sense right now.

But just in case, I tried that command now.

pelican -s pelicanconf.py content
Done: Processed 87 articles, 0 drafts, 0 hidden articles, 0 pages, 0 hidden pages and 0 draft pages in 2.34 seconds.

And it still fails like before.

As a double-check, I added that line to the service so it gets run just before start pelican and I removed --autoreload

pelican -s pelicanconf.py content
pelican --listen

and then bounced the linux service.

And it still fails like before.

justinmayer commented 9 months ago

Perhaps run with --debug, copy and paste the output to a paste-bin snippet (e.g., https://dpaste.org), and post a link to that snippet here?

cppgent0 commented 9 months ago

changed the line to:

pelican --listen --debug bounced the service

See https://dpaste.org/SNLra

Note that the output is from this command showing all three files tail -f /var/log/nginx/error.log -f /var/log/nginx/access.log -f /var/log/syslog

192.168.1.209 is the local ip address of the VBox VM test-me is the markdown page with the math samples I'm trying do_host_pelican is the bash script that runs pelican pelican_twitchy is the theme I'm using

I refreshed the Chrome page and it failed to render. I refreshed it again and the tab went into an infinite loop. I had to kill the tab and restart it. I checked the VM CPU usage with top and it wasn't spinning. So it seems the infinite loop is maybe in Chrome? I repeated that a couple of times and in the final run it rendered correctly.

cppgent0 commented 9 months ago

I think I found it.

I opened the inspect tab in Chrome. The console had this in it:

19:58:50.706 MathJax.js?config=TeX-AMS-MML_HTMLorMML:32 WARNING: cdn.mathjax.org has been retired. Check https://www.mathjax.org/cdn-shutting-down/ for migration tips.
replaceScript @ MathJax.js?config=TeX-AMS-MML_HTMLorMML:32

This is due to a line I put into base.html:

<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script> I added it based on a post in stackoverflow. It must have been an outdated one.

In any case, I commented the line out. Restarted pelican. And hit refresh on that page many times (20? 30?). No failures!

I’m going to post the resolution to your Stack Overflow question and ask you to mark it as answered.

Go for it Justin, I'll mark as answered.

(Apologies for the side track here)

justinmayer commented 8 months ago

In the end, I'm not sure how to quickly summarize everything in this issue into a good Stack Overflow answer, so I'm going to leave that be. I'm glad we were able to resolve the problem. 😊