Class: Jekyll::Tags::LatexBlock

Inherits:
Liquid::Block
  • Object
show all
Defined in:
lib/jekyll/tags/latex_block.rb

Overview

LaTeX tag, HTML rendering via KaTeX

Instance Method Summary collapse

Constructor Details

#initialize(tag_name, markup, options) ⇒ LatexBlock

Returns a new instance of LatexBlock.



10
11
12
13
# File 'lib/jekyll/tags/latex_block.rb', line 10

def initialize(tag_name, markup, options)
  @parsed_options = Liquid::Tag::Parser.new(markup).args
  super
end

Instance Method Details

#katex_jsObject



15
16
17
18
19
# File 'lib/jekyll/tags/latex_block.rb', line 15

def katex_js
  # rubocop:disable Style/ClassVars
  @@katex ||= ExecJS.compile(File.read(katex_path))
  # rubocop:enable Style/ClassVars
end

#katex_pathObject



21
22
23
# File 'lib/jekyll/tags/latex_block.rb', line 21

def katex_path
  File.expand_path('../../js/katex.js', File.dirname(__FILE__))
end

#render(context) ⇒ Object



25
26
27
28
# File 'lib/jekyll/tags/latex_block.rb', line 25

def render(context)
  latex_source = super
  katex_js.call('katex.renderToString', latex_source, @parsed_options)
end