language-markdown icon indicating copy to clipboard operation
language-markdown copied to clipboard

Support proper notations for math/equations

Open heavywatal opened this issue 8 years ago • 7 comments

Using $$ ... $$ for display-style equations is not recommended in LaTeX. Instead, users are supposed to use the following notations:

  • \[ ... \]
  • \begin{equation*} ... \end{equation*}
  • \begin{equation} ... \end{equation}

They work well with MathJax. So I tried adding them to grammars/repositories/flavors/math-block.cson:

key: 'math-block'
patterns: [
  {
    name: 'block.math.markup.md'
    begin: '\\['
    end: '\\]'
    patterns: [{ include: 'text.tex.latex' }]
    beginCaptures:
      1: name: 'punctuation.md'
    endCaptures:
      1: name: 'punctuation.md'
  }
  {
    name: 'block.math.markup.md'
    begin: '\\begin{equation}'
    end: '\\end{equation}'
    patterns: [{ include: 'text.tex.latex' }]
    beginCaptures:
      1: name: 'punctuation.md'
    endCaptures:
      1: name: 'punctuation.md'
  }
]

After compiling and reloading, Atom recognizes \\[ ... \\] as a math block, but ignores \[ ... \] and \begin{equation} ... \end{equation}. I may be misunderstanding how regex works in Atom.

heavywatal avatar Aug 31 '17 10:08 heavywatal

Could you add a link to documentation that supports your request?

burodepeper avatar Aug 31 '17 10:08 burodepeper

It is written in the first page of "Short Math Guide for LaTeX" from http://www.ams.org/publications/authors/tex/amslatex but their FTP server seems not working now. Here is my copy: short-math-guide.pdf.

Also I found a discussion in Stack Exchange: https://tex.stackexchange.com/questions/503/why-is-preferable-to

heavywatal avatar Aug 31 '17 10:08 heavywatal

Thanks!

To get this working, I think you need to escape the { and } in the second pattern as well. If your change doesn't cause any regressions/issues with the other elements of the grammar, please submit this a PR.

burodepeper avatar Aug 31 '17 10:08 burodepeper

begin: '\\begin\{equation\}'
end: '\\end\{equation\}'

burodepeper avatar Aug 31 '17 10:08 burodepeper

Thanks, but it didn't work. Those single backslashes are removed in the compiled language-markdown.json:

        {
          "name": "block.math.markup.md",
          "begin": "\\begin{equation}",
          "end": "\\end{equation}",
          "patterns": [

Double backslashes in cson remain double in the compiled json:

    begin: '\\begin\\{equation\\}'
    end: '\\end\\{equation\\}'

Of course it didn't match \begin{equation} in markdown.

heavywatal avatar Aug 31 '17 10:08 heavywatal

Let me know if and when you've got it figured out. I'm heading into a meeting now.

burodepeper avatar Aug 31 '17 10:08 burodepeper

Now I understand we need \\\\\\[ for a regex pattern in JSON string to match \[.

heavywatal avatar Sep 01 '17 05:09 heavywatal