Added support for $$ equations (#1916)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
diff --git a/components/prism-latex.js b/components/prism-latex.js
index 4ccbd72..68a45b6 100644
--- a/components/prism-latex.js
+++ b/components/prism-latex.js
@@ -15,12 +15,12 @@
lookbehind: true
},
/*
- * equations can be between $ $ or \( \) or \[ \]
+ * equations can be between $$ $$ or $ $ or \( \) or \[ \]
* (all are multiline)
*/
'equation': [
{
- pattern: /\$(?:\\[\s\S]|[^\\$])*\$|\\\([\s\S]*?\\\)|\\\[[\s\S]*?\\\]/,
+ pattern: /\$\$(?:\\[\s\S]|[^\\$])+\$\$|\$(?:\\[\s\S]|[^\\$])+\$|\\\([\s\S]*?\\\)|\\\[[\s\S]*?\\\]/,
inside: insideEqu,
alias: 'string'
},
diff --git a/components/prism-latex.min.js b/components/prism-latex.min.js
index bab30c2..261cae4 100644
--- a/components/prism-latex.min.js
+++ b/components/prism-latex.min.js
@@ -1 +1 @@
-!function(a){var e=/\\(?:[^a-z()[\]]|[a-z*]+)/i,n={"equation-command":{pattern:e,alias:"regex"}};a.languages.latex={comment:/%.*/m,cdata:{pattern:/(\\begin\{((?:verbatim|lstlisting)\*?)\})[\s\S]*?(?=\\end\{\2\})/,lookbehind:!0},equation:[{pattern:/\$(?:\\[\s\S]|[^\\$])*\$|\\\([\s\S]*?\\\)|\\\[[\s\S]*?\\\]/,inside:n,alias:"string"},{pattern:/(\\begin\{((?:equation|math|eqnarray|align|multline|gather)\*?)\})[\s\S]*?(?=\\end\{\2\})/,lookbehind:!0,inside:n,alias:"string"}],keyword:{pattern:/(\\(?:begin|end|ref|cite|label|usepackage|documentclass)(?:\[[^\]]+\])?\{)[^}]+(?=\})/,lookbehind:!0},url:{pattern:/(\\url\{)[^}]+(?=\})/,lookbehind:!0},headline:{pattern:/(\\(?:part|chapter|section|subsection|frametitle|subsubsection|paragraph|subparagraph|subsubparagraph|subsubsubparagraph)\*?(?:\[[^\]]+\])?\{)[^}]+(?=\}(?:\[[^\]]+\])?)/,lookbehind:!0,alias:"class-name"},function:{pattern:e,alias:"selector"},punctuation:/[[\]{}&]/},a.languages.tex=a.languages.latex,a.languages.context=a.languages.latex}(Prism);
\ No newline at end of file
+!function(a){var e=/\\(?:[^a-z()[\]]|[a-z*]+)/i,n={"equation-command":{pattern:e,alias:"regex"}};a.languages.latex={comment:/%.*/m,cdata:{pattern:/(\\begin\{((?:verbatim|lstlisting)\*?)\})[\s\S]*?(?=\\end\{\2\})/,lookbehind:!0},equation:[{pattern:/\$\$(?:\\[\s\S]|[^\\$])+\$\$|\$(?:\\[\s\S]|[^\\$])+\$|\\\([\s\S]*?\\\)|\\\[[\s\S]*?\\\]/,inside:n,alias:"string"},{pattern:/(\\begin\{((?:equation|math|eqnarray|align|multline|gather)\*?)\})[\s\S]*?(?=\\end\{\2\})/,lookbehind:!0,inside:n,alias:"string"}],keyword:{pattern:/(\\(?:begin|end|ref|cite|label|usepackage|documentclass)(?:\[[^\]]+\])?\{)[^}]+(?=\})/,lookbehind:!0},url:{pattern:/(\\url\{)[^}]+(?=\})/,lookbehind:!0},headline:{pattern:/(\\(?:part|chapter|section|subsection|frametitle|subsubsection|paragraph|subparagraph|subsubparagraph|subsubsubparagraph)\*?(?:\[[^\]]+\])?\{)[^}]+(?=\}(?:\[[^\]]+\])?)/,lookbehind:!0,alias:"class-name"},function:{pattern:e,alias:"selector"},punctuation:/[[\]{}&]/},a.languages.tex=a.languages.latex,a.languages.context=a.languages.latex}(Prism);
\ No newline at end of file
diff --git a/tests/languages/latex/equation_feature.test b/tests/languages/latex/equation_feature.test
index 40caeeb..60191b3 100644
--- a/tests/languages/latex/equation_feature.test
+++ b/tests/languages/latex/equation_feature.test
@@ -1,6 +1,9 @@
$foo$
$a \dots
b$
+$$foo$$
+$$a \dots
+b$$
\(foo\)
\(a \dots
b\)
@@ -36,6 +39,14 @@ b\end{gather}
["equation-command", "\\dots"],
"\r\nb$"
]],
+ ["equation", [
+ "$$foo$$"
+ ]],
+ ["equation", [
+ "$$a ",
+ ["equation-command", "\\dots"],
+ "\r\nb$$"
+ ]],
["equation", ["\\(foo\\)"]],
["equation", [
"\\(a ",
@@ -118,4 +129,4 @@ b\end{gather}
----------------------------------------------------
-Checks for equations.
\ No newline at end of file
+Checks for equations.