Sha256: 4b2eaee140c0e57a9938d162b27976eb8c49776195d67a9ce034e655dad7c996

Contents?: true

Size: 1.37 KB

Versions: 12

Compression:

Stored size: 1.37 KB

Contents


class String

  # This method allows one to compute
  # the strings that represent LaTeX
  # macro applicatins without descent
  # into a hell of backlslshes and braces,
  # especially when more than one macro
  # has to be applied.  For example,
  # instead of
  #
  #    content = "\\roleblue\{ #{content}\}"
  #
  # we say just
  #
  #    content = content.macro('roleblue')
  #
  # Here is an appication of three macros:
  #
  #    content.macro('roleblue').macro('foo').macro('bar')
  #
  #
  def macro(macro)
    "\\#{macro}\{#{self}\}"
  end

  #   The 'apply_macros' method simplifies the
  #   chaining of a sequence of macro applications.
  #   For example, we could say
  #
  #   'yoda'.macro('baz').macro('bar').macro('foo')
  #
  #         => "\\foo{\\bar{\\baz{yoda}}}"
  #
  #   But it is simpler to say
  #
  #   'yoda'.apply_macros(['foo', 'bar', 'baz'])
  #
  #       => "\\foo{\\bar{\\baz{yoda}}}"
  #
  #   Because we reverse the argument list, the
  #   application order of the LaTeX macros
  #   matches the order in the argument list.

  def apply_macros(macro_list)
    val = self
    macro_list.reverse.each do |macro_name|
      val = val.macro(macro_name)
    end
    val
  end


  # map '_' to '-' and prefix by 'x' if the
  # leading character is '-'
  def tex_normalize
    str = self.gsub('_', '-')
    if str[0] == '-'
      'x'+str
    else
      str
    end
  end


end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
asciidoctor-latex-1.5.0.17.dev lib/asciidoctor/latex/core_ext/utility.rb
asciidoctor-latex-1.5.0.16.dev lib/asciidoctor/latex/core_ext/utility.rb
asciidoctor-latex-1.5.0.15.dev lib/asciidoctor/latex/core_ext/utility.rb
asciidoctor-latex-1.5.0.14.dev lib/asciidoctor/latex/core_ext/utility.rb
asciidoctor-latex-1.5.0.13.dev lib/asciidoctor/latex/core_ext/utility.rb
asciidoctor-latex-1.5.0.12.dev lib/asciidoctor/latex/core_ext/utility.rb
asciidoctor-latex-1.5.0.11.dev lib/asciidoctor/latex/core_ext/utility.rb
asciidoctor-latex-1.5.0.10.dev lib/asciidoctor/latex/core_ext/utility.rb
asciidoctor-latex-1.5.0.9.dev lib/asciidoctor/latex/core_ext/utility.rb
asciidoctor-latex-1.5.0.8b.dev lib/asciidoctor/latex/core_ext/utility.rb
asciidoctor-latex-1.5.0.7.dev lib/asciidoctor/latex/core_ext/utility.rb
asciidoctor-latex-1.5.0.5.dev lib/asciidoctor/latex/core_ext/utility.rb