Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: math #208

Closed
krey opened this issue Aug 29, 2016 · 9 comments

Comments

@krey
Copy link

commented Aug 29, 2016

While GitHub does not support the insertion of latex into markdown, it would be a very useful feature for grip.
In-browser this can be using MathJax

@JasonYao

This comment has been minimized.

Copy link

commented Sep 15, 2016

Why bother if the README file is to be displayed on github anyways? This sounds like it should be a feature request for github's README renderer, not for grip.

@krey

This comment has been minimized.

Copy link
Author

commented Sep 15, 2016

@JasonYao: I wasn't talking about README files, I'm thinking of .md files in general

@JasonYao

This comment has been minimized.

Copy link

commented Sep 15, 2016

Right, I'm saying that if the github .md renderer doesn't render latex code, why would grip want to render it?

The main purpose of grip is to preview .md files and see how they'd look on github, if grip adds this and starts diverging from what github displays, then it defeats the purpose of grip in the first place.

@krey

This comment has been minimized.

Copy link
Author

commented Sep 15, 2016

@JasonYao: yeah, I guess it depends on what people wanna use this for. I've found that grip is one of the best markdown renderers out there and would like to use it as such.

If you're worried about divergence from github, make the LaTeX feature opt-in

@joeyespo

This comment has been minimized.

Copy link
Owner

commented Dec 2, 2016

@krey Thanks for the kind words 😄

If you want to use Grip more generally, may I suggest using the Python API to inject the custom pieces you need? Something like:

# gripjax.py

from grip import GitHubRenderer, Grip

MATHJAX_SCRIPT = """
<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]);">
"""

class MathJaxRenderer(GitHubRenderer):
    def patch(self, html):
        return super(MathJaxRenderer, self).patch(html) + MATHJAX_SCRIPT

Grip(renderer=MathJaxRenderer()).run()

Then run gripjax.py instead of grip.

Note that this is a bit of a hack. Namely, using patch instead of some dedicated scripts option. And the <img> trick so that the MathJax.Hub.Queue code will run on each auto-reload. (See this and this and this.)

I'm considering adding a way to more easily inject styles and scripts using the API or even globally with configuration. Until then, this should work for you. However, I don't plan to hardcode MathJax or any other custom library into this repo.

Hope this helps!

@joeyespo joeyespo closed this Dec 2, 2016

@ludaavics

This comment has been minimized.

Copy link

commented Mar 7, 2017

@joeyespo Thanks for this!
FWIW, I am in the same boat as @krey and use grip as my go to renderer and this worked like a charm. I would definitely use a "clean" way of adding MathJax support!

@drorata

This comment has been minimized.

Copy link

commented Jun 23, 2017

I'll just put it here: github/markup#897

@ludaavics

This comment has been minimized.

Copy link

commented Mar 9, 2018

@joeyespo it looks like f17a68a broke this quick fix.
Have you given more thoughts on allowing to inject custom scripts? I see there is now an option for styles, but doesn't look like there is one for scripts -- let me know if missing something.

This is out of my wheelhouse, but happy to work on it to the extent that I can help

@ztlevi

This comment has been minimized.

Copy link

commented May 29, 2019

It looks like github now support math equations. How can we achieve with grip?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants
You can’t perform that action at this time.