Skip to content

Instantly share code, notes, and snippets.

  • Star 25 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save jessykate/834610 to your computer and use it in GitHub Desktop.
A simple liquid tag for Jekyll/Octopress that converts {% m %} and {% em %} into inline math, and {% math %} and {% endmath %} into block equations, by replacing with the appropriate MathJax script tags.
module Jekyll
class MathJaxBlockTag < Liquid::Tag
def render(context)
'<script type="math/tex; mode=display">'
end
end
class MathJaxInlineTag < Liquid::Tag
def render(context)
'<script type="math/tex">'
end
end
class MathJaxEndTag < Liquid::Tag
def render(context)
'</script>'
end
end
end
Liquid::Template.register_tag('math', Jekyll::MathJaxBlockTag)
Liquid::Template.register_tag('m', Jekyll::MathJaxInlineTag)
Liquid::Template.register_tag('endmath', Jekyll::MathJaxEndTag)
Liquid::Template.register_tag('em', Jekyll::MathJaxEndTag)
@MySchizoBuddy
Copy link

Can you create a gist for mathjax that adds equation numbers, like 1.1, 1.2 for chapter 1 and 2.1, 2.2 for chapter 2 etc.

@bdesham
Copy link

bdesham commented Dec 10, 2011

This is way useful, thanks!

Copy link

ghost commented Feb 29, 2012

Seems a problem: when '&' is used in block equations, it would cause a render error, as '&' is an illegal character in raw string.

Copy link

ghost commented Mar 10, 2016

Jekyll's default Markdown renderer has built in mathjax support: http://kramdown.gettalong.org/math_engine/mathjax.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment