Module: ToAsciiLatex

Defined in:
lib/to_ascii_latex.rb,
lib/to_ascii_latex/version.rb

Constant Summary collapse

MAPPING =
{ "\u2014"  => "--",
  "\u2018"  => "`",
  "\u2019"  => "'",
  "\u201E"  => "``",
  "\u201C"  => "``",
  "\u201D"  => "''",
  "\u00A0"  => ' ',
  "\u00E6"  => '\ae{}',
  "\u00E0"  => '\\\\`{a}',
  "\u0097"  => '--',
  "\u0092"  => "'",
  "\u2026"  => '{}\ldots{}',
  "\uFB01"  => 'fi',
  "\u2013"  => '-',
  "\u25A0"  => '\ensuremath{\blacksquare}',
  "\u2022"  => '\ensuremath{\bullet}',
  "\u2248"  => '\ensuremath{\approx}',
  "\u0B0C"  => '?',
  "\u00B0"  => '\ensuremath{^{\ccirc}}',
  "\u00A7"  => '\S{}',
  "\u20AC"  => '\euro{}',
  "\u00A2"  => '\textcent{}'
}
MAPPING_RE =
/#{MAPPING.keys.join('|')}/
VERSION =
"0.0.14"
@@smartquotes =
false

Class Method Summary collapse

Class Method Details

.extended(base) ⇒ Object

Add a hook - whenever a class or module calls ‘extend ToAsciiLatex`, run this code



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/to_ascii_latex.rb', line 44

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)
      x = old_escape(s).gsub(MAPPING_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

.smartquotesObject



7
8
9
# File 'lib/to_ascii_latex.rb', line 7

def self.smartquotes
  @@smartquotes
end

.smartquotes=(v) ⇒ Object



11
12
13
14
# File 'lib/to_ascii_latex.rb', line 11

def self.smartquotes=(v)
  raise "Unexpected value #{v.inspect} for smartquotes" unless [true, false].include?(v)
  @@smartquotes = v
end