question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Include MathJax only if there are formulas on the page

See original GitHub issue

I want to suggest an idea and checked that …

  • … to my best knowledge, my idea wouldn’t break something for other users
  • … the documentation does not mention anything about my idea
  • … there are no open or closed issues that are related to my idea

Description

MkDocs includes tex-mml-chtml.js into every page which is an additional ~752Kb transfer. Serving the MathJax-specific JS only if rendered page contains $...$ blocks will save close to the megabyte per page.

Use Cases

Any case where serving additional traffic is undesirable. Which is… Every case?

Screenshots / Mockups

N/A

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
savchenkocommented, Feb 20, 2021

@facelessuser , Works like a charm, thank you!

@squidfunk ,

we have an automatic integration for Mermaid in place (#2170), but not for MathJax. Maybe worth considering.

Solution from Isaac works well, however having this happening automatically is easier / less confusing for an end-user. Depends on the complexity of implementation I reckon; certainly your call.

1reaction
facelessusercommented, Feb 19, 2021

Ah, the problem is that you are including it in extra_javascript , which will include it on every page. I actually include it at the end of the page that I want to have MathJax. I do this via the Snippets extension: https://facelessuser.github.io/pymdown-extensions/extensions/snippets/.

  1. I point Snippets to my _snippets folder: https://github.com/facelessuser/pymdown-extensions/blob/master/mkdocs.yml#L131

  2. And then I place this at the bottom of the page I want to use MathJax:

    ---8<---
    mathjax.txt
    ---8<---
    

You can see that mathjax.txt contains my config and the MathJax lib: https://github.com/facelessuser/pymdown-extensions/blob/master/docs/src/markdown/_snippets/mathjax.txt

Read more comments on GitHub >

github_iconTop Results From Across the Web

MathJax Frequently Asked Questions
MathJax loads components only when needed so there is a big difference between what is loaded on a page without mathematics and one...
Read more >
MathJax Frequently Asked Questions
Will MathJax make my page load slower even if there's no math?¶. It depends on how you have configured and loaded MathJax. The...
Read more >
Loading and Configuring MathJax
It is best to load MathJax in the document's <head> block, but it is also possible to load MathJax into the <body> section,...
Read more >
Modifying Math on the Page — MathJax 1.0 documentation
To do that, you need to use the MathJax.Hub.Typeset() method. This will cause the preprocessors (if any were loaded) to run over the...
Read more >
What is MathJax? — MathJax 3.2 documentation
MathJax allows page authors to write formulas using TeX and LaTeX notation, MathML (a World Wide Web Consortium standard for representing mathematics in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found