class Rouge::Formatters::Tex

def escape_tex(str)

def escape_tex(str)
  str.gsub(ESCAPE_REGEX, ESCAPE)
end

def hphantom_tag(tok, val)

of the x's.
\hphantom{xxxx}, which renders an empty space equal to the size
by a previous command. We replace all initial spaces with
Special handling for leading spaces, since they may be gobbled
def hphantom_tag(tok, val)
  leading = nil
  val.sub!(/^[ ]+/) { leading = $&.size; '' }
  yield "\\hphantom{#{'x' * leading}}" if leading
  yield tag(tok, val) unless val.empty?
end

def initialize(opts={})

def initialize(opts={})
  @prefix = opts.fetch(:prefix) { 'RG' }
end

def render_line(line, &b)

def render_line(line, &b)
  line.each do |(tok, val)|
    hphantom_tag(tok, val, &b)
  end
end

def stream(tokens, &b)

def stream(tokens, &b)
  # surround the output with \begin{RG*}...\end{RG*}
  yield "\\begin{#{@prefix}*}%\n"
  # we strip the newline off the last line to avoid
  # an extra line being rendered. we do this by yielding
  # the \newline tag *before* every line group except
  # the first.
  first = true
  token_lines tokens do |line|
    if first
      first = false
    else
      yield "\\newline%\n"
    end
    render_line(line, &b)
  end
  yield "%\n\\end{#{@prefix}*}%\n"
end

def tag(tok, val)

def tag(tok, val)
  if escape?(tok)
    val
  elsif tok == Token::Tokens::Text
    escape_tex(val)
  else
    "\\#@prefix{#{tok.shortname}}{#{escape_tex(val)}}"
  end
end