Skip to content

Instantly share code, notes, and snippets.

@chrischoy
Last active August 13, 2023 21:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save chrischoy/d3cc31de0e2b79d476cbd87e2d24453f to your computer and use it in GitHub Desktop.
Save chrischoy/d3cc31de0e2b79d476cbd87e2d24453f to your computer and use it in GitHub Desktop.
Markdown Tips

Rendering latex Eqs in Markdown

  • Github doesn't allow javascript in a markdown file. Try to compile equations using readme2tex presents an elegant solution for rendering latex equations.

  • grip runs a simple http server to visualize a readme file on a browser. It also tracks changes in a readme file and refresh the page whenever there is a change. However, you need to embed the following script so that the Mathjax renders eqs.

    <script async src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_CHTML"></script>
    <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" onload="javascript:MathJax.Hub.Queue(['Typeset', MathJax.Hub]);">

    If grip is not rendering it correctly, try running it with the following script by @joeyespo

    # gripjax.py
    import sys
    from grip import GitHubRenderer, Grip
    
    MATHJAX_SCRIPT = """
    <script type="text/x-mathjax-config">
    MathJax.Hub.Config({
      tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}
    });
    </script>
    <script async src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_CHTML"></script>
    """
    
    class MathJaxRenderer(GitHubRenderer):
        def patch(self, html):
            return super(MathJaxRenderer, self).patch(html) + MATHJAX_SCRIPT
    
    Grip(source=sys.argv[1], renderer=MathJaxRenderer()).run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment