Sha256: 1e85dda41f1bc96d153a6a885faa18ffff28f986212a348e64ad3775505d3bb3

Contents?: true

Size: 1.78 KB

Versions: 14

Compression:

Stored size: 1.78 KB

Contents

# -*- coding: utf-8 -*- #

module Rouge
  module Lexers
    class TeX < RegexLexer
      title "TeX"
      desc "The TeX typesetting system"
      tag 'tex'
      aliases 'TeX', 'LaTeX', 'latex'

      filenames '*.tex', '*.aux', '*.toc'
      mimetypes 'text/x-tex', 'text/x-latex'

      def self.analyze_text(text)
        return 1 if text =~ /\A\s*\\documentclass/
        return 1 if text =~ /\A\s*\\input/
        return 1 if text =~ /\A\s*\\documentstyle/
        return 1 if text =~ /\A\s*\\relax/
      end

      command = /\\([a-z]+|\s+|.)/i

      state :general do
        rule /%.*$/, Comment
        rule /[{}&_^]/, Punctuation
      end

      state :root do
        rule /\\\[/, Punctuation, :displaymath
        rule /\\\(/, Punctuation, :inlinemath
        rule /\$\$/, Punctuation, :displaymath
        rule /\$/, Punctuation, :inlinemath
        rule /\\(begin|end)\{.*?\}/, Name::Tag

        rule /(\\verb)\b(\S)(.*?)(\2)/ do |m|
          groups Name::Builtin, Keyword::Pseudo, Str::Other, Keyword::Pseudo
        end

        rule command, Keyword, :command
        mixin :general
        rule /[^\\$%&_^{}]+/, Text
      end

      state :math do
        rule command, Name::Variable
        mixin :general
        rule /[0-9]+/, Num
        rule /[-=!+*\/()\[\]]/, Operator
        rule /[^=!+*\/()\[\]\\$%&_^{}0-9-]+/, Name::Builtin
      end

      state :inlinemath do
        rule /\\\)/, Punctuation, :pop!
        rule /\$/, Punctuation, :pop!
        mixin :math
      end

      state :displaymath do
        rule /\\\]/, Punctuation, :pop!
        rule /\$\$/, Punctuation, :pop!
        rule /\$/, Name::Builtin
        mixin :math
      end

      state :command do
        rule /\[.*?\]/, Name::Attribute
        rule /\*/, Keyword
        rule(//) { pop! }
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
rouge-2.0.6 lib/rouge/lexers/tex.rb
rouge-2.0.5 lib/rouge/lexers/tex.rb
rouge-2.0.3 lib/rouge/lexers/tex.rb
rouge-2.0.2 lib/rouge/lexers/tex.rb
rouge-2.0.1 lib/rouge/lexers/tex.rb
rouge-2.0.0 lib/rouge/lexers/tex.rb
rouge-1.11.1 lib/rouge/lexers/tex.rb
rouge-1.11.0 lib/rouge/lexers/tex.rb
rouge-1.10.1 lib/rouge/lexers/tex.rb
rouge-1.10.0 lib/rouge/lexers/tex.rb
gitlab-rouge-1.9.2 lib/rouge/lexers/tex.rb
rouge-1.9.1 lib/rouge/lexers/tex.rb
rouge-1.9.0 lib/rouge/lexers/tex.rb
rouge-1.8.0 lib/rouge/lexers/tex.rb