Hacker News new | past | comments | ask | show | jobs | submit login
Mdmath – LaTeX Math for Markdown inside of Visual Studio Code (github.com/goessner)
225 points by fango on Dec 20, 2016 | hide | past | favorite | 61 comments



I wonder if Pandoc being written in Haskell is what's stopping it from being the default Markdown engine everywhere. Or am I misunderstanding the technical needs here?


I tried to switch from markdown.pl to Pandoc and encountered some problems, one of which remains an open issue (https://github.com/jgm/pandoc/issues/1841): https://twitter.com/arntzenius/status/745946799836381184

A telling comment on that github issue is "Actually, it's a bit unclear what the behavior should be." I think the real problem is the idea of "a default Markdown engine" is pretty impossible when Markdown doesn't even have a formal spec. Complex human-readable formats without a spec are never gonna be compatible between different implementations without extraordinary effort. (Hence the http://commonmark.org/ effort, which I applaud, but doesn't seem to have a 1.0 spec out yet.)


That's sort of convincing me that Markdown + arbitrary HTML is a fundamentally unstable idea. What's the use case for it? GitHub allows a subset of HTML tags; sites like Reddit allow none.

I mean, I use Pelican's Markdown support in my own blog, but I wouldn't be unhappy about having to use <i> instead of underscores.


I use markdown for writing blog posts, and I need arbitrary HTML all the time. For tables; or for custom syntax highlighting; for drop-down menus that let readers choose what PL they want to see examples in (http://www.rntz.net/post/2016-06-06-not-everything-is-an-exp... ); to put the numbers on section headings into the left-margin; etc, etc.

Basically, markdown has (at least) two use-cases:

1. A safe (if you do HTML sanitization properly) way to let people mark-up their input on web comment sites like HN, StackOverflow, etc. This is probably the most common use-case.

2. A web authoring tool. This was the intended use-case.

Supporting arbitrary HTML is absolutely inadmissible for (1); not having arbitrary HTML is basically inexcusable for (2). And yeah, I could write the posts in straight HTML, but honestly that's a pain. Why shouldn't there be a tool that makes writing styled-text-with-lists-and-headings easy but lets me drop down to HTML when I need to?


Because intermixing Markdown and HTML is ambiguous, and if you're authoring HTML, you clearly know HTML already?

I'm not actually sure I believe this yet. But I think I'd see a lot more use case for something that lets me do a very tiny amount of things, maybe just headings and bold and italic, and avoids not only ambiguity but any risk of ambiguity.

It just feels like we've reinvented HoTMetaL (https://support.novell.com/techcenter/articles/img/ana199609...) but with bonus ambiguity.


Are you saying you shouldn't use HTML with markdown? Markdown was explicitly designed not to cover each and everything HTML, and so that you could fallback to HTML; it's kind of the entire point of markdown (or have I misunderstood you?).


> But I think I'd see a lot more use case for something that lets me do a very tiny amount of things, maybe just headings and bold and italic, and avoids not only ambiguity but any risk of ambiguity.

When you build that, let me know. Until then I'll be over here, using a Perl script from 2004 that still works just fine.


There's an easy compromise between (1) and (2): configurable bleaching.

I also use markdown for writing blog posts, and have a lot of the same pain points. I have been working on an extended version of markdown (https://github.com/alexbecker/blogdown) to fix this.


AFAIK the author of Pandoc is also a CommonMark core contributor.


Pandoc isn't used by this VSCode plugin, so I'm not sure why that's relevant? Generating a PDF from Pandoc depends on LaTeX, which is over 2GB. Definitely not a solution for "everywhere".

Also there are some arguably nicer alternatives to just shoving LaTeX syntax into markdown, for example http://asciimath.org.


LaTeX itself isn't over 2GB. The complete texlive distribution is about that large, but that's everything and the kitchen sink.

You can install a small base which comes in ~150mb, then add packages as you need.


and then 90 seconds later you'll find yourself running `sudo apt-get texlive-full` because some mysterious font somewhere is wedging up the gears and it's not worth sorting out.


Yeah, fair enough. On MacTeX or texlive on Arch, it usually takes me a few iterations of `tlmgr install` runs before I have everything I need. "collection-fontsrecommended" is usually the (meta) package I install these days.

I wish texlive would move to rolling updates, or at-least make distribution upgrades easier.


Arg, this reads like LaTeX without the backslashes and with minor inconsistencies. Why not just use a proper subset of LaTeX math notation instead of inventing yet another syntax?


Probably for the same reason that we don't create modern programming languages using a subset of FORTRAN syntax: because we can do better.

Note that one of the advantages of asciimath is that it maps unambiguously to MathML.


Because, sometime you don't need all the whistles, but only a subset.

Curious, what inconsistencies does asciimath have?


Oh man, this is PERFECT for me. Previously I would just run VS Code and periodically build my current markdown document while writing LaTeX in it, and have a browser window refresh on changes (using the LivePage addon for Chrome). This saves a lot of trouble for me, very excited!


Very awesome. However, the $ signs indicate financial stuff. It would be nice to have a different delimiter like the code blocks use back-tics. For example using back-ticks couple with single-quotes? It doesn't work since it clash with the code block just for example more legible:

`' x^2 + 4x + 4 '`

Remember: the whole idea behind markdown is it should be first and foremost* legible from plain-text. One idea behind typography is it shouldn't be noticed at all to the reader.


"$" ("$$" to be exact) is actually used in TeX to indicate opening and closing of statements/mathematical expressions. I think the author of this project is trying to conform to TeX syntax as much as possible so that TeX users like me would feel at home :).


>"$" ("$$" to be exact) is actually used in TeX to indicate opening and closing of statements/mathematical expressions.

Both are used. A single $ is used for inline math, the double $$ begins an equation on its own line. For example:

The solution to $ax^2 + bx + c = 0$ will be $$x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}$$

The first block will be mid-sentence, while the second one will get its own line.


The story is that Knuth chose '$' to denote math mode because math typesetting at the time was prohibitively expensive.


ahaha, that's a good piece of anecdote.


Ah, wasn't aware of that. Thanks. :)


Using $ and $$ is most legible for me. Having spent many years using TeX. Pandoc seems to do the same thing - I suspect for the same reasons. I usually patch this into markdown systems that I use. This is especially useful when you have have to talk about things like $x$ and $y$ and how $x^2+y^2=z^2$. In actual math documents, every third or forth word will be surrounded by $, it is almost like italics to mathematicians, and would be nice to be able to express it just as easily as italics.

I find it a lot more readable than the \( and \[ that LaTeX and other markdown systems use.

I believe gitbook uses just "$$", but this looses the distinction between inline and display math. (And there is a subtle difference between display math within a paragraph and display math between paragraphs, so you can't tell from context.)

I understand that some people will want to talk about money and having to escape $ could be incredibly annoying, but for actually writing math documents, this is kinda essential. So, to me, it feels like something that needs to be an optional add-on.


To the contrary, as someone who hasn't used TeX at all I find it somewhat hard to read the plain-text. The $$$ have more visual weight than the actual formulas.

Kind of interesting to see some alternatives and note the visual weight. The back-ticks are by far the best in my opinion. Too bad they are taken by the code blocks! Semicolons are nice though--kind of like a LISP comment.

@@ x^2 + 4x = 10 @@

%% x^2 + 4x = 10 %%

<< x^2 + 4x = 10 >>

$$ x^2 + 4x = 10 $$

`` x^2 + 4x = 10 ``

'' x^2 + 4x = 10 ''

"" x^2 + 4x = 10 ""

;; x^2 + 4x = 10 ;;

\\ x^2 + 4x = 10 //

?? x^2 + 4x = 10 ??


MathJax by default doesn't use $ as a delimiter for inline equations, but instead uses \( and \) to avoid confusion with monetary quantities. Perhaps a similar thing could be done.


Off the top of my head, I feel that using that syntax would increase the chances that you would run into issues trying to differentiate between escaped characters and expressions, though it's an interesting recommendation (and if MathJax has been able to make it work, I'm sure it's feasible).


I am theoretically a big fan of the (not yet existing) Markua math format from leanpub: https://leanpub.com/markua/read#math

The inline math syntax is `x^2 + 4x +4`$ so the dollar sign is outside the backticks, but the formula is encapsulated in the code.

For a display block, they use the code fences with either latex or $ as a math toggle:

```latex

\psi = \frac{5 \phi}{\omega}

```

or

```$

\psi = \frac{5 \phi}{\omega}

```

At some point soon, I intend to implement this for my own use. It should be pretty easy using a markdown parser assuming one can do a lookahead/gobbler to the next character after the inline backticks.


For exactly that reason, we used $$(inline expression) and $$$(block expression) for the KaTeX delimiters in a web-based Markdown editor that I worked on.

Originally we used the "standard" single $ delimiter but would run into problems when someone's content included a string like, "...between $190 and $200...". It wasn't elegant, but saved a lot of complicated parsing to look for whitespace or other implicit indications of what the author was trying to do.


I have looked into markdown editors a lot, and the best I found was this plugin for Atom:

https://github.com/shd101wyy/markdown-preview-enhanced

I know Atom kind of sucks, but this plugin is amazing. Mostly because it supports PlantUML which is also amazing.

Highly recommended.


> I know Atom kind of sucks

I've tried really hard to like Atom. It's a shame that 'modern open-source configurable' seems to mean 'Electron app' (cf. Hyper) - I'm convinced it's not the best in terms of potential, but since that's where the collective effort, it seems unfortunately the best available.

(I revert to vim after getting fed up with Atom, I just can't help feeling that better could be achieved by forgetting legacy platforms and backwards compatibility - I'll try Kakoune if it stops being called the author's "experiment" and gets versioned releases.)


Couldn’t you just write your “LaTeX Math” for LaTeX instead?


As I see it, it is more for "I just wrote/ended up with this code doing a complex math equation. But I just can't read it even with all these comments." cases.


This is really cool for quick things, but for anything short of quick notes, I don't want to have to manually number my equations. I generally don't write top-to-bottom, I write subsections at a time.

Labels seem straightforward enough, but I'm at a loss for a markdown-y way to do a ref.

$$\exist 0 \in R \mathrm{s.t.} a + 0 = a \forall a \in R$$ (eqn:addid)

In addition to a zero as per (*eqn:addid), one must also show the existence of an inverse.

It's decent, but I don't love it. And further overloading the splat will be miserable.


Oh wow! Man this is so rad. This can help me kick my dependence on Typora / Dropbox Paper for class notes and continue the VSCode loving.


I've been using the free-tier of Classeur [1] for taking notes during class, which I then export to a PDF. It's basically an online Math/Mardown editor with pretty much the same feature-set.

Maybe I'll try this out and see how I like it.

[1] http://classeur.io/



This is wonderful. However, I always loved markdown because of its being so simple and fast.

Isn't Latex Turing-Complete?


TeX has \def which basically allows you to write lambda expressions, so yeah it's Turing complete. The basic math notation isn't though, and I'd be surprised if this extension allows you to use \def (or really any of the more powerful features of TeX).


If it's using the full selection of functions available to KaTeX, here's the list:

https://github.com/Khan/KaTeX/wiki/Function-Support-in-KaTeX

\def isn't included in the core set, from what I can see.


Being turing-complete doesn't prevent you from emulating it. Also the subset of math expressions should be pretty simple.


Surprised I haven't seen anyone post Markdeep here yet: https://casual-effects.com/markdeep/

Seems to cover a lot of the same ground, though it's not restricted to visual studio code.


I really wish the author had chosen asciidoc which has well defined semantics for latex math incorporation and also supports asciimath


That's neat, but I managed to do something similar (except for the graphics, I haven't tried that) with Markdown + Mathjax.


As I understand it, this is basically that; except with Khan Academy's KaTeX library instead (it's got ridiculously fast rendering compared to MathJax).


Is there a latex editor that can show the end product side by side while you're writing the document?


Both http://sharelatex.com and http://overleaf.com support that by re-rendering a pdf preview as you make changes. Overleaf also has a WYSIWYG editor with inline latex, although I find it doesn't work for everything.


The best WYSIWYG LaTeX I've come across is http://mathquill.com


If you press and hold `/`, that's a Christmas tree generator.


https://en.wikipedia.org/wiki/Comparison_of_TeX_editors

look for the wysiwyg tag ( read note 1: https://en.wikipedia.org/wiki/Comparison_of_TeX_editors#cite...)

There is also the 'Integrated viewer' column with notes on live/instant updates.


Yes you should get Atom (ugh I know, but it is worth it for this extension), and Markdown Preview Enhanced:

https://github.com/shd101wyy/markdown-preview-enhanced

I have looked into markdown editors a lot, and this is the best by far. It supports Latex, PlantUML, images, Graphviz, and some more stuff.


https://cloud.sagemath.com/ has one of the best online latex editors I've seen. It has live preview and you can jump from source to the right position in the end product, and vis-versa. It's definitely worth checking out!


Texmaker is pretty close. It doesn't update live, but I've never actually needed that capability. Tons of other useful features too. No affiliation, I just use it a lot.

http://www.xm1math.net/texmaker/


Gummi[0] is a really great one for Linux users. It's simple and stays out of your way. It live-updates as you type.

0: https://github.com/alexandervdm/gummi


Bakoma TeXWord does exactly that.

http://www.bakoma-tex.com/


Overleaf.com is an online site that works that way.


lyx + instant preview, perhaps?


Nitpick: Title should indicate VSCode


Can someone do this for atom?


i would appreciate something like this for Atom.


doesn't understand \boldsymbol :/




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: