lib/softcover/mathjax.rb in softcover-1.0.beta16 vs lib/softcover/mathjax.rb in softcover-1.0.beta17
- old
+ new
@@ -51,34 +51,33 @@
MATHJAX = 'MathJax/MathJax.js?config='
AMS_HTML = '/' + MATHJAX + 'TeX-AMS_HTML'
AMS_SVG = MATHJAX + 'TeX-AMS-MML_SVG'
+ # Returns the custom macros as defined in the custom style file.
+ def self.custom_macros
+ extract_macros(Softcover.custom_styles)
+ end
private
- # Returns the custom macros as defined in the custom style file.
- def self.custom_macros
- extract_macros(Softcover.custom_styles)
- end
-
# Extracts and formats the macros from the given string of style commands.
# The output format is compatible with the macro configuration described
# at http://docs.mathjax.org/en/latest/tex.html.
def self.extract_macros(styles)
# For some reason, \ensuremath doesn't work in MathJax, so remove it.
styles.gsub!('\ensuremath', '')
# First extract commands with no arguments.
cmd_no_args = /^\s*\\newcommand\{\\(.*?)\}\{(.*)\}/
cna = styles.scan(cmd_no_args).map do |name, definition|
escaped_definition = definition.gsub('\\', '\\\\\\\\')
- %(#{name}: "#{escaped_definition}")
+ %("#{name}": "#{escaped_definition}")
end
# Then grab the commands with arguments.
cmd_with_args = /^\s*\\newcommand\{\\(.*?)\}\[(\d+)\]\{(.*)\}/
cwa = styles.scan(cmd_with_args).map do |name, number, definition|
escaped_definition = definition.gsub('\\', '\\\\\\\\')
- %(#{name}: ["#{escaped_definition}", #{number}])
+ %("#{name}": ["#{escaped_definition}", #{number}])
end
(cna + cwa).join(",\n")
end
end
end