Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I mix LaTeX in with Markdown? [closed]

People also ask

Can you use LaTeX in markdown?

Mathematical formulaWe can use LaTeX to write mathematical equations in Markdown. To write inline LaTeX formula use a single $ before and after the equation and use a double $ to display equations.

Should I learn LaTeX or markdown?

Markdown is the better approach. much simpler syntax; not only is it easier to learn, but it makes the actual typing much more smooth and efficient (especially in regards to citations, in-text formatting, links, figures)

How do you write formulas in markdown?

To insert in-line math use the $ symbol within a Markdown cell. For example, the text $this_{is}^{inline}$ will produce: t h i s i s i n l i n e .

Does Jekyll support LaTeX?

Jekyll and MathJax do not offer all of the functionality of LaTeX—there is no support for the LaTeX usepackage command, so only the core LaTeX functionality that has been ported to MathJax is available.


Have you tried with Pandoc?

EDIT:

Although the documentation has become a bit complex, pandoc has supported inline LaTeX and LaTeX templates for 10 years.

Documents like the following one can be written in Markdown:

---
title: Just say hello!
author: My Friend
header-includes: |
    \usepackage{tikz,pgfplots}
    \usepackage{fancyhdr}
    \pagestyle{fancy}
    \fancyhead[CO,CE]{This is fancy}
    \fancyfoot[CO,CE]{So is this}
    \fancyfoot[LE,RO]{\thepage}
abstract: This is a pandoc test with Markdown + inline LaTeX
---

Just say hello!
===============

This could be a good example or inlined \LaTeX:

\begin{tikzpicture}
\begin{axis}
\addplot[color=red]{exp(x)};
\end{axis}
\end{tikzpicture}
%Here ends the furst plot
\hskip 5pt
%Here begins the 3d plot
\begin{tikzpicture}
\begin{axis}
\addplot3[
    surf,
]
{exp(-x^2-y^2)*x};
\end{axis}
\end{tikzpicture}

And now, just a few words to terminate:

> Goodbye folks!

Which can be converted to LaTeX using commands like this: pandoc -s -i Hello.md -o Hello.tex

Following is an image of the converted Hello.md to Hello.pdf file using MiKTeX as LaTeX processor with the command: pandoc -s -i Hello.md -o Hello.pdf

enter image description here

Finally, there are some open source LaTeX templates like this one: https://github.com/Wandmalfarbe/pandoc-latex-template, that can be used for better formatting.

As always, the reader should dig deeper if he has less trivial use cases than presented here.


Perhaps mathJAX is the ticket. It's built on jsMath, a 2004 vintage JavaScript library.

As of 5-Feb-2015 I'd switch to recommend KaTeX - most performant Javascript LaTeX library from Khan Academy.


Add the following code to the top of your Markdown files to get MathJax rendering support

<style TYPE="text/css">
code.has-jax {font: inherit; font-size: 100%; background: inherit; border: inherit;}
</style>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
    tex2jax: {
        inlineMath: [['$','$'], ['\\(','\\)']],
        skipTags: ['script', 'noscript', 'style', 'textarea', 'pre'] // removed 'code' entry
    }
});
MathJax.Hub.Queue(function() {
    var all = MathJax.Hub.getAllJax(), i;
    for(i = 0; i < all.length; i += 1) {
        all[i].SourceElement().parentNode.className += ' has-jax';
    }
});
</script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.4/MathJax.js?config=TeX-AMS_HTML-full"></script>

and then `$x^2$` or `$$x^2$$` will render as expected :-)

You can always install a local version of MathJax if you don't want to use the online distribution, but you might need to host it through a local webserver.

UPDATE: these days I just use pandoc instead of canonical markdown, but the above is still useful.


I'll answer your question with a counter-question...

What do you think of Org-mode? It's not as pure as Markdown, but it is Markdown-like, and I find it as easy to work with, and it allows embedding of Latex. Cf. http://www.gnu.org/software/emacs/manual/html_node/org/Embedded-LaTeX.html

Postscript

In case you haven't looked at org-mode, it has one great strength as a general purpose "natural markup language" over Markdown, namely its treatment of tables. The source:

| 1 | 0 | 0 |
| -1 | 1 | 0 |
| -1 | -1 | 1 |

represents just what you think it will...

And the Latex is rendered in pieces using tex-mode's preview-latex.


you should look at multimarkdown http://fletcherpenney.net/multimarkdown/

it has support for metadata (headers, keywords, date, author, etc), tables, asciimath, mathml, hell i'm sure you could stick latex math code right in there. it's basically an extension to markdown to add all these other very useful features. It uses XSLT, so you can easily whip up your own LaTeX styles, and have it directly convert. I use it all the time, and I like it a lot.

I wish the markdown would just incorporate multimarkdown. it would be rather nice.

Edit: Multimarkdown will produce html, latex, and a few other formats. html can come with a style sheet of your choice. it will convert into MathML as well, which displays in Firefox and Safari/Chrome, if I remember correctly.


RStudio has a good free IDE that allows for Markdown and LaTeX.


kramdown does exactly what you describe:

https://kramdown.gettalong.org/syntax.html#math-blocks

And it's way more reliable and well-defined than Markdown.