Skip to content

Commit

Permalink
Attempt to use codecogs for Latex in RSS
Browse files Browse the repository at this point in the history
Refs #50
  • Loading branch information
fdavidcl committed Mar 5, 2016
1 parent 4fcf45e commit e7a755e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
27 changes: 27 additions & 0 deletions _plugins/codecogs.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Title: codecogs plugin
# Author: Carl Boettiger, @cboettig
# License: MIT
#
# A simple filter to replace mathjax-latex syntax with images of the
# equations as rendered by codecogs. This is useful to filter content
# entered into the atom feed, where javascript and css-based rendering
# of equations won't work.

# Credits to Noam Ross http://www.noamross.net/blog/2012/4/4/math-in-rss-feeds.html for inspiring this approach and to
# helpful folks on SO for the regexpr: http://stackoverflow.com/questions/13166112/ruby-regexp-to-replace-equations

# Example use:
#
# {{ post.content | codecogs }}
#

module Jekyll
module ImageFilter
def codecogs(input)
# puts "generating images for equations in RSS feed with codecogs.rb"
desired = input.gsub(/\\\[\s*(.*?)\s*\\\]/, "<div style=\"text-align:center;\"><img src=\"http://latex.codecogs.com/png.latex?\\1\" alt=\"\\1\" /></div>")
desired.gsub(/\\\(\s*(.*?)\s*\\\)/, "<img src=\"http://latex.codecogs.com/png.latex?\\1\\inline\"/>")
end
end
end
Liquid::Template.register_filter(Jekyll::ImageFilter)
6 changes: 3 additions & 3 deletions feed.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ layout: null
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>{{ site.name | xml_escape }}</title>
<description>{% if site.description %}{{ site.description | xml_escape }}{% endif %}</description>
<description>{% if site.description %}{{ site.description | xml_escape }}{% endif %}</description>
<link>{{ site.url }}</link>
<atom:link href="{{ site.url }}/feed.xml" rel="self" type="application/rss+xml" />
{% for post in site.posts limit:10 %}
<item>
<title>{{ post.title | xml_escape }}</title>
<description>{{ post.content | xml_escape }}</description>
<description>{{ post.content | codecogs | xml_escape }}</description>
<pubDate>{{ post.date | date: "%a, %d %b %Y %H:%M:%S %z" }}</pubDate>
<link>{{ site.url }}{{ post.url }}</link>
<guid isPermaLink="true">{{ site.url }}{{ post.url }}</guid>
</item>
{% endfor %}
</channel>
</rss>
</rss>

0 comments on commit e7a755e

Please sign in to comment.