# *manual* refresh needed when using mathjax from script

#### jaromir.benes

26 Feb, 2021 09:29 AM

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

1. Posted by jaromir.benes on 26 Feb, 2021 09:33 AM

2. Support Staff 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

-Brett

3. Posted by jaromir.benes on 26 Feb, 2021 12:19 PM

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

4. Support Staff 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

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

### »

• test.md 378 Bytes

#### Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

# Keyboard shortcuts

### Generic

? Show this help Blurs the current field

### Comment Form

r Focus the comment reply box Submit the comment

You can use Command ⌘ instead of Control ^ on Mac

## Recent Discussions

 15 Apr, 2021 11:43 PM Allow MARKED_ORIGIN, etc., variable substitution in customprocessor arguments 15 Apr, 2021 08:09 PM Images rendering.... 15 Apr, 2021 01:29 PM Marked crashes when launching from a terminal 14 Apr, 2021 02:43 PM Change citation style 13 Apr, 2021 03:39 PM Section collpse not working after upgrade

## Recent Articles

 Intra-document links in exported PDFs Using Ulysses with Marked Fenced code blocks inside indented code blocks Using JavaScript in Marked Custom CSS: Writing custom CSS for Marked