scopeName: text.latex
firstLineMatch: ^\\documentclass.*
fileTypes: 
  - tex
foldingStartMarker: \\begin\{.*\}
foldingStopMarker: \\end\{.*\}
patterns: 
  - name: string.other.math.block.latex
    begin: \$\$
    end: \$\$
  - name: keyword.operator.braces.latex
    match: [\[\]\{\}]
  - name: keyword.operator.newline.latex
    match: \\\\
  - name: declaration.section.latex
    begin: ((\\(?:(?:sub)*section|chapter|paragraph|part))(\*?)(?:(\[)[^\[]*?(\]))??(\{))
    end: (\})
    captures: 1: name: support.function.section.latex
    patterns: 
      - name: variable.parameter.section.latex
        match: [^}]+
  - name: source.python.embedded.latex
    # Put the lstlisting match before the more general environment listing. Someday it would be nice to make this rule general enough to figure out which language is inside the lstlisting environment rather than my own personal use for python. --Brad
    begin: (\\begin\{)(lstlisting)(\})(\[(.*)\])?
    end: (\\end\{)(lstlisting)(\})
    captures: 
      1: name: support.function.latex
      2: name: variable.parameter.latex
      3: name: support.function.latex
      4: name: support.function.latex
    patterns: 
      - include: source.python
  - name: declaration.verbatim.latex
    begin: ^\s*(\\begin\{)(verbatim)(\})
    end: ^\s*(\\end\{)(verbatim)(\})
    captures: 
      1: name: support.function.latex
      2: name: variable.parameter.latex
      3: name: support.function.latex
  - name: declaration.begin-document.latex
    # These two patterns match the \begin{document} and \end{document} commands, so that the environment matching pattern following them will ignore those commands.
    match: (\\begin\{)(document)(\})
    captures: 
      1: name: support.function.latex
      2: name: variable.parameter.latex
      3: name: support.function.latex
  - name: declaration.end-document.latex
    match: (\\end\{)(document)(\})
    captures: 
      1: name: support.function.latex
      2: name: variable.parameter.latex
      3: name: support.function.latex
  - name: declaration.begin-list.latex
    match: (\\begin\{)(enumerate|itemize|description|list)(\})
    captures: 
      1: name: support.function.be.latex
      2: name: variable.parameter.latex
      3: name: support.function.be.latex
  - name: declaration.end-list.latex
    match: (\\end\{)(enumerate|itemize|description|list)(\})
    captures: 
      1: name: support.function.be.latex
      2: name: variable.parameter.latex
      3: name: support.function.be.latex
  - name: declaration.begin.latex
    # Ideally these two commands should be changed to a single begin-end match, once Allan has gotten recursion working.
    match: (\\begin\{)(.*?)(\})
    captures: 
      1: name: support.function.be.latex
      2: name: variable.parameter.latex
      3: name: support.function.be.latex
  - name: declaration.end.latex
    match: (\\end\{)(.*?)(\})
    captures: 
      1: name: support.function.be.latex
      2: name: variable.parameter.latex
      3: name: support.function.be.latex
  - name: declaration.textit.latex
    # We put the keyword in a capture and name this capture, so that disabling spell checking for “keyword” won't be inherited by the argument to \textit{...}.
    # 
    # Put specific matches for particular LaTeX keyword.functions before the last two more general functions
    begin: (\\textit\{)
    end: (\})
    captures: 1: name: support.function.textit.latex
    patterns: 
      - name: markup.italic.textit.latex
        match: [^}]+
  - name: declaration.textbf.latex
    begin: (\\textbf\{)
    end: (\})
    captures: 1: name: support.function.textbf.latex
    patterns: 
      - name: markup.bold.textbf.latex
        match: [^}]+
  - name: declaration.texttt.latex
    begin: (\\texttt\{)
    end: (\})
    captures: 1: name: support.function.texttt.latex
    patterns: 
      - name: markup.other.raw.texttt.latex
        match: [^}]+
  - name: declaration.item.latex
    match: (\\item)(.*)$
    captures: 1: name: support.constant.item.latex
  - name: declaration.cite.latex
    begin: (\\cite(al)?[tp]?\*?(\[[^\]]*\]){,2}\{)
    end: (\})
    captures: 1: name: keyword.control.cite.latex
    patterns: 
      - name: variable.parameter.cite.latex
        match: \w+
  - name: declaration.ref-or-label.latex
    begin: (\\(?:ref|eqref|label)\{)
    end: (\})
    captures: 1: name: keyword.control.ref-or-label.latex
    patterns: 
      - name: variable.parameter.ref-or-latex.latex
        match: [a-zA-Z,:0-9]+
  - name: declaration.function.with-arg.latex
    # These next two are catch-all matches that will match almost any latex function. First match: \foo{arg1}{arg2}{...}{argN}
    begin: (\\[A-Za-z]\w*)(?=\{|\[)
    end: (?<=\]|\})
    captures: 1: name: support.function.with-arg.latex
    patterns: 
      - begin: \{
        end: \}
        patterns: 
          - name: variable.parameter.function.latex
            match: [^}]+
      - begin: \[
        end: \]
        patterns: 
          - name: variable.parameter.function.latex
            match: [^]]+
  - name: support.function.latex
    # then match just: \foo
    match: \\[A-Za-z]\w*
  - name: string.quoted.single.latex
    begin: ``
    end: ''
  - name: string.other.math.latex
    begin: (^|[^\\])\$
    end: \$
  - name: string.other.math.latex
    begin: \\\(
    end: \\\)
  - name: string.other.math.latex
    begin: \\\[
    end: \\\]
  - name: constant.character.escape.latex
    # Not sure if this is the proper classification. This is a catch-all for \<symbol> so that e.g. \" doesn't start an (invalid) string
    match: \\[^A-Za-z\n]
  - name: comment.line.percentage.latex
    match: %.*$
