Module: Polytexnic::Postprocessor::Polytex

Included in:
Polytexnic::Postprocessor
Defined in:
lib/polytexnic/postprocessors/polytex.rb

Instance Method Summary collapse

Instance Method Details

#escape_hack(string) ⇒ Object

Hacks some backslash escapes. Seriously, WTF is up with backslashes?



46
47
48
# File 'lib/polytexnic/postprocessors/polytex.rb', line 46

def escape_hack(string)
  string.gsub('\\', '\\\\\\')
end

#fix_verbatim_bugObject

Fixes a kramdown verbatim bug. When converting code, kramdown outputs “beginHtml#verbatimfoo” instead of “beginHtml#verbatimnfoo”.



18
19
20
# File 'lib/polytexnic/postprocessors/polytex.rb', line 18

def fix_verbatim_bug
  @source.gsub!(/\\begin\{verbatim\}/) { |s| s + "\n" }
end

#remove_hypertargetObject

Removes references to the hypertarget package. TODO: Support hypertarget This isn’t a priority, as you get most of what you need with hyperref.



10
11
12
# File 'lib/polytexnic/postprocessors/polytex.rb', line 10

def remove_hypertarget
  @source.gsub!(/\\hypertarget.*$/, '')
end

#write_polytex_codeObject

Writes the PolyTeX code environments based on the code cache. I.e., code that looks like lang=“ruby”

def foo
  "bar"
end

becomes %= lang:ruby beginHtml#code def foo

"bar"

end endHtml#code which reduces syntax highlighting to a previously solved problem.



36
37
38
39
40
41
42
# File 'lib/polytexnic/postprocessors/polytex.rb', line 36

def write_polytex_code
  code_cache.each do |key, (code, lang, in_codelisting, options)|
    latex = "%= lang:#{lang}#{options}\n" +
            "\\begin{code}\n" + escape_hack(code) + "\n\\end{code}"
    @source.gsub!(key, latex)
  end
end