fletcher / MultiMarkdown-5

Reference implementation of MultiMarkdown; replaces MultiMarkdown v4 (deprecated -- see MMD-6 instead)
https://github.com/fletcher/MultiMarkdown-6
Other
293 stars 46 forks source link

mmd2tex math delimiters #16

Open ickc opened 8 years ago

ickc commented 8 years ago

Hi, I mentioned this before in the mmd support forum, but it was buried in another issue I was talking about (related to LaTeX math environment $$\begin{align)...). In the hindsight I should have separated the 2 issues. I hope you don't mind I kind of repeat it here:

Currently, in mmd2html and mmd2tex, this is how the math delimiter is translated:

MMD Source HTML Output LaTeX Output
$...$ \(...\) $...$
$$...$$ \[...\] $$...$$
\\(...\\) \(...\) $...$
\\[...\\] \[...\] \[...\]

The proposal is simple:

MMD Source HTML Output LaTeX Output
$...$ \(...\) \(...\)
$$...$$ \[...\] \[...\]
\\(...\\) \(...\) \(...\)
\\[...\\] \[...\] \[...\]

Reasons:

  1. the \(...\) and \[...\] delimiters are preferred in LaTeX, and $$...$$ might cause errors with some ams packages.
  2. so that the HTML output and LaTeX output are identical as far as math delimiter is concerned
fletcher commented 8 years ago

It seems that the "proper" fix is that \\(...\\) should become $...$, right? Some people want to use "dollar sign math" in LaTeX, and I'm not clear why we should get rid of that.

The goal is not that HTML and LaTeX output is the same (for obvious reasons). The goal is that the meaning of the MMD input is correctly represented in each output format, regardless of the syntax to produce that output. (Math is a bit strange since it's not really HTML math, but MathJax math... This was different in MMD 2 when I used ASCIIMathML.)

ickc commented 8 years ago

According to LaTeX/Mathematics - Wikibooks, open books for an open world, $...$ and $$...$$ are TeX, \(...\) and \[...\] are LaTeX. And the reason to avoid $...$ and $$...$$ is that AMS packages might have error, especially when $$...$$ is used.

And since we're talking about mmd2tex generation, the source is in mmd. So like me, I want to write in $...$ and $$...$$ rather than \\(...\\) and \\[...\\] in mmd (obviously because of the inconvenience of double backslash). But we want the .tex output to be a "correct" LaTeX file. And from what I heard the "correct" way of using that in LaTeX is \(...\) and \[...\].

Since my sources are from wikibooks, forums, google searches, I might not be correct. But I recall MathJax's documentation mention something related and they recommend \(...\) and \[...\] (that's why your mmd2html also output \(...\) and \[...\]). Although MathJax allow optional setup to use $...$ (see MathJax TeX and LaTeX Support — MathJax 2.6 documentation), but it is discouraged.

So that's why I said in the beginning it might be better for MMD to output the brackets rather than dollar sign, regardless which one is used in the mmd source.

By the way, you said

It seems that the "proper" fix is that \\(...\\) should become $...$, right?

I actually mean,

MMD Source HTML Output LaTeX Output
$...$ \(...\) \(...\)
$$...$$ \[...\] \[...\]
\\(...\\) \(...\) \(...\)
\\[...\\] \[...\] \[...\]

The first column is the MMD source, the last column is the proposed output in LaTeX. The most serious trouble maker is $$...$$ in mmd, which currently becomes the same thing in TeX, but as I said it would (in some cases) cause error in AMS packages. So the "proper" fix is \[...\].

ickc commented 8 years ago

In other words, is $...$ identical to \(...\) and $$...$$ identical to \[...\] in LaTeX? If so, it is only an aesthetic choice as you said "some people might want to use...". But my point it they are not identical in LaTeX, the dollar signs are inferior, legacy, discouraged, and might sometimes cause errors.

But I emphasized this is only something I read from the others sources, that I didn't know deeply why it is discouraged [^ at least the original creator of TeX also think it is a mistake (when designing TeX) to use dollar sign as it becomes very difficult to detect the beginning and the end of a math environment] and when it will cause error.

And another support might be from pandoc, that when the dollar signs are used (the default of pandoc), it turn them into brackets in .tex generation.