Module: Softcover::Mathjax

Defined in:
lib/softcover/mathjax.rb

Constant Summary collapse

MATHJAX =
'MathJax/MathJax.js?config='
AMS_HTML =
'/' + MATHJAX + 'TeX-AMS_HTML'
AMS_SVG =
MATHJAX + 'TeX-AMS-MML_SVG'

Class Method Summary collapse

Class Method Details

.config(options = {}) ⇒ Object

Returns the MathJax configuration.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/softcover/mathjax.rb', line 5

def self.config(options = {})
  chapter_number = if options[:chapter_number]
                     if (options[:chapter_number].zero? ||
                         Softcover::Utils.article?)
                         false
                       else
                         # Call .inspect.inspect to escape the chapter
                         # number code for interpolation.
                         options[:chapter_number].inspect.inspect
                       end
                     elsif options[:chapter_number].nil?
                      false
                   else  # chapter_number is false, i.e., it's a single page
                     false
                   end
  fn = if chapter_number
         "formatNumber: function (n) { return #{chapter_number} + '.adfadsfa  ' + n }"
       else
         ""
       end

  config = <<-EOS
  MathJax.Hub.Config({
    "HTML-CSS": {
      availableFonts: ["TeX"],
    },
    TeX: {
      extensions: ["AMSmath.js", "AMSsymbols.js"],
      equationNumbers: {
        autoNumber: "AMS",
        #{fn}
      },
      Macros: {
        PolyTeX:    "Poly{\\\\TeX}",
        PolyTeXnic: "Poly{\\\\TeX}nic",
        #{custom_macros}
      }
    },
    showProcessingMessages: false,
    messageStyle: "none",
    imageFont: null
  });
  EOS
  config
end

.custom_macrosObject

Returns the custom macros as defined in the custom style file.



63
64
65
# File 'lib/softcover/mathjax.rb', line 63

def self.custom_macros
  extract_macros(Softcover.custom_styles)
end

.escaped_configObject

Rerturns a version of the MathJax configuration escaped for the server. There’s an extra interpolation somewhere between here and the server, which this method corrects for.



54
55
56
# File 'lib/softcover/mathjax.rb', line 54

def self.escaped_config
  self.config.gsub('\\', '\\\\\\\\')
end