From 94f19cad29ba172b2efa8011f98b50519145f0f9 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Thu, 14 Apr 2022 11:06:08 +0200 Subject: [PATCH] latex: update queries Make use of parser updates * add `\{re}newenvironment` * add `\DeclarePairedDelimiter{X}` * add `\title` and `\author` * add optional arguments to sectioning commands * use builtin nodes for math environments --- queries/latex/folds.scm | 1 + queries/latex/highlights.scm | 102 ++++++++++++++--------------------- 2 files changed, 42 insertions(+), 61 deletions(-) diff --git a/queries/latex/folds.scm b/queries/latex/folds.scm index 6769b2e6a..07505c375 100644 --- a/queries/latex/folds.scm +++ b/queries/latex/folds.scm @@ -8,6 +8,7 @@ (subparagraph) (generic_environment) + (math_environment) (comment_environment) (displayed_equation) ] @fold diff --git a/queries/latex/highlights.scm b/queries/latex/highlights.scm index bfa3edbc6..e1772ca16 100644 --- a/queries/latex/highlights.scm +++ b/queries/latex/highlights.scm @@ -32,35 +32,11 @@ ;; General environments (begin command: _ @text.environment - name: (curly_group_text - (text) @text.environment.name) - (#not-any-of? @text.environment.name - "displaymath" "displaymath*" - "equation" "equation*" - "multline" "multline*" - "eqnarray" "eqnarray*" - "align" "align*" - "array" "array*" - "split" "split*" - "alignat" "alignat*" - "gather" "gather*" - "flalign" "flalign*")) + name: (curly_group_text (text) @text.environment.name)) (end command: _ @text.environment - name: (curly_group_text - (text) @text.environment.name) - (#not-any-of? @text.environment.name - "displaymath" "displaymath*" - "equation" "equation*" - "multline" "multline*" - "eqnarray" "eqnarray*" - "align" "align*" - "array" "array*" - "split" "split*" - "alignat" "alignat*" - "gather" "gather*" - "flalign" "flalign*")) + name: (curly_group_text (text) @text.environment.name)) ;; Definitions and references (new_command_definition @@ -73,10 +49,18 @@ command: _ @function.macro declaration: (_) @function) +(environment_definition + command: _ @function.macro + name: (curly_group_text (_) @text.reference)) + (theorem_definition command: _ @function.macro name: (curly_group_text (_) @text.environment.name)) +(paired_delimiter_definition + command: _ @function.macro + declaration: (curly_group_command_name (_) @function)) + (label_definition command: _ @function.macro name: (curly_group_text (_) @text.reference)) @@ -121,69 +105,65 @@ [ (displayed_equation) (inline_formula) + (math_set) ] @text.math -((generic_environment +(math_environment (begin command: _ @text.math - name: (curly_group_text - (text) @_env))) @text.math - (#any-of? @_env - "displaymath" "displaymath*" - "equation" "equation*" - "multline" "multline*" - "eqnarray" "eqnarray*" - "align" "align*" - "array" "array*" - "split" "split*" - "alignat" "alignat*" - "gather" "gather*" - "flalign" "flalign*")) -((generic_environment + name: (curly_group_text (text) @text.math))) + +(math_environment (end command: _ @text.math - name: (curly_group_text - (text) @_env))) @text.math - (#any-of? @_env - "displaymath" "displaymath*" - "equation" "equation*" - "multline" "multline*" - "eqnarray" "eqnarray*" - "align" "align*" - "array" "array*" - "split" "split*" - "alignat" "alignat*" - "gather" "gather*" - "flalign" "flalign*")) + name: (curly_group_text (text) @text.math))) ;; Sectioning +(title_declaration + command: _ @namespace + options: (brack_group (_) @text.title)? + text: (curly_group (_) @text.title)) + +(author_declaration + command: _ @namespace + authors: (curly_group_author_list + ((command_name)? @function) + ((author)+ @text.title))) + (chapter command: _ @namespace - text: (curly_group) @text.title) + toc: (brack_group (_) @text.title)? + text: (curly_group (_) @text.title)) (part command: _ @namespace - text: (curly_group) @text.title) + toc: (brack_group (_) @text.title)? + text: (curly_group (_) @text.title)) (section command: _ @namespace - text: (curly_group) @text.title) + toc: (brack_group (_) @text.title)? + text: (curly_group (_) @text.title)) (subsection command: _ @namespace - text: (curly_group) @text.title) + toc: (brack_group (_) @text.title)? + text: (curly_group (_) @text.title)) (subsubsection command: _ @namespace - text: (curly_group) @text.title) + toc: (brack_group (_) @text.title)? + text: (curly_group (_) @text.title)) (paragraph command: _ @namespace - text: (curly_group) @text.title) + toc: (brack_group (_) @text.title)? + text: (curly_group (_) @text.title)) (subparagraph command: _ @namespace - text: (curly_group) @text.title) + toc: (brack_group (_) @text.title)? + text: (curly_group (_) @text.title)) ;; Beamer frames (generic_environment