Sha256: 2a3f7a85d96cd7830f5f4a775fcaea4ee67d0f4c7f5d8e34a9e50ef10bccb0e8

Contents?: true

Size: 1.83 KB

Versions: 12

Compression:

Stored size: 1.83 KB

Contents

module Polytexnic
  module Preprocessor
    module Latex

      def to_processed_latex
        @polytex = convert_gifs(
                     polish_tables(
                     process_asides(clean_latex_document)))
      end

      # Returns LaTeX with hashed versions of literal environments.
      # Literal environments are hashed and passed through the pipeline
      # so that we can process things like refs and hyperrefs using gsubs.
      def clean_latex_document
        cache_literal(@polytex, :latex)
      end

      # Convert GIFs to PNGs.
      # Unfortunately, xelatex doesn't support GIFs. This converts the included
      # filenames to use '.png' in place of '.gif'. When used with the Softcover
      # system, the correct PNG files are automatically created on the fly.
      def convert_gifs(text)
        text.tap do
          text.gsub!(/\\(includegraphics|image|imagebox)\{(.*)\.gif\}/) do
            "\\#{$1}{#{$2}.png}"
          end
        end
      end

      def polish_tables(text)
        text.tap do
          text.gsub!(/^\s*(\\begin\{table\})/) do
            "#{$1}\n\\begin{center}\n\\small\n"
          end
          text.gsub!(/^\s*(\\end\{table\})/) { "\\end{center}\n#{$1}" }
        end
      end

      # Processes aside environments.
      # In order to get nice framed & shaded aside boxes, we need to
      # transform the default aside into a new environment.
      def process_asides(text)
        # Transform asides with labels and headings.
        aside_regex = /\\begin{aside}\n\s*
                       \\label{(.*?)}\s*
                       \\heading{(.*?)}\n
                       (.*?)
                       \\end{aside}/mx
        text.tap do
          text.gsub!(aside_regex) do
            %(\\begin{shaded_aside}{#{$2}}{#{$1}}\n#{$3}\n\\end{shaded_aside})
          end
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
polytexnic-1.0.beta1 lib/polytexnic/preprocessors/latex.rb
polytexnic-0.9.10 lib/polytexnic/preprocessors/latex.rb
polytexnic-0.9.9 lib/polytexnic/preprocessors/latex.rb
polytexnic-0.9.8 lib/polytexnic/preprocessors/latex.rb
polytexnic-0.9.7 lib/polytexnic/preprocessors/latex.rb
polytexnic-0.9.6 lib/polytexnic/preprocessors/latex.rb
polytexnic-0.9.5 lib/polytexnic/preprocessors/latex.rb
polytexnic-0.9.4 lib/polytexnic/preprocessors/latex.rb
polytexnic-0.9.3 lib/polytexnic/preprocessors/latex.rb
polytexnic-0.9.2 lib/polytexnic/preprocessors/latex.rb
polytexnic-0.9.1 lib/polytexnic/preprocessors/latex.rb
polytexnic-0.9.0 lib/polytexnic/preprocessors/latex.rb