File tree Expand file tree Collapse file tree 2 files changed +61
-0
lines changed Expand file tree Collapse file tree 2 files changed +61
-0
lines changed Original file line number Diff line number Diff line change 1+ # Author: Trevor Bedford
2+ # License: MIT
3+
4+ module Jekyll
5+ class Eq < Liquid ::Tag
6+ def initialize ( tag_name , markup , tokens )
7+ super
8+ @markup = "#{ markup } " . strip
9+ end
10+ def render ( context )
11+
12+ require 'execjs'
13+
14+ parsed = Liquid ::Template . parse ( @markup ) . render context
15+
16+ katexsrc = open ( "./js/katex.min.js" ) . read
17+ @katex = ExecJS . compile ( katexsrc )
18+
19+ style = "text-align: center; margin-top: 0.5em; margin-bottom: 0.5em;"
20+ div_open = "<div style='#{ style } '>"
21+ parsed = "\\ displaystyle " + parsed
22+ div_close = "</div>"
23+ output = div_open + eqn_to_html ( parsed ) + div_close
24+
25+ return output
26+
27+ end
28+ def eqn_to_html ( string )
29+ return @katex . call ( "katex.renderToString" , string , { displayMode : true } )
30+ end
31+ end
32+ end
33+
34+ Liquid ::Template . register_tag ( 'eq' , Jekyll ::Eq )
Original file line number Diff line number Diff line change 1+ # Author: Trevor Bedford
2+ # License: MIT
3+
4+ module Jekyll
5+ class EqInline < Liquid ::Tag
6+ def initialize ( tag_name , markup , tokens )
7+ super
8+ @markup = "#{ markup } " . strip
9+ end
10+ def render ( context )
11+
12+ require 'execjs'
13+
14+ parsed = Liquid ::Template . parse ( @markup ) . render context
15+
16+ katexsrc = open ( "./js/katex.min.js" ) . read
17+ @katex = ExecJS . compile ( katexsrc )
18+ return eqn_to_html ( parsed )
19+
20+ end
21+ def eqn_to_html ( string )
22+ return @katex . call ( "katex.renderToString" , string )
23+ end
24+ end
25+ end
26+
27+ Liquid ::Template . register_tag ( 'eqinline' , Jekyll ::EqInline )
You can’t perform that action at this time.
0 commit comments