{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "**WARNING: This document will not render correctly using nbviewer or nbconvert. To render this notebook correctly, open in `IPython Notebook` and run `Cell->Run All` from the menu bar.**" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Introduction" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The IPython Notebook allows Markdown, HTML, and inline LaTeX in *Mardown Cells*. The inline LaTeX is parsed with [MathJax](http://www.mathjax.org/) and Markdown is parsed with [marked](https://github.com/chjj/marked). Any inline HTML is left to the web browser to parse. NBConvert is a utility that allows users to easily convert their notebooks to various formats. Pandoc is used to parse markdown text in NBConvert. Since what the notebook web interface supports is a mix of Markdown, HTML, and LaTeX, Pandoc has trouble converting notebook markdown. This results in incomplete representations of the notebook in nbviewer or a compiled Latex PDF.\n", "\n", "This isn't a Pandoc flaw; Pandoc isn't designed to parse and convert a mixed format document. Unfortunately, this means that Pandoc can only support a subset of the markup supported in the notebook web interface. This notebook compares output of Pandoc to the notebook web interface.\n", "\n", "**Changes:**\n", "\n", "05102013\n", "\n", " * heading anchors\n", " * note on remote images\n", "\n", "06102013\n", "\n", " * remove strip_math_space filter\n", " * add lxml test\n", " \n", "" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Utilities" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Define functions to render Markdown using the notebook and Pandoc." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from IPython.nbconvert.utils.pandoc import pandoc\n", "from IPython.display import HTML, Javascript, display\n", "\n", "from IPython.nbconvert.filters import citation2latex, strip_files_prefix, \\\n", " markdown2html, markdown2latex\n", "\n", "def pandoc_render(markdown):\n", " \"\"\"Render Pandoc Markdown->LaTeX content.\"\"\"\n", " \n", " ## Convert the markdown directly to latex. This is what nbconvert does.\n", " #latex = pandoc(markdown, \"markdown\", \"latex\")\n", " #html = pandoc(markdown, \"markdown\", \"html\", [\"--mathjax\"])\n", " \n", " # nbconvert template conversions\n", " html = strip_files_prefix(markdown2html(markdown))\n", " latex = markdown2latex(citation2latex(markdown))\n", " display(HTML(data=\"
\"\\\n", " \"\" + latex + \"
\\section{Heading 1}\n", "\n", "\\subsection{Heading 2}\n", "\n", "\\subsubsection{Heading 3}\n", "\n", "\\paragraph{Heading 4}\n", "\n", "\\subparagraph{Heading 5}\n", "\n", "Heading 6
\\section{Heading 1}\n", "\n", "\\subsection{Heading 2}\n", "\n", "\\subsubsection{Heading 3}\n", "\n", "\\paragraph{Heading 4}\n", "\n", "\\subparagraph{Heading 5}\n", "\n", "Heading 6
\\href{http://127.0.0.1:8888/0a2d8086-ee24-4e5b-a32b-f66b525836cb\\#General-markdown}{Link2Heading}
This is Markdown \\textbf{bold} and \\emph{italic} text.
This is Markdown bold and italic text.
\\begin{itemize}\n", "\\itemsep1pt\\parskip0pt\\parsep0pt\n", "\\item\n", " li 1\n", "\\item\n", " li 2\n", "\n", " \\begin{enumerate}\n", " \\def\\labelenumi{\\arabic{enumi}.}\n", " \\itemsep1pt\\parskip0pt\\parsep0pt\n", " \\item\n", " li 3\n", " \\item\n", " li 4\n", " \\end{enumerate}\n", "\\item\n", " li 5\n", "\\end{itemize}
überschuß +\\emph{*}\\^{}°³³ α β θ
überschuß +*^°³³ α β θ
\\section{Heading 1 \\sout{strikeout}}
above\n", "\n", "\\begin{center}\\rule{3in}{0.4pt}\\end{center}\n", "\n", "below
above
\n", "below
This is Markdown \\textsubscript{subscript} and\n", "\\textsuperscript{superscript} text.
This is Markdown subscript and superscript text.
This is Markdown not\\_italic\\_.
This is Markdown not_italic_.
\\newcommand{\\tuple}[1]{\\langle #1 \\rangle}\n", "\n", "$\\tuple{a, b, c}$
\\(\\langle a, b, c \\rangle\\)
$\\newcommand{\\foo}[1]{...:: #1 ::...}$ $\\foo{bar}$
\\(\\newcommand{\\foo}[1]{...:: #1 ::...}\\) \\(\\foo{bar}\\)
This is HTML bold and italic text.
This is HTML bold and italic text.
Center aligned
This is \\LaTeX \\bf{bold} and \\emph{italic} text.
This is
\\textbf{foo} $\\left( \\sum_{k=1}^n a_k b_k \\right)^2 \\leq$ b\\$ar \\[test\\]\n", "\\cite{}
foo \\(\\left( \\sum_{k=1}^n a_k b_k \\right)^2 \\leq\\) b$ar \\[test\\]
a | \\nb | \\n
c | \\nd | \\n
a\n", "\n", "b\n", "\n", "c\n", "\n", "d
\n", "a\n", " | \n", "\n", "b\n", " | \n", "
\n", "c\n", " | \n", "\n", "d\n", " | \n", "
a | \n", "b | \n", "
c | \n", "d | \n", "
\\begin{longtable}[c]{@{}ll@{}}\n", "\\hline\\noalign{\\medskip}\n", "\\begin{minipage}[t]{0.06\\columnwidth}\\raggedright\n", "a\n", "\\end{minipage} & \\begin{minipage}[t]{0.06\\columnwidth}\\raggedright\n", "b\n", "\\end{minipage}\n", "\\\\\\noalign{\\medskip}\n", "\\begin{minipage}[t]{0.06\\columnwidth}\\raggedright\n", "c\n", "\\end{minipage} & \\begin{minipage}[t]{0.06\\columnwidth}\\raggedright\n", "d\n", "\\end{minipage}\n", "\\\\\\noalign{\\medskip}\n", "\\hline\n", "\\end{longtable}
a | \n",
"b | \n",
"
c | \n",
"d | \n",
"
\\begin{longtable}[c]{@{}lcr@{}}\n", "\\hline\\noalign{\\medskip}\n", "Left & Center & Right\n", "\\\\\\noalign{\\medskip}\n", "\\hline\\noalign{\\medskip}\n", "Text1 & Text2 & Text3\n", "\\\\\\noalign{\\medskip}\n", "\\hline\n", "\\end{longtable}
Left | \n", "Center | \n", "Right | \n", "
---|---|---|
Text1 | \n", "Text2 | \n", "Text3 | \n", "
\\begin{longtable}[c]{@{}lll@{}}\n", "\\hline\\noalign{\\medskip}\n", "Right Aligned & Center Aligned & Left Aligned\n", "\\\\\\noalign{\\medskip}\n", "\\hline\\noalign{\\medskip}\n", "Why & does & this\n", "\\\\\\noalign{\\medskip}\n", "actually & work? & Who\n", "\\\\\\noalign{\\medskip}\n", "knows & \\ldots{} &\n", "\\\\\\noalign{\\medskip}\n", "\\hline\n", "\\end{longtable}
Right Aligned | \n", "Center Aligned | \n", "Left Aligned | \n", "
---|---|---|
Why | \n", "does | \n", "this | \n", "
actually | \n", "work? | \n", "Who | \n", "
knows | \n", "... | \n", "\n", " |
\\begin{figure}[htbp]\n", "\\centering\n", "\\includegraphics{http://ipython.org/_static/IPy_header.png}\n", "\\caption{Alternate Text}\n", "\\end{figure}
My equation: \\[ 5/x=2y \\]\n", "\n", "It is inline \\$ 5/x=2y \\$ here.
My equation: \\[ 5/x=2y \\]
\n", "It is inline $ 5/x=2y $ here.
$5 \\cdot x=2$\n", "\n", "\\$ 5 \\cdot x=2\\$\n", "\n", "\\$ 5 \\cdot x=2 \\$
\\(5 \\cdot x=2\\)
\n", "$ 5 x=2$
\n", "$ 5 x=2 $
\\begin{align}\n", "a & b\\\\\n", "d & c\n", "\\end{align}\n", "\n", "\\begin{eqnarray}\n", "a & b \\\\\n", "c & d\n", "\\end{eqnarray}
14 is false.\n", "\n", "$14$ is false.\n", "\n", "1
1<2 is true, but 3>4 is false.
\n", "\\(1<2\\) is true, but \\(3>4\\) is false.
\n", "1<2 it is even worse if it is alone in a line.
some source code\n", "\n", "\\begin{verbatim}\n", "a = \"test\"\n", "print(a)\n", "\\end{verbatim}
some source code
\n", "a = "test"\n",
"print(a)
some source code\n", "\n", "\\begin{Shaded}\n", "\\begin{Highlighting}[]\n", "\\NormalTok{a = }\\StringTok{\"test\"}\n", "\\KeywordTok{print}\\NormalTok{(a)}\n", "\\end{Highlighting}\n", "\\end{Shaded}
some source code
\n", "a = "test"\n",
"print(a)