Module: Polytexnic::Postprocessor::Polytex
- Included in:
- Polytexnic::Postprocessor
- Defined in:
- lib/polytexnic/postprocessors/polytex.rb
Instance Method Summary collapse
-
#escape_hack(string) ⇒ Object
Hacks some backslash escapes.
-
#fix_verbatim_bug ⇒ Object
Fixes a kramdown verbatim bug.
-
#remove_hypertarget ⇒ Object
Removes references to the hypertarget package.
-
#write_polytex_code ⇒ Object
Writes the PolyTeX code environments based on the code cache.
Instance Method Details
#escape_hack(string) ⇒ Object
Hacks some backslash escapes. Seriously, WTF is up with backslashes?
49 50 51 |
# File 'lib/polytexnic/postprocessors/polytex.rb', line 49 def escape_hack(string) string.gsub('\\', '\\\\\\') end |
#fix_verbatim_bug ⇒ Object
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_hypertarget ⇒ Object
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_code ⇒ Object
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 43 44 45 |
# File 'lib/polytexnic/postprocessors/polytex.rb', line 36 def write_polytex_code code_cache.each do |key, (code, lang, in_codelisting, )| # puts '*********' # puts @source.inspect # raise code.inspect latex = "%= lang:#{lang}#{}\n" + "\\begin{code}\n" + escape_hack(code) + "\n\\end{code}" @source.gsub!(key, latex) end end |