# Markdown + Mathjax => PDF [closed]

I've used LaTeX a lot in the past, but now (thanks to StackOverflow's great editor!), I find it annoying/boring, for short documents (< 2 pages), to have to use pure LaTeX.

For a short document, instead of having 30 lines as introduction:

\begin{document}
\documentclass[11pt,a4paper]{article}
\usepackage[frenchb]{babel}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amsfonts} + <lots of other things>


I'd like to write my short document with MarkDown + Math, like on math.stackexchange.com.

# Question:

Is there an offline compiler such that

compilemarkdown exercice.tex


would produce a PDF from this:

#Title

Here is a *short document* including Markdown and Math, here is the equation:

$$f(x)=x^2$$

___

Proof: ...

This is **bold**.

-

## closed as off-topic by Martin Schröder, Papiro, Maarten Dhondt, Jesse, Christian HupferFeb 14 at 17:00

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "This question does not fall within the scope of TeX, LaTeX or related typesetting systems as defined in the help center." – Martin Schröder, Papiro, Maarten Dhondt, Jesse, Christian Hupfer
If this question can be reworded to fit the rules in the help center, please edit the question.

Well, not a solution, but many LaTeX editors allow to use templates. So you can create one and then just open it. I created one and then I just call it on Linux terminal fastex and the editor opens with my minimal template. – Sigur Feb 1 at 19:50
@Sigur I already use templates, but this is not really a solution. To sum up the idea : now that I'm used to mix Markdown and Latex/Mathjax (thanks StackExchange!), I really want to have this great way of writing short documents offline. No more 30 lines of \usepackage[frenchb]{babel} \usepackage[latin1]{inputenc}... I want to keep the goodness of StackEdit / StackExchange's editor offline, as a compiler like latex. – Basj Feb 1 at 19:54
try pandoc's new non-latex pdf generation. – erreka Feb 1 at 20:00
@Basj Okay, I think pandoc will work for you then. I've posted an answer that uses pandoc. – Null Feb 1 at 20:04
Why would you want to do this in LaTeX? There is a ton of markdown editors which do exactly that. You write markdown + mathjax, then export as either PDF or LaTeX. There are cloud solutions, Windows solutions, Linux solutions... – rumtscho Feb 2 at 9:15

## 3 Answers

This is possible with pandoc. If the Markdown you've posted is in the file test.md you can generate a PDF called test.pdf with the following command:

pandoc test.md -o test.pdf


The PDF file looks like this:

pandoc converts the Markdown to a PDF using LaTeX. It recognizes that the input is Markdown from the file extension, but if you use a different file extension you can include -f markdown to instruct pandoc to convert from Markdown. The -o test.pdf part of the command tells pandoc to output a PDF with the given filename.

The pandoc website has a nice getting started guide.

-
Really really nice. Installed and already working! This is really LaTeX's future. I will always use this for small documents now! Wonderful. – Basj Feb 1 at 20:09
@Basj Glad to hear you like it! – Null Feb 1 at 20:12
If someone has a SublimeText .sublime-build build system file to share, I'm in heaven :) – Basj Feb 1 at 20:14

I'd use RedNotebook for notes and small documents. It's really a journal or diary, but it lets me to take quick notes with (modified) markdown and MathJax (with webkit), and then, if necessary, to export to html or pdf or LaTeX.

If I type:

= Title =

Here is a //short document// including Markdown and Math, here is the equation:

$$f(x)=x^2$$

====================

Proof: ...

This is **bold**.


I get this (edition mode):

and this (preview):

Then you export to pdf, which looks like this:

(Output font can be changed from Preferences).

-
Nice as well! Thanks. – Basj Feb 1 at 20:14

What I meant by my original comment is this: with pandoc -t html5 -o test.pdf test.md you can bypass LaTeX entirely; you are only required to install wkhtmltopdf, which is a single executable like pandoc on windows.

Results as follows:

You may control the output with css.

-