module ToAsciiLatex
Constants
- MAPPING
- NBSP
www.fileformat.info/info/unicode/char/fb01/index.htm www.w3.org/Math/characters/unicode.xml www.johndcook.com/unicode_latex.html
- RE
- RE_SPECIALS
- VERSION
Public Class Methods
escape(s)
If we call `escape`, now we'll get our `new_escape` method
Also aliased as: old_escape
Alias for: new_escape
extended(base)
click to toggle source
Add a hook - whenever a class or module calls `extend ToAsciiLatex`, run this code
# File lib/to_ascii_latex.rb, line 59 def self.extended(base) # In the context of the extending module or class # (in this case, it will be ToLatex), do the following base.class_eval do # Define this new method def self.new_escape(s) s = s.gsub(NBSP, ' ') if @@replace_nbsp x = s.gsub(RE){|c| MAPPING[c]} # .gsub('\backslash{}', '\ensuremath{\backslash}') warn "Unicode in #{x.inspect}" if x.delete("^\u{0000}-\u{007F}") != x if @@smartquotes i = 0 x.gsub!('"'){|q| i += 1; (i % 2 == 0) ? "''" : "``"} end return x end # Set up aliases. # We're already in the context of the class, but there's no # `self.alias`, so we need to call `alias` inside this block class << self # We can call the original `escape` method with `old_escape` alias :old_escape :escape # If we call `escape`, now we'll get our `new_escape` method alias :escape :new_escape end end end
new_escape(s)
click to toggle source
Define this new method
# File lib/to_ascii_latex.rb, line 66 def self.new_escape(s) s = s.gsub(NBSP, ' ') if @@replace_nbsp x = s.gsub(RE){|c| MAPPING[c]} # .gsub('\backslash{}', '\ensuremath{\backslash}') warn "Unicode in #{x.inspect}" if x.delete("^\u{0000}-\u{007F}") != x if @@smartquotes i = 0 x.gsub!('"'){|q| i += 1; (i % 2 == 0) ? "''" : "``"} end return x end
Also aliased as: escape
replace_nbsp()
click to toggle source
# File lib/to_ascii_latex.rb, line 16 def self.replace_nbsp @@replace_nbsp end
replace_nbsp=(v)
click to toggle source
# File lib/to_ascii_latex.rb, line 19 def self.replace_nbsp=(v) raise "Unexpected value #{v.inspect} for replace_nbsp" unless [true, false].include?(v) @@replace_nbsp = v end
smartquotes()
click to toggle source
# File lib/to_ascii_latex.rb, line 9 def self.smartquotes @@smartquotes end
smartquotes=(v)
click to toggle source
# File lib/to_ascii_latex.rb, line 12 def self.smartquotes=(v) raise "Unexpected value #{v.inspect} for smartquotes" unless [true, false].include?(v) @@smartquotes = v end