# TextMate + MultiMarkDown + MathJax: The Perfect Combo for Leanpub Authros

Leanpub is a great publishing platform for independent authors. However first time authors often struggle deciding on the right editor, especially because leanpub uses markdown encoding. After hours of googling, I failed to find any perfect editor. In particular I was looking for a simple editor but had two major requirements:

1. I haven’t used markdown syntax much before and wanted an editor that has live preview option.
2. I often deal with equations and therefore needed an editor that can support latex based equation and show them in live preview without I personally moving the files around.

After googling for almost a day, I failed to find the perfect editor. But I managed to build one by using  the combination of TextMate, Multimarkdown and MathJax. You might want to see this video to get excited about my solution.

Below are the steps you need to carry out in order to get the TextMate based solution working.

Step 1: Install Multimarkdown: From your terminal, run the following command. I am assuming that you are familiar with homebrew. If not, read more about it over here
brew install multimarkdown

Step 2: Install Markdown TextMate bundle
b. Unzip and rename the top level folder to “markdown.tmbundle”
c. Double click on it and it should be installed in TextMate.

Step 3: Update TextMate Path Variable:
a. Start TextMate and go to TextMate > Preferences > Advanced Tab
b. Edit Path variable and add /usr/local/bin: as the first thing (Make sure that you don’t delete other paths)

Step 4. Install MathJax
b. Open Mac System Preferences. Click on “Sharing” icon and switch on “Web Sharing”.
c. On the right side, you will see an option to “Create Personal Website Folder”. Click that button. This will create a folder named “Sites” in your home directory.
d. Unzip and move MathJax folder to the above created (~/Sites) folder.
e. Test whether MathJax is properly installed by going to the following address: “http://127.0.0.1/~CHANGE_TO_USERNAME/Mathjax/test/index.html&#8221;

Step 5. Test Live Preview of Markdown and Equation Support
a. Download the sample file and open it using TextMake. Make sure that the langugage setting is set to “Multimarkdown”. If not, change it to “Multimarkdown”.
b. From TextMate Menu bar, select Windows > Show Web Preview. You should see nicely formatted output along with the equation.
c. Now try modify to the modify content of the downloaded sample file and you will notice that the web preview automatically refreshes.

Voila!!!

Questions:
1. What is there Xhtml header and what’s its doing ?
The Xhtml header at the top of the sample file calls the MathJax library. Also it modifies the equation tag from $$to {$$}. I did that mainly because leanpub requires that equations are enclosed by {$$} and {/$$}.

Make sure you have appended path variable in TextMate. See step 3b

3. Equations are not being rendered correctly
Make sure that Mathjax is correctly installed by going to “http://127.0.0.1/~USERNAME/Mathjax/test/index.html&#8221;. If this is working, then make sure that you have correct path in the script tag of sample file.

4. My computer is on fire!! and is starting to run very slow
Change the refresh rate in preview. If you set it 0.0 seconds that TextMate web preview will call MathJax after you add even a single character. I generally set it to 500 seconds when I am focusing on writing and change it to 0.5 seconds if I am working on formatting issues.

## One thought on “TextMate + MultiMarkDown + MathJax: The Perfect Combo for Leanpub Authros”

1. Pil says:

Oh gee! This is so perfectly written article that I cannot help leaving a comment. Thanks a lot. Great helps.