Created
October 27, 2013 15:04
-
-
Save preshing/7183310 to your computer and use it in GitHub Desktop.
MathJax tags for Octopress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#-------------------------------------------------------------- | |
# MathJax tags for Octopress | |
# | |
# Put this in the plugins folder. | |
# Use a single "inlinemath" tag for inline math. | |
# Use a pair of "math/endmath" tags for math as a standalone paragraph. | |
# The "math" tag takes an optional size argument. | |
# You also need to include MathJax in the page header, for example by adding | |
# <script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script> | |
# to source/_includes/custom/head.html | |
# | |
# Examples: | |
# | |
# ... our approximation takes the form {% inlinemath 1 - e^{-X} %}, because ... | |
# | |
# {% math %} | |
# \frac{N-1}{N}\times\frac{N-2}{N}\times\dots\times\frac{N-(k-2)}{N}\times\frac{N-(k-1)}{N} | |
# {% endmath %} | |
# | |
# {% math 170% %} | |
# e^{\frac{-k(k-1)}{2N}} | |
# {% endmath %} | |
#-------------------------------------------------------------- | |
module Jekyll | |
class MathBlock < Liquid::Block | |
def initialize(tag_name, params, tokens) | |
super | |
@size = params.strip | |
end | |
def render(context) | |
if @size == '' | |
"$$ #{super} $$" | |
else | |
"<div style=\"font-size:#{@size};\">$$ #{super} $$</div>" | |
end | |
end | |
end | |
class InlineMathTag < Liquid::Tag | |
def initialize(tag_name, params, tokens) | |
super | |
@text = params | |
end | |
def render(context) | |
"\\\\(#{@text}\\\\)" | |
end | |
end | |
end | |
Liquid::Template.register_tag('math', Jekyll::MathBlock) | |
Liquid::Template.register_tag('inlinemath', Jekyll::InlineMathTag) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment