Add math grammar/language to markdown math blocks

Fixes #124719
This commit is contained in:
Matt Bierner 2021-06-17 18:01:02 -07:00
parent 334fb18d6f
commit 2ae31a96cf
No known key found for this signature in database
GPG key ID: 099C331567E11888
8 changed files with 4129 additions and 0 deletions

View file

@ -0,0 +1,17 @@
{
"registrations": [
{
"component": {
"type": "git",
"git": {
"name": "James-Yu/LaTeX-Workshop",
"repositoryUrl": "https://github.com/James-Yu/LaTeX-Workshop",
"commitHash": "e4cd86f1731546c2cdde0cc93717ca3fec2da0ba"
}
},
"license": "MIT",
"version": "8.19.1"
}
],
"version": 1
}

View file

@ -0,0 +1,56 @@
{
"comments": {
"lineComment": "%"
},
// symbols used as brackets
"brackets": [
[
"{",
"}"
],
[
"[",
"]"
],
[
"(",
")"
]
],
"autoClosingPairs": [
{
"open": "{",
"close": "}"
},
{
"open": "[",
"close": "]"
},
{
"open": "(",
"close": ")"
}
],
"surroundingPairs": [
[
"(",
")"
],
[
"[",
"]"
],
[
"{",
"}"
],
[
"'",
"'"
],
[
"\"",
"\""
]
]
}

View file

@ -23,6 +23,40 @@
"browser": "./dist/browser/extension",
"activationEvents": [],
"contributes": {
"languages": [
{
"id": "markdown-math",
"aliases": [],
"configuration": "./language-configuration.json"
}
],
"grammars": [
{
"language": "markdown-math",
"scopeName": "text.html.markdown.math",
"path": "./syntaxes/md-math.tmLanguage.json"
},
{
"scopeName": "markdown.math.block",
"path": "./syntaxes/md-math-block.tmLanguage.json",
"injectTo": [
"text.html.markdown"
],
"embeddedLanguages": {
"meta.embedded.math.markdown": "markdown-math"
}
},
{
"scopeName": "markdown.math.inline",
"path": "./syntaxes/md-math-inline.tmLanguage.json",
"injectTo": [
"text.html.markdown"
],
"embeddedLanguages": {
"meta.embedded.math.markdown": "markdown-math"
}
}
],
"notebookRenderer": [
{
"id": "markdownItRenderer-katex",

View file

@ -0,0 +1,33 @@
{
"fileTypes": [],
"injectionSelector": "L:text.html.markdown - (comment, string, meta.paragraph.markdown, markup.math.block.markdown)",
"patterns": [
{
"include": "#math_block"
}
],
"repository": {
"math_block": {
"name": "markup.math.block.markdown",
"contentName": "meta.embedded.math.markdown",
"begin": "(?<=(^|\\G)\\s*)(\\${1,2})(?=\\s*$)",
"beginCaptures": {
"1": {
"name": "punctuation.definition.math.begin.markdown"
}
},
"end": "^\\s*(\\${1,2})\\s*$",
"endCaptures": {
"1": {
"name": "punctuation.definition.math.end.markdown"
}
},
"patterns": [
{
"include": "text.html.markdown.math#math"
}
]
}
},
"scopeName": "markdown.math.block"
}

View file

@ -0,0 +1,32 @@
{
"fileTypes": [],
"injectionSelector": "L:meta.paragraph.markdown - (comment, string, markup.math.inline.markdown)",
"patterns": [
{
"include": "#math_inline"
}
],
"repository": {
"math_inline": {
"name": "markup.math.inline.markdown",
"contentName": "meta.embedded.math.markdown",
"match": "(?<=\\s|^)(\\${1,2})(.+?)(\\${1,2})(?=\\s|$)",
"captures": {
"1": {
"name": "punctuation.definition.math.begin.markdown"
},
"2": {
"patterns": [
{
"include": "text.html.markdown.math#math"
}
]
},
"3": {
"name": "punctuation.definition.math.begin.markdown"
}
}
}
},
"scopeName": "markdown.math.inline"
}

View file

@ -0,0 +1,107 @@
{
"information_for_contributors": [
"This file includes some grammar rules copied from https://github.com/James-Yu/LaTeX-Workshop/blob/master/syntax/TeX.tmLanguage.json"
],
"name": "Markdown Math",
"scopeName": "text.html.markdown.math",
"patterns": [
{
"include": "#math"
}
],
"repository": {
"math": {
"patterns": [
{
"name": "comment.line.math.tex",
"match": "(%)(.+)$",
"captures": {
"1": {
"name": "punctuation.definition.comment.math.tex"
}
}
},
{
"name": "line.separator.math.tex",
"match": "(\\\\\\\\)$",
"captures": {
"1": {
"name": "punctuation.line.separator.math.tex"
}
}
},
{
"name": "meta.function.math.tex",
"begin": "((\\\\)([a-zA-Z_]+))(\\{)",
"beginCaptures": {
"1": {
"name": "storage.type.function.math.tex"
},
"2": {
"name": "punctuation.definition.function.math.tex"
},
"3": {
"name": "entity.name.function.math.tex"
},
"4": {
"name": "punctuation.definition.arguments.begin.math.tex"
}
},
"end": "\\}",
"endCaptures": {
"0": {
"name": "punctuation.definition.arguments.end.math.tex"
}
},
"patterns": [
{
"include": "$self"
}
]
},
{
"captures": {
"1": {
"name": "punctuation.definition.constant.math.tex"
}
},
"match": "(\\\\)([a-zA-Z_]+)\\b",
"name": "constant.character.math.tex"
},
{
"captures": {
"1": {
"name": "punctuation.definition.constant.math.tex"
}
},
"match": "(\\\\)(?!begin\\{|verb)([A-Za-z]+)",
"name": "constant.other.general.math.tex"
},
{
"match": "(?<!\\\\)\\{",
"name": "punctuation.math.begin.bracket.curly"
},
{
"match": "(?<!\\\\)\\}",
"name": "punctuation.math.end.bracket.curly"
},
{
"match": "\\(",
"name": "punctuation.math.begin.bracket.round"
},
{
"match": "\\)",
"name": "punctuation.math.end.bracket.round"
},
{
"match": "(([0-9]*[\\.][0-9]+)|[0-9]+)",
"name": "constant.numeric.math.tex"
},
{
"match": "[\\+\\*/_\\^-]",
"name": "punctuation.math.operator.latex"
}
]
}
}
}

View file

@ -0,0 +1,64 @@
<!-- Should highlight math blocks -->
$$
\theta
$$
$$
\theta{ % comment
$$
**a**
$$
\relax{x}{1} = \int_{-\infty}^\infty
\hat\xi\,e^{2 \pi i \xi x}
\,d\xi % comment
$$
$
x = 1.1 \int_{a}
$
$
\begin{smallmatrix}
1 & 2 \\
4 & 3
\end{smallmatrix}
$
$
x = a_0 + \frac{1}{a_1 + \frac{1}{a_2 + \frac{1}{a_3 + a_4}}}
$
$
\displaystyle {1 + \frac{q^2}{(1-q)}+\frac{q^6}{(1-q)(1-q^2)}+\cdots }= \prod_{j=0}^{\infty}\frac{1}{(1-q^{5j+2})(1-q^{5j+3})}, \quad\quad \text{for }\lvert q\rvert<1.
$
<!-- Should highlight inline -->
a **a** $$ \theta $$ aa a **a**
a **a** $ \theta $ aa a **a**
$ \theta $
$$ 1 \theta 1 1 $$
<!-- Should not highlight inline cases without whitespace -->
$10 $20
**a** $10 $20 **a**
**a** a $10 $20 a **a**
a **a**$ \theta $aa a **a**
a **a**$$ \theta $$aa a **a**
<!--
$$
\theta % comment
$$
-->

File diff suppressed because it is too large Load diff