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.

  • Download Gist
Jekyll nd Octopress Liquid tag for MathJax.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
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)

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.

This is way useful, thanks!

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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.