14

I've used LaTeX a lot in the past, but now, when comparing with StackExchange's great editor, I find it tedious, 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 https://math.stackexchange.com/questions/ask.

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**.
12
  • 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
    Commented Feb 1, 2016 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
    Commented Feb 1, 2016 at 19:54
  • 2
    try pandoc's new non-latex pdf generation.
    – jarnosc
    Commented Feb 1, 2016 at 20:00
  • 1
    @Basj Okay, I think pandoc will work for you then. I've posted an answer that uses pandoc.
    – Null
    Commented Feb 1, 2016 at 20:04
  • 2
    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
    Commented Feb 2, 2016 at 9:15

3 Answers 3

34

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:

enter image description here

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.

4
  • Really really nice. Installed and already working! This is really LaTeX's future. I will always use this for small documents now! Wonderful.
    – Basj
    Commented Feb 1, 2016 at 20:09
  • 1
    @Basj Glad to hear you like it!
    – Null
    Commented Feb 1, 2016 at 20:12
  • If someone has a SublimeText .sublime-build build system file to share, I'm in heaven :)
    – Basj
    Commented Feb 1, 2016 at 20:14
  • If the markdown is based on Jekyll and has used some plugins, is this method still work? I have tried a simple case to convert my vita.md page yet failed. Commented Jan 18, 2017 at 5:36
4

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):

Editor

and this (preview):

Preview

Then you export to pdf, which looks like this:

PDF output

(Output font can be changed from Preferences).

0
3

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:

Result with wkhtmltopdf, without LaTeX

You may control the output with css.

1
  • this should be a good answer! Commented Mar 23 at 6:57

Not the answer you're looking for? Browse other questions tagged .