Sha256: 313284f51ae5a5b53c95dd3efaaa15d3819fa9e951be9607ca5d760bebdfd953
Contents?: true
Size: 1.05 KB
Versions: 4
Compression:
Stored size: 1.05 KB
Contents
class String # These are TeX's special characters LATEX_ADD_SLASH = [ '{', '}', '$', '&', '#', '_', '%'].map{|x|x[0]} # These, we transform to {\tt \char<ascii code>} LATEX_TO_CHARCODE = [ '^', '~', '>','<'].map{|x|x[0]} def int_to_string(char) tmp = "0"; tmp[0]=char; tmp; end def escape_to_latex(s) s2 = "" s.each_byte do |b| if LATEX_TO_CHARCODE.include? b s2 += "{\\tt \\char#{b}}" elsif LATEX_ADD_SLASH.include? b s2 += "\\" s2 += int_to_string(b) elsif b == "\\"[0] # there is no backslash in cmr10 fonts s2 += "$\\backslash$" else s2 += int_to_string(b) end end s2 end # escapes special characters def to_latex s = self s = escape_to_latex(s) # puts "Before: #{s.inspect}" # puts "after: #{s.inspect}" OtherGoodies.each do |k, v| s.gsub!(k, v) end s end # other things that are good on the eyes OtherGoodies = { /(\s)LaTeX/ => '\1\\LaTeX\\xspace ', # XXX not if already \latex # 'HTML' => '\\textsc{html}\\xspace ', # 'PDF' => '\\textsc{pdf}\\xspace ' } end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
maruku-0.2.12 | lib/maruku/to_latex_strings.rb |
maruku-0.2.11 | lib/maruku/to_latex_strings.rb |
maruku-0.2.13 | lib/maruku/to_latex_strings.rb |
maruku-0.3.0 | lib/maruku/to_latex_strings.rb |