Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Markdown-here does not seem to handle long equations #410

Open
GLorieul opened this issue Feb 2, 2017 · 1 comment
Open

Markdown-here does not seem to handle long equations #410

GLorieul opened this issue Feb 2, 2017 · 1 comment

Comments

@GLorieul
Copy link

GLorieul commented Feb 2, 2017

Hi,

To add to what has been reported earlier on a similar subject here, I would like to present here some limitations of Google Charts that have caused me trouble while using Markdown-here v2.12.0 (2015-09-07).

User case

I am writing an e-mail to my PhD supervisors to inform them of a mistake I found in a previous PhD dissertation in numerical methods. For that purpose, an e-mail appears to me as the right medium. Of course because of the nature of the subject, it has to contain equations…

As part of the e-mail I have a small demonstration that is quite "technical" (i.e. a fair bit of calculations).

Problem occurs with Markdown-here + google charts

However, calculations can get quite long and for instance one of the equations that I must write is the following :

$\Delta (u \times v ) = \left\{ \begin{matrix} [ b \, \Delta r + r \, \Delta b + 2 \, \nabla b \cdot \Delta r ] - [ c \, \Delta q + q \, \Delta c + 2 \, \nabla c \cdot \nabla q ] \\ [ c \, \Delta p + p \, \Delta c + 2 \, \nabla c \cdot \Delta p ] - [ a \, \Delta r + r \, \Delta a + 2 \, \nabla a \cdot \nabla r ] \\ [ a \, \Delta q + q \, \Delta a + 2 \, \nabla a \cdot \Delta q ] - [ b \, \Delta p + p \, \Delta b + 2 \, \nabla b \cdot \nabla p ] \end{matrix} \right\}$

Unfortunately this line doesn't render, eventhough it is syntaxly correct… Indeed, it can be compiled by storing it in a *.tex file

\documentclass[10pt, a4paper]{article}
\usepackage{amsmath}

\begin{document}
\[
\Delta (u \times v ) = \left\{ \begin{matrix} [ b \, \Delta r + r \, \Delta b + 2 \, \nabla b \cdot \Delta r ] - [ c \, \Delta q + q \, \Delta c + 2 \, \nabla c \cdot \nabla q ] \\ [ c \, \Delta p + p \, \Delta c + 2 \, \nabla c \cdot \Delta p ] - [ a \, \Delta r + r \, \Delta a + 2 \, \nabla a \cdot \nabla r ] \\ [ a \, \Delta q + q \, \Delta a + 2 \, \nabla a \cdot \Delta q ] - [ b \, \Delta p + p \, \Delta b + 2 \, \nabla b \cdot \nabla p ] \end{matrix} \right\}
\]
\end{document}

and invoking pdflatex on it…

pdflatex main.tex

After having played a little bit with the markdown source, I had the impression that if the line gets too long then markdown-here doesn't render it… Perhaps this is a limitation of google Chart ?

Problem doesn't occur with pandoc + mathjax

Previously, I have generated some *.html documents using pandoc. It uses mathjax instead of Google charts, and rendering the previous equation does not cause any issue at all!

To see it in action, create a doc.md file and fill it with

$$\Delta (u \times v ) = \left\{ \begin{matrix} [ b \, \Delta r + r \, \Delta b + 2 \, \nabla b \cdot \Delta r ] - [ c \, \Delta q + q \, \Delta c + 2 \, \nabla c \cdot \nabla q ] \\ [ c \, \Delta p + p \, \Delta c + 2 \, \nabla c \cdot \Delta p ] - [ a \, \Delta r + r \, \Delta a + 2 \, \nabla a \cdot \nabla r ] \\ [ a \, \Delta q + q \, \Delta a + 2 \, \nabla a \cdot \Delta q ] - [ b \, \Delta p + p \, \Delta b + 2 \, \nabla b \cdot \nabla p ] \end{matrix} \right\}$$

(Pandoc requires two dollar signs '$'). Then, transform it into a *.html file by invoking

pandoc --mathjax --standalone -o doc.md.html doc.md

Eventually open doc.md.html using your favorite web browser.

Also (smaller detail) pandoc + mathjax seems to handles the line breaks better. For instance the following text is a rewrite of the above equation with line breaks so as to make it much more human-readable.

$$
    \Delta (u \times v )
=
    \left\{
    \begin{matrix}
        [ b \, \Delta r + r \, \Delta b + 2 \, \nabla b \cdot \Delta r ]
    -
        [ c \, \Delta q + q \, \Delta c + 2 \, \nabla c \cdot \nabla q ]
    \\
        [ c \, \Delta p + p \, \Delta c + 2 \, \nabla c \cdot \Delta p ]
    -
        [ a \, \Delta r + r \, \Delta a + 2 \, \nabla a \cdot \nabla r ]
    \\
        [ a \, \Delta q + q \, \Delta a + 2 \, \nabla a \cdot \Delta q ]
    -
        [ b \, \Delta p + p \, \Delta b + 2 \, \nabla b \cdot \nabla p ]
    \end{matrix}
    \right\}
$$

It can be parsed properly by mathjax, whereas Google Charts requires '$' to be followed directly by a non-space character which makes the syntax a bit awkward :

$\Delta (u \times v )
=
    \left\{
    \begin{matrix}
        [ b \, \Delta r + r \, \Delta b + 2 \, \nabla b \cdot \Delta r ]
    \\
        c
    \end{matrix}
    \right\}$

When I look at the html source code that has been generated,

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <meta http-equiv="Content-Style-Type" content="text/css" />
  <meta name="generator" content="pandoc" />
  <title></title>
  <style type="text/css">code{white-space: pre;}</style>
  <script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"></script>
</head>
<body>
<p><span class="math display">\[\Delta (u \times v ) = \left\{ \begin{matrix} [ b \, \Delta r + r \, \Delta b + 2 \, \nabla b \cdot \Delta r ] - [ c \, \Delta q + q \, \Delta c + 2 \, \nabla c \cdot \nabla q ] \\ [ c \, \Delta p + p \, \Delta c + 2 \, \nabla c \cdot \Delta p ] - [ a \, \Delta r + r \, \Delta a + 2 \, \nabla a \cdot \nabla r ] \\ [ a \, \Delta q + q \, \Delta a + 2 \, \nabla a \cdot \Delta q ] - [ b \, \Delta p + p \, \Delta b + 2 \, \nabla b \cdot \nabla p ] \end{matrix} \right\}\]</span></p>
</body>
</html>

what pandoc has done is stupidly simple :

  1. It added a link to mathjax in the <head> section of the *.html file

    <script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"></script>
    
  2. It copied and pasted the Latex source code into a <span> block (and replaced the $$ [...] $$ tag by a \[ [...] \] tag)

    \[ [...] \]

What I did eventually : text + Unicode

Since I could not get Markdown-here to do what I wanted, and since I did not want to write my own html code (or to generate it through pandoc), I sent my e-mail in text form and used unicode to write my equations… For instance the previous line can be writen using unicode as:

         ⎧ [b.Δr + r.Δb + 2.∇b·∇r] - [c.Δq + qΔc + 2.Δc·∇q] ⎫
Δ(u×v) = ⎨ [c.Δp + p.Δc + 2.∇c·∇p] - [a.Δr + rΔa + 2.Δa·∇r] ⎬
         ⎩ [a.Δq + q.Δa + 2.∇a·∇q] - [b.Δp + pΔb + 2.Δb·∇p] ⎭

Summary

It seems Markdown-here cannot handle long formulas (to double-check), probably because Google Charts does not allow it (to double-check).

As you can see, the difficulty I encountered lead me to not use markdown-here at all, and to switch back to the good old text e-mail… Which is a shame because apart from that, I am very happy with your extension so far… (Actually, I love to use it to write minutes of meetings!)

I am not sure what the best solution could be:

  1. Keep using Markdown + google charts (i.e. do nothing)
  2. Use Markdown + mathjax (i.e. dump google charts) (or Katex?)
  3. Or allow the user to select the rendering service he/she would like to use?
  4. Some other solution?

Anyway many thanks for your work, that is a very useful extension you have made! ;) (even-though this corner case is causing me trouble…)

Cheers,

Gaël

@GLorieul
Copy link
Author

GLorieul commented Feb 2, 2017

A less extreme case is

$\Delta(a \times b)
~=~
    \Delta a \, \times \, b
~+~
    a \, \times \, \Delta b
+
    2.\sum_i
\left[
    \frac{\partial a_i}{\partial x_i}
\times
    \frac{\partial b_i}{\partial x_i}
\right]$

which can be rendered. This time, it is a fairly short equation. However, add 100 to it and it no longer renders:

$\Delta(a \times b)
~=~
    \Delta a \, \times \, b
~+~
    a \, \times \, \Delta b
+
    2.\sum_i
\left[
    \frac{\partial a_i}{\partial x_i}
\times
    \frac{\partial b_i}{\partial x_i}
\right] + 100$

although it renders if you only add 10 instead of 100…

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant