Module: Softcover::Mathjax

Defined in:
lib/softcover/mathjax.rb

Constant Summary collapse

MATHJAX =
'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/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
50
# 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?
                       '#{chapter_number}'
                   else  # chapter_number is false, i.e., it's a single page
                     false
                   end
  fn = if chapter_number
         "formatNumber: function (n) { return #{chapter_number} + '.' + n }"
       else
         ""
       end

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

.custom_macrosObject

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



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

def self.custom_macros
  extract_macros(Softcover.custom_styles)
end

.escaped_config(options = {}) ⇒ Object

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.



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

def self.escaped_config(options={})
  self.config(options).gsub('\\', '\\\\\\\\')
end