Writing documents with math equations in WM

181 views
Skip to first unread message

Venki Phy6

unread,
Apr 27, 2016, 12:45:01 PM4/27/16
to Writemonkey
The Markdown flavors available in WM, as you might know, don't support Mathjax style math equations. I was kinda disappointed by it because I just loved the Zen like distraction free environment and the awesome Pomodoro plugin of WM. I just couldn't leave WM just because of a single feature not being available! So I set out to find a workaround and I did!

It is actually pretty simple, but since I am not from a computer science background it took me sometime to figure it out. Anyways, here is what you do:-

1. Install Pandoc. Pandoc is like "Mystique" - can change from any format and to any format you want(.pdf, .opml, .html, .latex ...). I really mean it - ANY format.
2. Learn Pandoc markdown syntax. You can either read the documentation here or have a look at this cheatsheet. (It is very simple. In fact that seems to be the whole point of markdown - to be simple!)
3. Then have a look at this SE thread which is pretty much a cheatsheet for how to write equations in MathJax. 
4. Now just write in Pandoc markdown in WM and save as .md as usual. 
5. Now use Pandoc, by following the instructions here, to convert to whatever format you want! All your equations will show up beautifully! You can even change to .latex if you so desire!
6. Now it might be irritating to convert your source every time to check if everything is formatted properly. For this you can use Markmon previewer(click the link for install instructions).
7. After installing Markmon just go to your command line, change your directory to wherever you stored your .md file and type in :-

markmon "filename.md" --command "pandoc --mathjax -N -t HTML5" --port 3000

8. Now just open your internet browser and in your address bar type in:- localhost:3000 
9. Your document will be live previewed! 

That is it! From now on you can just type in Pandoc markdown in WM, preview it in Markmon(from your browser) and change your .md to whatever format you want to with Pandoc. If you want to automate things a bit, maybe write a script for the markmon command!

Hope it helps you!

Venki Phy6

unread,
May 3, 2016, 5:18:01 AM5/3/16
to Writemonkey
So I have been playing around a little more and found a way to include jumps for all the mathjax formulae! 

For inline formulae:
1. In WM go to Preferences>Jumps  
2. Select add and name it as "Inline formulae"(or any other name you want to give). 
3. Now add the following regular expression(which cleverly uses lookarounds): 
((?<!\$)\$(?!\$))(.+?)(?(1)(?<!\$)\1(?!\$))

Now all your inline formulae can be seen in your Jumps window under "Inline Formulae". 

For display formulae(i.e formulae not shown within a line but separately) you can use the jumps name "Display formulae" and the expression:
(?<!\$)\$\$(?!\$))(.+?)(?(1)(?<!\$)\1(?!\$))

I actually found this in this SE thread (it has some mistakes which I have corrected and given above). 

Also in Pandoc markdown syntax, unfortunately, this,
// Comment
is not considered a comment! So it just shows up in your output! Instead you can use the comments syntax as:
[//]: # Comment
This is not just specific to Pandoc but applies to many parsers atleast according to this another SE thread. Therefore if you like to write comments in your documents, write it with the above syntax and if you also want to view it in your Jumps, go to the Jumps tab in the Preferences menu again and the Edit the regex of the Comments jump as: 
^//.+?\n$|\[\/\/\]: # .+
As you can see I have just added an alternative expression to match rather than removing the original expression so that you can write comments both way and see it in the jumps(but remember that Pandoc will show comments followed by a '//' in your output!).

Now I am looking around if I can somehow change syntax highlighting for the formulae. I will try it and get back if I make nay progress. Any help is appreciated.


 
Reply all
Reply to author
Forward
0 new messages