*manual* refresh needed when using mathjax from script
Hi
Because I need to use the newer mathjax (v3), I do the following
* disable Mathjax in the Style pane in Preferences
* put the necessary <script> machinery at the top of the file (in fact, I have a little preprocessor to do that but that's irrelevant here as the issue remains exactly the same)
Everything works like a charm except that the preview does not automatically render math after the source file gets modified/updated and saved. The underlying math source code is displayed in the preview instead of the rendered equations. To get the equations rendered, I have to manually move to the preview window and press Cmd-R. I also tried to use x-marked://refresh (which would be an easy workaround for me, working off vim) but to no avail - it does not render the equations either and a manual Cmd-R refresh is really needed.
Any thoughts?
I'm on macOS Big Sur 11.1, Marked2 2.6.4 (1014).
Attaching a little test.md file for you to see the <script> setup, a screenshot of the preview before it gets manually refreshed, and afterwards.
Best
Jaromir
- test.md 378 Bytes
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac
1 Posted by jaromir.benes on 26 Feb, 2021 09:33 AM
...the screenshots here...
Support Staff 2 Posted by Brett on 26 Feb, 2021 11:18 AM
Unfortunately this is expected behavior. The last major update to Marked
switched its preview to use DOM injection rather than a full reload when
updating, and that doesn't re-trigger MathJax's rendering. The built-in
MathJax compensates for this by calling the MathJax typeset method on
every update, but there's no hook currently available for refreshing
external scripts the same way. (Though if I could find an elegant way to
do that, I'd take it under consideration.)
`x-marked://refresh` really should work the same as ⌘R, though, and
you could have an x-success param that returned focus to your editor. If
that's a workable solution for you, I'm happy to look into why that
wouldn't be performing a full refresh. Might have broken something over
the last few updates.
-Brett
3 Posted by jaromir.benes on 26 Feb, 2021 12:19 PM
Many thanks, Brett, for your prompt reply!
I double checked the behavior of x-marked://refresh and it, indeed, does not render the math - however, x-success does trigger the url. Worse still, if I run it on an existing, unchanged, correctly rendered preview, it actually reverts all math to its underlying source code...
And yes, I'd be more than grateful to you for looking into this. Getting this fixed would save me a lot of pain switching back and forth :)
Many thanks for all your work on Marked2.
Best
Jaromir
Support Staff 4 Posted by Brett on 26 Feb, 2021 12:50 PM
I'll try to have the refresh handler working for the next update.
I also took some time to think about it and it makes sense to me to have
a queue available through the JS API that lets you add functions to run
on update. Something like `Marked.queue.push(function(){
MathJax.Typeset(...) }`. Then you could just add a couple lines to any
script and have it refresh when Marked does without requiring a full
reload. Don't know if you're a javascript person at all, but I'd be open
to ideas on that front if you are. Even if you're not, I think I could
make it easy enough that anyone could implement with some handy
instructions...
-Brett
5 Posted by jaromir.benes on 26 Feb, 2021 02:24 PM
Thanks. I'm more of a matlab/python/julia person with just the bare minimum
skills in js so I guess am of no help to you on this :) But a queue of
user functions triggered on update looks like a simple elegant solution.
Look forward,
Jaromir
6 Posted by Patrick Walsh on 29 Mar, 2023 11:11 PM
Would love to bump this up. Something like a
Marked.onupdate.push(function() { /* do the things */ });
would be very useful for handling Mermaid diagrams and also for updates to slides using marp. Both of those do Bad Things after an update and I have to cmd-tab to Marked and cmd-r after each save, which is a bummer. If something like this has already been added, please do share! I didn't find anything in the knowledgebase or the docs.Support Staff 7 Posted by Brett on 29 Mar, 2023 11:50 PM
https://marked2app.com/help/Embedding_Scripts.html
- Brett
8 Posted by Patrick Walsh on 30 Mar, 2023 02:48 PM
Sorry I failed to find that even after searching via google and site! Great to see!