Module: TexOutput

Included in:
AutoQCMRenderer
Defined in:
lib/ruql/tex_output.rb

Constant Summary collapse

@@tex_replace =
{
  /_/ => '\textunderscore{}',
  Regexp.new('<tt>([^<]+)</tt>', Regexp::IGNORECASE) => "\\texttt{\\1}",
  Regexp.new('<pre>(.*?)</pre>', Regexp::MULTILINE | Regexp::IGNORECASE) => "\\texttt{\\1}",
}
@@tex_escape =
Regexp.new '\$|&|%|#|\{|\}'

Instance Method Summary collapse

Instance Method Details

#add_newlines(str) ⇒ Object



3
4
5
6
7
8
# File 'lib/ruql/tex_output.rb', line 3

def add_newlines(str)
  str.gsub(Regexp.new('<pre>(.*?)</pre>', Regexp::MULTILINE | Regexp::IGNORECASE) ) do |code_section|
    code_section.gsub!("\n"){"\\\\"}
    code_section.gsub!("  "){"\\hspace*{2em}"}      
  end
end

#to_tex(str) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/ruql/tex_output.rb', line 18

def to_tex(str)
  str = str.gsub(@@tex_escape) { |match| "\\#{match}" }
  str = add_newlines(str)
  
  @@tex_replace.each_pair do |match, replace|
    str = str.gsub(match, replace)
  end
  str
end