Sha256: 2cda489c31b0d0fde571ec609f253efbf3fe3037a4aa071ea29172a09fee6912

Contents?: true

Size: 1.5 KB

Versions: 101

Compression:

Stored size: 1.5 KB

Contents

# encoding=utf-8
module Polytexnic
  module Postprocessor
    module Polytex

      # Removes references to the hypertarget package.
      # TODO: Support hypertarget
      # This isn't a priority, as you get most of what you need
      # with hyperref.
      def remove_hypertarget
        @source.gsub!(/\\hypertarget.*$/, '')
      end

      # Fixes a kramdown verbatim bug.
      # When converting code, kramdown outputs
      # "\begin{verbatim}foo" instead of
      # "\begin{verbatim}\nfoo".
      def fix_verbatim_bug
        @source.gsub!(/\\begin\{verbatim\}/) { |s| s + "\n" }
      end

      # 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
      # \begin{code}
      # def foo
      #   "bar"
      # end
      # \end{code}
      # which reduces syntax highlighting to a previously solved problem.
      def write_polytex_code
        code_cache.each do |key, (code, lang, in_codelisting, options)|
          # puts '*********'
          # puts @source.inspect
          # raise code.inspect
          latex = "%= lang:#{lang}#{options}\n" +
                  "\\begin{code}\n" + escape_hack(code) + "\n\\end{code}"
          @source.gsub!(key, latex)
        end
      end

      # Hacks some backslash escapes.
      # Seriously, WTF is up with backslashes?
      def escape_hack(string)
        string.gsub('\\', '\\\\\\')
      end
    end
  end
end

Version data entries

101 entries across 101 versions & 1 rubygems

Version Path
polytexnic-1.9.2 lib/polytexnic/postprocessors/polytex.rb
polytexnic-1.9.1 lib/polytexnic/postprocessors/polytex.rb
polytexnic-1.9.0 lib/polytexnic/postprocessors/polytex.rb
polytexnic-1.8.2 lib/polytexnic/postprocessors/polytex.rb
polytexnic-1.8.1 lib/polytexnic/postprocessors/polytex.rb
polytexnic-1.8.0 lib/polytexnic/postprocessors/polytex.rb
polytexnic-1.7.5 lib/polytexnic/postprocessors/polytex.rb
polytexnic-1.7.4 lib/polytexnic/postprocessors/polytex.rb
polytexnic-1.7.3 lib/polytexnic/postprocessors/polytex.rb
polytexnic-1.7.2 lib/polytexnic/postprocessors/polytex.rb
polytexnic-1.7.1 lib/polytexnic/postprocessors/polytex.rb
polytexnic-1.7.0 lib/polytexnic/postprocessors/polytex.rb
polytexnic-1.6.6 lib/polytexnic/postprocessors/polytex.rb
polytexnic-1.6.5 lib/polytexnic/postprocessors/polytex.rb
polytexnic-1.6.4 lib/polytexnic/postprocessors/polytex.rb
polytexnic-1.6.3 lib/polytexnic/postprocessors/polytex.rb
polytexnic-1.6.2 lib/polytexnic/postprocessors/polytex.rb
polytexnic-1.6.1 lib/polytexnic/postprocessors/polytex.rb
polytexnic-1.6.0 lib/polytexnic/postprocessors/polytex.rb
polytexnic-1.5.16 lib/polytexnic/postprocessors/polytex.rb