Skip to content

Instantly share code, notes, and snippets.

@jdfreder
Last active December 24, 2015 02:59
Show Gist options
  • Save jdfreder/6734825 to your computer and use it in GitHub Desktop.
Save jdfreder/6734825 to your computer and use it in GitHub Desktop.
Notebook that compares the Markdown output of Pandoc to the IPython Notebook.
Display the source blob
Display the rendered blob
Raw
{
"metadata": {
"name": ""
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"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": "heading",
"level": 1,
"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",
"<style>\n",
" .rendered_html xmp { \n",
" white-space: pre-wrap;\n",
" }\n",
"</style>"
]
},
{
"cell_type": "heading",
"level": 2,
"metadata": {},
"source": [
"Utilities"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Define functions to render Markdown using the notebook and Pandoc."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"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=\"<div style='display: inline-block; width: 30%; vertical-align: top;'>\" \\\n",
" \"<div style='background: #AAFFAA; width: 100%;'>NBConvert Latex Output</div>\" \\\n",
" \"<pre class='prettyprint lang-tex' style='background: #EEFFEE; border: 1px solid #DDEEDD;'><xmp>\" + latex + \"</xmp></pre>\"\\\n",
" \"</div>\" \\\n",
" \"<div style='display: inline-block; width: 2%;'></div>\" \\\n",
" \"<div style='display: inline-block; width: 30%; vertical-align: top;'>\" \\\n",
" \"<div style='background: #FFAAAA; width: 100%;'>NBViewer Output</div>\" \\\n",
" \"<div style='display: inline-block; width: 100%;'>\" + html + \"</div>\" \\\n",
" \"</div>\"))\n",
" javascript = \"\"\"\n",
" $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n",
"\"\"\"\n",
" display(Javascript(data=javascript))\n",
"\n",
"def notebook_render(markdown):\n",
" javascript = \"\"\"\n",
"var mdcell = new IPython.MarkdownCell();\n",
"mdcell.create_element();\n",
"mdcell.set_text('\"\"\" + markdown.replace(\"\\\\\", \"\\\\\\\\\").replace(\"'\", \"\\'\").replace(\"\\n\", \"\\\\n\") + \"\"\"');\n",
"mdcell.render();\n",
"$(element).append(mdcell.element)\n",
".removeClass()\n",
".css('left', '66%')\n",
".css('position', 'absolute')\n",
".css('width', '30%')\n",
"mdcell.element.prepend(\n",
" $('<div />')\n",
" .removeClass()\n",
" .css('background', '#AAAAFF')\n",
" .css('width', '100 %')\n",
" .html('Notebook Output')\n",
"\n",
");\n",
"container.show()\n",
"\"\"\"\n",
" display(Javascript(data=javascript))\n",
"\n",
" \n",
"def pandoc_html_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",
" \n",
" # Convert the pandoc generated latex to HTML so it can be rendered in \n",
" # the web browser.\n",
" html = pandoc(latex, \"latex\", \"html\", [\"--mathjax\"])\n",
" display(HTML(data=\"<div style='background: #AAFFAA; width: 40%;'>HTML Pandoc Output</div>\" \\\n",
" \"<div style='display: inline-block; width: 40%;'>\" + html + \"</div>\"))\n",
" return html\n",
" \n",
"def compare_render(markdown):\n",
" notebook_render(markdown)\n",
" pandoc_render(markdown)"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 1
},
{
"cell_type": "heading",
"level": 1,
"metadata": {},
"source": [
"Outputs"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"try:\n",
" import lxml\n",
" print 'LXML found!'\n",
"except:\n",
" print 'Warning! No LXML found - the old citation2latex filter will not work'"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"LXML found!\n"
]
}
],
"prompt_number": 1
},
{
"cell_type": "heading",
"level": 2,
"metadata": {},
"source": [
"General markdown"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Heading level 6 is not supported by Pandoc."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"compare_render(r\"\"\"\n",
"\n",
"# Heading 1 \n",
"## Heading 2 \n",
"### Heading 3 \n",
"#### Heading 4 \n",
"##### Heading 5 \n",
"###### Heading 6\"\"\")"
],
"language": "python",
"metadata": {},
"outputs": [
{
"javascript": [
"\n",
"var mdcell = new IPython.MarkdownCell();\n",
"mdcell.create_element();\n",
"mdcell.set_text('\\n\\n# Heading 1 \\n## Heading 2 \\n### Heading 3 \\n#### Heading 4 \\n##### Heading 5 \\n###### Heading 6');\n",
"mdcell.render();\n",
"$(element).append(mdcell.element)\n",
".removeClass()\n",
".css('left', '66%')\n",
".css('position', 'absolute')\n",
".css('width', '30%')\n",
"mdcell.element.prepend(\n",
" $('<div />')\n",
" .removeClass()\n",
" .css('background', '#AAAAFF')\n",
" .css('width', '100 %')\n",
" .html('Notebook Output')\n",
"\n",
");\n",
"container.show()\n"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.Javascript at 0x21ac2d0>"
]
},
{
"html": [
"<div style='display: inline-block; width: 30%; vertical-align: top;'><div style='background: #AAFFAA; width: 100%;'>NBConvert Latex Output</div><pre class='prettyprint lang-tex' style='background: #EEFFEE; border: 1px solid #DDEEDD;'><xmp>\\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</xmp></pre></div><div style='display: inline-block; width: 2%;'></div><div style='display: inline-block; width: 30%; vertical-align: top;'><div style='background: #FFAAAA; width: 100%;'>NBViewer Output</div><div style='display: inline-block; width: 100%;'><h1 id=\"heading-1\">Heading 1</h1>\n",
"<h2 id=\"heading-2\">Heading 2</h2>\n",
"<h3 id=\"heading-3\">Heading 3</h3>\n",
"<h4 id=\"heading-4\">Heading 4</h4>\n",
"<h5 id=\"heading-5\">Heading 5</h5>\n",
"<h6 id=\"heading-6\">Heading 6</h6></div></div>"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.HTML at 0x21b9fd0>"
]
},
{
"javascript": [
"\n",
" $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.Javascript at 0x21b9fd0>"
]
}
],
"prompt_number": 2
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Headers aren't recognized by (Pandoc on Windows?) if there isn't a blank line above the headers."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"compare_render(r\"\"\"\n",
"# Heading 1 \n",
"## Heading 2 \n",
"### Heading 3 \n",
"#### Heading 4 \n",
"##### Heading 5 \n",
"###### Heading 6 \"\"\")\n",
"\n",
"print(\"\\n\"*10)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"javascript": [
"\n",
"var mdcell = new IPython.MarkdownCell();\n",
"mdcell.create_element();\n",
"mdcell.set_text('\\n# Heading 1 \\n## Heading 2 \\n### Heading 3 \\n#### Heading 4 \\n##### Heading 5 \\n###### Heading 6 ');\n",
"mdcell.render();\n",
"$(element).append(mdcell.element)\n",
".removeClass()\n",
".css('left', '66%')\n",
".css('position', 'absolute')\n",
".css('width', '30%')\n",
"mdcell.element.prepend(\n",
" $('<div />')\n",
" .removeClass()\n",
" .css('background', '#AAAAFF')\n",
" .css('width', '100 %')\n",
" .html('Notebook Output')\n",
"\n",
");\n",
"container.show()\n"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.Javascript at 0x21ac550>"
]
},
{
"html": [
"<div style='display: inline-block; width: 30%; vertical-align: top;'><div style='background: #AAFFAA; width: 100%;'>NBConvert Latex Output</div><pre class='prettyprint lang-tex' style='background: #EEFFEE; border: 1px solid #DDEEDD;'><xmp>\\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</xmp></pre></div><div style='display: inline-block; width: 2%;'></div><div style='display: inline-block; width: 30%; vertical-align: top;'><div style='background: #FFAAAA; width: 100%;'>NBViewer Output</div><div style='display: inline-block; width: 100%;'><h1 id=\"heading-1\">Heading 1</h1>\n",
"<h2 id=\"heading-2\">Heading 2</h2>\n",
"<h3 id=\"heading-3\">Heading 3</h3>\n",
"<h4 id=\"heading-4\">Heading 4</h4>\n",
"<h5 id=\"heading-5\">Heading 5</h5>\n",
"<h6 id=\"heading-6\">Heading 6</h6></div></div>"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.HTML at 0x21ac550>"
]
},
{
"javascript": [
"\n",
" $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.Javascript at 0x21ac550>"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n"
]
}
],
"prompt_number": 3
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"If internal links are defined, these will not work in nbviewer and latex as the local link is not existing."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"compare_render(r\"\"\"\n",
"[Link2Heading](http://127.0.0.1:8888/0a2d8086-ee24-4e5b-a32b-f66b525836cb#General-markdown)\n",
"\"\"\")"
],
"language": "python",
"metadata": {},
"outputs": [
{
"javascript": [
"\n",
"var mdcell = new IPython.MarkdownCell();\n",
"mdcell.create_element();\n",
"mdcell.set_text('\\n[Link2Heading](http://127.0.0.1:8888/0a2d8086-ee24-4e5b-a32b-f66b525836cb#General-markdown)\\n');\n",
"mdcell.render();\n",
"$(element).append(mdcell.element)\n",
".removeClass()\n",
".css('left', '66%')\n",
".css('position', 'absolute')\n",
".css('width', '30%')\n",
"mdcell.element.prepend(\n",
" $('<div />')\n",
" .removeClass()\n",
" .css('background', '#AAAAFF')\n",
" .css('width', '100 %')\n",
" .html('Notebook Output')\n",
"\n",
");\n",
"container.show()\n"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.Javascript at 0x21ac210>"
]
},
{
"html": [
"<div style='display: inline-block; width: 30%; vertical-align: top;'><div style='background: #AAFFAA; width: 100%;'>NBConvert Latex Output</div><pre class='prettyprint lang-tex' style='background: #EEFFEE; border: 1px solid #DDEEDD;'><xmp>\\href{http://127.0.0.1:8888/0a2d8086-ee24-4e5b-a32b-f66b525836cb\\#General-markdown}{Link2Heading}</xmp></pre></div><div style='display: inline-block; width: 2%;'></div><div style='display: inline-block; width: 30%; vertical-align: top;'><div style='background: #FFAAAA; width: 100%;'>NBViewer Output</div><div style='display: inline-block; width: 100%;'><p><a href=\"http://127.0.0.1:8888/0a2d8086-ee24-4e5b-a32b-f66b525836cb#General-markdown\">Link2Heading</a></p></div></div>"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.HTML at 0x21ac210>"
]
},
{
"javascript": [
"\n",
" $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.Javascript at 0x21ac210>"
]
}
],
"prompt_number": 4
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Basic Markdown bold and italic works."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"compare_render(r\"\"\"\n",
"This is Markdown **bold** and *italic* text.\n",
"\"\"\")"
],
"language": "python",
"metadata": {},
"outputs": [
{
"javascript": [
"\n",
"var mdcell = new IPython.MarkdownCell();\n",
"mdcell.create_element();\n",
"mdcell.set_text('\\nThis is Markdown **bold** and *italic* text.\\n');\n",
"mdcell.render();\n",
"$(element).append(mdcell.element)\n",
".removeClass()\n",
".css('left', '66%')\n",
".css('position', 'absolute')\n",
".css('width', '30%')\n",
"mdcell.element.prepend(\n",
" $('<div />')\n",
" .removeClass()\n",
" .css('background', '#AAAAFF')\n",
" .css('width', '100 %')\n",
" .html('Notebook Output')\n",
"\n",
");\n",
"container.show()\n"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.Javascript at 0x21ac450>"
]
},
{
"html": [
"<div style='display: inline-block; width: 30%; vertical-align: top;'><div style='background: #AAFFAA; width: 100%;'>NBConvert Latex Output</div><pre class='prettyprint lang-tex' style='background: #EEFFEE; border: 1px solid #DDEEDD;'><xmp>This is Markdown \\textbf{bold} and \\emph{italic} text.</xmp></pre></div><div style='display: inline-block; width: 2%;'></div><div style='display: inline-block; width: 30%; vertical-align: top;'><div style='background: #FFAAAA; width: 100%;'>NBViewer Output</div><div style='display: inline-block; width: 100%;'><p>This is Markdown <strong>bold</strong> and <em>italic</em> text.</p></div></div>"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.HTML at 0x21ac450>"
]
},
{
"javascript": [
"\n",
" $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.Javascript at 0x21ac450>"
]
}
],
"prompt_number": 5
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Nested lists work as well"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"compare_render(r\"\"\"\n",
"- li 1\n",
"- li 2\n",
" 1. li 3\n",
" 1. li 4\n",
"- li 5\n",
"\"\"\")"
],
"language": "python",
"metadata": {},
"outputs": [
{
"javascript": [
"\n",
"var mdcell = new IPython.MarkdownCell();\n",
"mdcell.create_element();\n",
"mdcell.set_text('\\n- li 1\\n- li 2\\n 1. li 3\\n 1. li 4\\n- li 5\\n');\n",
"mdcell.render();\n",
"$(element).append(mdcell.element)\n",
".removeClass()\n",
".css('left', '66%')\n",
".css('position', 'absolute')\n",
".css('width', '30%')\n",
"mdcell.element.prepend(\n",
" $('<div />')\n",
" .removeClass()\n",
" .css('background', '#AAAAFF')\n",
" .css('width', '100 %')\n",
" .html('Notebook Output')\n",
"\n",
");\n",
"container.show()\n"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.Javascript at 0x21ac150>"
]
},
{
"html": [
"<div style='display: inline-block; width: 30%; vertical-align: top;'><div style='background: #AAFFAA; width: 100%;'>NBConvert Latex Output</div><pre class='prettyprint lang-tex' style='background: #EEFFEE; border: 1px solid #DDEEDD;'><xmp>\\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}</xmp></pre></div><div style='display: inline-block; width: 2%;'></div><div style='display: inline-block; width: 30%; vertical-align: top;'><div style='background: #FFAAAA; width: 100%;'>NBViewer Output</div><div style='display: inline-block; width: 100%;'><ul>\n",
"<li>li 1</li>\n",
"<li>li 2\n",
"<ol style=\"list-style-type: decimal\">\n",
"<li>li 3</li>\n",
"<li>li 4</li>\n",
"</ol></li>\n",
"<li>li 5</li>\n",
"</ul></div></div>"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.HTML at 0x21ac150>"
]
},
{
"javascript": [
"\n",
" $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.Javascript at 0x21ac150>"
]
}
],
"prompt_number": 6
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Unicode support"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"compare_render(ur\"\"\"\n",
"\u00fcberschu\u00df +***^\u00b0\u00b3\u00b3 \u03b1 \u03b2 \u03b8\n",
"\"\"\")"
],
"language": "python",
"metadata": {},
"outputs": [
{
"javascript": [
"\n",
"var mdcell = new IPython.MarkdownCell();\n",
"mdcell.create_element();\n",
"mdcell.set_text('\\n\u00fcberschu\u00df +***^\u00b0\u00b3\u00b3 \u03b1 \u03b2 \u03b8\\n');\n",
"mdcell.render();\n",
"$(element).append(mdcell.element)\n",
".removeClass()\n",
".css('left', '66%')\n",
".css('position', 'absolute')\n",
".css('width', '30%')\n",
"mdcell.element.prepend(\n",
" $('<div />')\n",
" .removeClass()\n",
" .css('background', '#AAAAFF')\n",
" .css('width', '100 %')\n",
" .html('Notebook Output')\n",
"\n",
");\n",
"container.show()\n"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.Javascript at 0x22b6950>"
]
},
{
"html": [
"<div style='display: inline-block; width: 30%; vertical-align: top;'><div style='background: #AAFFAA; width: 100%;'>NBConvert Latex Output</div><pre class='prettyprint lang-tex' style='background: #EEFFEE; border: 1px solid #DDEEDD;'><xmp>\u00fcberschu\u00df +\\emph{*}\\^{}\u00b0\u00b3\u00b3 \u03b1 \u03b2 \u03b8</xmp></pre></div><div style='display: inline-block; width: 2%;'></div><div style='display: inline-block; width: 30%; vertical-align: top;'><div style='background: #FFAAAA; width: 100%;'>NBViewer Output</div><div style='display: inline-block; width: 100%;'><p>\u00fcberschu\u00df +<em>*</em>^\u00b0\u00b3\u00b3 \u03b1 \u03b2 \u03b8</p></div></div>"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.HTML at 0x21ac3d0>"
]
},
{
"javascript": [
"\n",
" $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.Javascript at 0x21ac3d0>"
]
}
],
"prompt_number": 7
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Pandoc may produce invalid latex, e.g \\sout is not allowed in headings"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"compare_render(r\"\"\"\n",
"\n",
"# Heading 1 ~~strikeout~~\n",
"\"\"\")"
],
"language": "python",
"metadata": {},
"outputs": [
{
"javascript": [
"\n",
"var mdcell = new IPython.MarkdownCell();\n",
"mdcell.create_element();\n",
"mdcell.set_text('\\n\\n# Heading 1 ~~strikeout~~\\n');\n",
"mdcell.render();\n",
"$(element).append(mdcell.element)\n",
".removeClass()\n",
".css('left', '66%')\n",
".css('position', 'absolute')\n",
".css('width', '30%')\n",
"mdcell.element.prepend(\n",
" $('<div />')\n",
" .removeClass()\n",
" .css('background', '#AAAAFF')\n",
" .css('width', '100 %')\n",
" .html('Notebook Output')\n",
"\n",
");\n",
"container.show()\n"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.Javascript at 0x21ac590>"
]
},
{
"html": [
"<div style='display: inline-block; width: 30%; vertical-align: top;'><div style='background: #AAFFAA; width: 100%;'>NBConvert Latex Output</div><pre class='prettyprint lang-tex' style='background: #EEFFEE; border: 1px solid #DDEEDD;'><xmp>\\section{Heading 1 \\sout{strikeout}}</xmp></pre></div><div style='display: inline-block; width: 2%;'></div><div style='display: inline-block; width: 30%; vertical-align: top;'><div style='background: #FFAAAA; width: 100%;'>NBViewer Output</div><div style='display: inline-block; width: 100%;'><h1 id=\"heading-1-strikeout\">Heading 1 <del>strikeout</del></h1></div></div>"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.HTML at 0x21ac590>"
]
},
{
"javascript": [
"\n",
" $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.Javascript at 0x21ac590>"
]
}
],
"prompt_number": 8
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Horizontal lines work just fine"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"compare_render(r\"\"\"\n",
"above\n",
"\n",
"--------\n",
"\n",
"below\n",
"\"\"\")"
],
"language": "python",
"metadata": {},
"outputs": [
{
"javascript": [
"\n",
"var mdcell = new IPython.MarkdownCell();\n",
"mdcell.create_element();\n",
"mdcell.set_text('\\nabove\\n\\n--------\\n\\nbelow\\n');\n",
"mdcell.render();\n",
"$(element).append(mdcell.element)\n",
".removeClass()\n",
".css('left', '66%')\n",
".css('position', 'absolute')\n",
".css('width', '30%')\n",
"mdcell.element.prepend(\n",
" $('<div />')\n",
" .removeClass()\n",
" .css('background', '#AAAAFF')\n",
" .css('width', '100 %')\n",
" .html('Notebook Output')\n",
"\n",
");\n",
"container.show()\n"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.Javascript at 0x21ac150>"
]
},
{
"html": [
"<div style='display: inline-block; width: 30%; vertical-align: top;'><div style='background: #AAFFAA; width: 100%;'>NBConvert Latex Output</div><pre class='prettyprint lang-tex' style='background: #EEFFEE; border: 1px solid #DDEEDD;'><xmp>above\n",
"\n",
"\\begin{center}\\rule{3in}{0.4pt}\\end{center}\n",
"\n",
"below</xmp></pre></div><div style='display: inline-block; width: 2%;'></div><div style='display: inline-block; width: 30%; vertical-align: top;'><div style='background: #FFAAAA; width: 100%;'>NBViewer Output</div><div style='display: inline-block; width: 100%;'><p>above</p>\n",
"<hr />\n",
"<p>below</p></div></div>"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.HTML at 0x21ac450>"
]
},
{
"javascript": [
"\n",
" $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.Javascript at 0x21ac450>"
]
}
],
"prompt_number": 9
},
{
"cell_type": "heading",
"level": 2,
"metadata": {},
"source": [
"Extended markdown of pandoc"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"(maybe we should deactivate this) "
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"compare_render(r\"\"\"\n",
"This is Markdown ~subscript~ and ^superscript^ text.\n",
"\"\"\")"
],
"language": "python",
"metadata": {},
"outputs": [
{
"javascript": [
"\n",
"var mdcell = new IPython.MarkdownCell();\n",
"mdcell.create_element();\n",
"mdcell.set_text('\\nThis is Markdown ~subscript~ and ^superscript^ text.\\n');\n",
"mdcell.render();\n",
"$(element).append(mdcell.element)\n",
".removeClass()\n",
".css('left', '66%')\n",
".css('position', 'absolute')\n",
".css('width', '30%')\n",
"mdcell.element.prepend(\n",
" $('<div />')\n",
" .removeClass()\n",
" .css('background', '#AAAAFF')\n",
" .css('width', '100 %')\n",
" .html('Notebook Output')\n",
"\n",
");\n",
"container.show()\n"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.Javascript at 0x21ac150>"
]
},
{
"html": [
"<div style='display: inline-block; width: 30%; vertical-align: top;'><div style='background: #AAFFAA; width: 100%;'>NBConvert Latex Output</div><pre class='prettyprint lang-tex' style='background: #EEFFEE; border: 1px solid #DDEEDD;'><xmp>This is Markdown \\textsubscript{subscript} and\n",
"\\textsuperscript{superscript} text.</xmp></pre></div><div style='display: inline-block; width: 2%;'></div><div style='display: inline-block; width: 30%; vertical-align: top;'><div style='background: #FFAAAA; width: 100%;'>NBViewer Output</div><div style='display: inline-block; width: 100%;'><p>This is Markdown <sub>subscript</sub> and <sup>superscript</sup> text.</p></div></div>"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.HTML at 0x21ac150>"
]
},
{
"javascript": [
"\n",
" $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.Javascript at 0x21ac150>"
]
}
],
"prompt_number": 10
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"No space before underline behaves inconsistent (Pandoc extension: intraword_underscores - deactivate?)"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"compare_render(r\"\"\"\n",
"This is Markdown not_italic_.\n",
"\"\"\")"
],
"language": "python",
"metadata": {},
"outputs": [
{
"javascript": [
"\n",
"var mdcell = new IPython.MarkdownCell();\n",
"mdcell.create_element();\n",
"mdcell.set_text('\\nThis is Markdown not_italic_.\\n');\n",
"mdcell.render();\n",
"$(element).append(mdcell.element)\n",
".removeClass()\n",
".css('left', '66%')\n",
".css('position', 'absolute')\n",
".css('width', '30%')\n",
"mdcell.element.prepend(\n",
" $('<div />')\n",
" .removeClass()\n",
" .css('background', '#AAAAFF')\n",
" .css('width', '100 %')\n",
" .html('Notebook Output')\n",
"\n",
");\n",
"container.show()\n"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.Javascript at 0x21ac5d0>"
]
},
{
"html": [
"<div style='display: inline-block; width: 30%; vertical-align: top;'><div style='background: #AAFFAA; width: 100%;'>NBConvert Latex Output</div><pre class='prettyprint lang-tex' style='background: #EEFFEE; border: 1px solid #DDEEDD;'><xmp>This is Markdown not\\_italic\\_.</xmp></pre></div><div style='display: inline-block; width: 2%;'></div><div style='display: inline-block; width: 30%; vertical-align: top;'><div style='background: #FFAAAA; width: 100%;'>NBViewer Output</div><div style='display: inline-block; width: 100%;'><p>This is Markdown not_italic_.</p></div></div>"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.HTML at 0x21ac5d0>"
]
},
{
"javascript": [
"\n",
" $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.Javascript at 0x21ac5d0>"
]
}
],
"prompt_number": 11
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Pandoc allows to define tex macros which are respected for all output formats, the notebook not. "
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"compare_render(r\"\"\"\n",
"\\newcommand{\\tuple}[1]{\\langle #1 \\rangle}\n",
"\n",
"$\\tuple{a, b, c}$\n",
"\"\"\")"
],
"language": "python",
"metadata": {},
"outputs": [
{
"javascript": [
"\n",
"var mdcell = new IPython.MarkdownCell();\n",
"mdcell.create_element();\n",
"mdcell.set_text('\\n\\\\newcommand{\\\\tuple}[1]{\\\\langle #1 \\\\rangle}\\n\\n$\\\\tuple{a, b, c}$\\n');\n",
"mdcell.render();\n",
"$(element).append(mdcell.element)\n",
".removeClass()\n",
".css('left', '66%')\n",
".css('position', 'absolute')\n",
".css('width', '30%')\n",
"mdcell.element.prepend(\n",
" $('<div />')\n",
" .removeClass()\n",
" .css('background', '#AAAAFF')\n",
" .css('width', '100 %')\n",
" .html('Notebook Output')\n",
"\n",
");\n",
"container.show()\n"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.Javascript at 0x21ac450>"
]
},
{
"html": [
"<div style='display: inline-block; width: 30%; vertical-align: top;'><div style='background: #AAFFAA; width: 100%;'>NBConvert Latex Output</div><pre class='prettyprint lang-tex' style='background: #EEFFEE; border: 1px solid #DDEEDD;'><xmp>\\newcommand{\\tuple}[1]{\\langle #1 \\rangle}\n",
"\n",
"$\\tuple{a, b, c}$</xmp></pre></div><div style='display: inline-block; width: 2%;'></div><div style='display: inline-block; width: 30%; vertical-align: top;'><div style='background: #FFAAAA; width: 100%;'>NBViewer Output</div><div style='display: inline-block; width: 100%;'><p><span class=\"math\">\\(\\langle a, b, c \\rangle\\)</span></p></div></div>"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.HTML at 0x21ac450>"
]
},
{
"javascript": [
"\n",
" $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.Javascript at 0x21ac450>"
]
}
],
"prompt_number": 12
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"When placing the \\newcommand inside a math environment it works within the notebook and nbviewer, but produces invalid latex (the newcommand is only valid in the same math environment)."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"compare_render(r\"\"\"\n",
"$\\newcommand{\\foo}[1]{...:: #1 ::...}$\n",
"$\\foo{bar}$\n",
"\"\"\")"
],
"language": "python",
"metadata": {},
"outputs": [
{
"javascript": [
"\n",
"var mdcell = new IPython.MarkdownCell();\n",
"mdcell.create_element();\n",
"mdcell.set_text('\\n$\\\\newcommand{\\\\foo}[1]{...:: #1 ::...}$\\n$\\\\foo{bar}$\\n');\n",
"mdcell.render();\n",
"$(element).append(mdcell.element)\n",
".removeClass()\n",
".css('left', '66%')\n",
".css('position', 'absolute')\n",
".css('width', '30%')\n",
"mdcell.element.prepend(\n",
" $('<div />')\n",
" .removeClass()\n",
" .css('background', '#AAAAFF')\n",
" .css('width', '100 %')\n",
" .html('Notebook Output')\n",
"\n",
");\n",
"container.show()\n"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.Javascript at 0x21ac590>"
]
},
{
"html": [
"<div style='display: inline-block; width: 30%; vertical-align: top;'><div style='background: #AAFFAA; width: 100%;'>NBConvert Latex Output</div><pre class='prettyprint lang-tex' style='background: #EEFFEE; border: 1px solid #DDEEDD;'><xmp>$\\newcommand{\\foo}[1]{...:: #1 ::...}$ $\\foo{bar}$</xmp></pre></div><div style='display: inline-block; width: 2%;'></div><div style='display: inline-block; width: 30%; vertical-align: top;'><div style='background: #FFAAAA; width: 100%;'>NBViewer Output</div><div style='display: inline-block; width: 100%;'><p><span class=\"math\">\\(\\newcommand{\\foo}[1]{...:: #1 ::...}\\)</span> <span class=\"math\">\\(\\foo{bar}\\)</span></p></div></div>"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.HTML at 0x21ac590>"
]
},
{
"javascript": [
"\n",
" $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.Javascript at 0x21ac590>"
]
}
],
"prompt_number": 13
},
{
"cell_type": "heading",
"level": 2,
"metadata": {},
"source": [
"HTML or LaTeX injections"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Raw HTML gets dropped entirely when converting to $\\LaTeX$."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"compare_render(r\"\"\"\n",
"This is HTML <b>bold</b> and <i>italic</i> text.\n",
"\"\"\")"
],
"language": "python",
"metadata": {},
"outputs": [
{
"javascript": [
"\n",
"var mdcell = new IPython.MarkdownCell();\n",
"mdcell.create_element();\n",
"mdcell.set_text('\\nThis is HTML <b>bold</b> and <i>italic</i> text.\\n');\n",
"mdcell.render();\n",
"$(element).append(mdcell.element)\n",
".removeClass()\n",
".css('left', '66%')\n",
".css('position', 'absolute')\n",
".css('width', '30%')\n",
"mdcell.element.prepend(\n",
" $('<div />')\n",
" .removeClass()\n",
" .css('background', '#AAAAFF')\n",
" .css('width', '100 %')\n",
" .html('Notebook Output')\n",
"\n",
");\n",
"container.show()\n"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.Javascript at 0x21ac5d0>"
]
},
{
"html": [
"<div style='display: inline-block; width: 30%; vertical-align: top;'><div style='background: #AAFFAA; width: 100%;'>NBConvert Latex Output</div><pre class='prettyprint lang-tex' style='background: #EEFFEE; border: 1px solid #DDEEDD;'><xmp>This is HTML bold and italic text.</xmp></pre></div><div style='display: inline-block; width: 2%;'></div><div style='display: inline-block; width: 30%; vertical-align: top;'><div style='background: #FFAAAA; width: 100%;'>NBViewer Output</div><div style='display: inline-block; width: 100%;'><p>This is HTML <b>bold</b> and <i>italic</i> text.</p></div></div>"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.HTML at 0x21ac5d0>"
]
},
{
"javascript": [
"\n",
" $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.Javascript at 0x21ac5d0>"
]
}
],
"prompt_number": 14
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Same for something like center"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"compare_render(r\"\"\"\n",
"<center>Center aligned</center>\n",
"\"\"\")"
],
"language": "python",
"metadata": {},
"outputs": [
{
"javascript": [
"\n",
"var mdcell = new IPython.MarkdownCell();\n",
"mdcell.create_element();\n",
"mdcell.set_text('\\n<center>Center aligned</center>\\n');\n",
"mdcell.render();\n",
"$(element).append(mdcell.element)\n",
".removeClass()\n",
".css('left', '66%')\n",
".css('position', 'absolute')\n",
".css('width', '30%')\n",
"mdcell.element.prepend(\n",
" $('<div />')\n",
" .removeClass()\n",
" .css('background', '#AAAAFF')\n",
" .css('width', '100 %')\n",
" .html('Notebook Output')\n",
"\n",
");\n",
"container.show()\n"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.Javascript at 0x21ac210>"
]
},
{
"html": [
"<div style='display: inline-block; width: 30%; vertical-align: top;'><div style='background: #AAFFAA; width: 100%;'>NBConvert Latex Output</div><pre class='prettyprint lang-tex' style='background: #EEFFEE; border: 1px solid #DDEEDD;'><xmp>Center aligned</xmp></pre></div><div style='display: inline-block; width: 2%;'></div><div style='display: inline-block; width: 30%; vertical-align: top;'><div style='background: #FFAAAA; width: 100%;'>NBViewer Output</div><div style='display: inline-block; width: 100%;'><center>\n",
"Center aligned\n",
"</center></div></div>"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.HTML at 0x21ac210>"
]
},
{
"javascript": [
"\n",
" $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.Javascript at 0x21ac210>"
]
}
],
"prompt_number": 15
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Raw $\\LaTeX$ gets droppen entirely when converted to HTML. (I don't know why the HTML output is cropped here???)"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"compare_render(r\"\"\"\n",
"This is \\LaTeX \\bf{bold} and \\emph{italic} text.\n",
"\"\"\")"
],
"language": "python",
"metadata": {},
"outputs": [
{
"javascript": [
"\n",
"var mdcell = new IPython.MarkdownCell();\n",
"mdcell.create_element();\n",
"mdcell.set_text('\\nThis is \\\\LaTeX \\\\bf{bold} and \\\\emph{italic} text.\\n');\n",
"mdcell.render();\n",
"$(element).append(mdcell.element)\n",
".removeClass()\n",
".css('left', '66%')\n",
".css('position', 'absolute')\n",
".css('width', '30%')\n",
"mdcell.element.prepend(\n",
" $('<div />')\n",
" .removeClass()\n",
" .css('background', '#AAAAFF')\n",
" .css('width', '100 %')\n",
" .html('Notebook Output')\n",
"\n",
");\n",
"container.show()\n"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.Javascript at 0x21ac590>"
]
},
{
"html": [
"<div style='display: inline-block; width: 30%; vertical-align: top;'><div style='background: #AAFFAA; width: 100%;'>NBConvert Latex Output</div><pre class='prettyprint lang-tex' style='background: #EEFFEE; border: 1px solid #DDEEDD;'><xmp>This is \\LaTeX \\bf{bold} and \\emph{italic} text.</xmp></pre></div><div style='display: inline-block; width: 2%;'></div><div style='display: inline-block; width: 30%; vertical-align: top;'><div style='background: #FFAAAA; width: 100%;'>NBViewer Output</div><div style='display: inline-block; width: 100%;'><p>This is </p></div></div>"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.HTML at 0x21ac590>"
]
},
{
"javascript": [
"\n",
" $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.Javascript at 0x21ac590>"
]
}
],
"prompt_number": 16
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"A combination of raw $\\LaTeX$ and raw HTML"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"compare_render(r\"\"\"\n",
"**foo** $\\left( \\sum_{k=1}^n a_k b_k \\right)^2 \\leq$ <b>b\\$ar</b> $$test$$ \n",
"\\cite{}\n",
"\"\"\")"
],
"language": "python",
"metadata": {},
"outputs": [
{
"javascript": [
"\n",
"var mdcell = new IPython.MarkdownCell();\n",
"mdcell.create_element();\n",
"mdcell.set_text('\\n**foo** $\\\\left( \\\\sum_{k=1}^n a_k b_k \\\\right)^2 \\\\leq$ <b>b\\\\$ar</b> $$test$$ \\n\\\\cite{}\\n');\n",
"mdcell.render();\n",
"$(element).append(mdcell.element)\n",
".removeClass()\n",
".css('left', '66%')\n",
".css('position', 'absolute')\n",
".css('width', '30%')\n",
"mdcell.element.prepend(\n",
" $('<div />')\n",
" .removeClass()\n",
" .css('background', '#AAAAFF')\n",
" .css('width', '100 %')\n",
" .html('Notebook Output')\n",
"\n",
");\n",
"container.show()\n"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.Javascript at 0x21ac590>"
]
},
{
"html": [
"<div style='display: inline-block; width: 30%; vertical-align: top;'><div style='background: #AAFFAA; width: 100%;'>NBConvert Latex Output</div><pre class='prettyprint lang-tex' style='background: #EEFFEE; border: 1px solid #DDEEDD;'><xmp>\\textbf{foo} $\\left( \\sum_{k=1}^n a_k b_k \\right)^2 \\leq$ b\\$ar \\[test\\]\n",
"\\cite{}</xmp></pre></div><div style='display: inline-block; width: 2%;'></div><div style='display: inline-block; width: 30%; vertical-align: top;'><div style='background: #FFAAAA; width: 100%;'>NBViewer Output</div><div style='display: inline-block; width: 100%;'><p><strong>foo</strong> <span class=\"math\">\\(\\left( \\sum_{k=1}^n a_k b_k \\right)^2 \\leq\\)</span> <b>b$ar</b> <span class=\"math\">\\[test\\]</span> </p></div></div>"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.HTML at 0x21ac590>"
]
},
{
"javascript": [
"\n",
" $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.Javascript at 0x21ac590>"
]
}
],
"prompt_number": 17
},
{
"cell_type": "heading",
"level": 2,
"metadata": {},
"source": [
"Tables"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"HTML tables render in the notebook, but not in Pandoc."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"compare_render(r\"\"\"\n",
"<table>\n",
" <tr>\n",
" <td>a</td>\n",
" <td>b</td>\n",
" </tr>\n",
" <tr>\n",
" <td>c</td>\n",
" <td>d</td>\n",
" </tr>\n",
"</table>\n",
"\"\"\")"
],
"language": "python",
"metadata": {},
"outputs": [
{
"javascript": [
"\n",
"var mdcell = new IPython.MarkdownCell();\n",
"mdcell.create_element();\n",
"mdcell.set_text('\\n<table>\\n <tr>\\n <td>a</td>\\n <td>b</td>\\n </tr>\\n <tr>\\n <td>c</td>\\n <td>d</td>\\n </tr>\\n</table>\\n');\n",
"mdcell.render();\n",
"$(element).append(mdcell.element)\n",
".removeClass()\n",
".css('left', '66%')\n",
".css('position', 'absolute')\n",
".css('width', '30%')\n",
"mdcell.element.prepend(\n",
" $('<div />')\n",
" .removeClass()\n",
" .css('background', '#AAAAFF')\n",
" .css('width', '100 %')\n",
" .html('Notebook Output')\n",
"\n",
");\n",
"container.show()\n"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.Javascript at 0x21ac5d0>"
]
},
{
"html": [
"<div style='display: inline-block; width: 30%; vertical-align: top;'><div style='background: #AAFFAA; width: 100%;'>NBConvert Latex Output</div><pre class='prettyprint lang-tex' style='background: #EEFFEE; border: 1px solid #DDEEDD;'><xmp>a\n",
"\n",
"b\n",
"\n",
"c\n",
"\n",
"d</xmp></pre></div><div style='display: inline-block; width: 2%;'></div><div style='display: inline-block; width: 30%; vertical-align: top;'><div style='background: #FFAAAA; width: 100%;'>NBViewer Output</div><div style='display: inline-block; width: 100%;'><table>\n",
" <tr>\n",
" <td>\n",
"a\n",
"</td>\n",
" <td>\n",
"b\n",
"</td>\n",
" </tr>\n",
" <tr>\n",
" <td>\n",
"c\n",
"</td>\n",
" <td>\n",
"d\n",
"</td>\n",
" </tr>\n",
"</table></div></div>"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.HTML at 0x21ac5d0>"
]
},
{
"javascript": [
"\n",
" $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.Javascript at 0x21ac5d0>"
]
}
],
"prompt_number": 18
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Instead, Pandoc supports simple ascii tables. Unfortunately marked.js doesn't support this, and therefore it is not supported in the notebook."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"compare_render(r\"\"\"\n",
"+---+---+\n",
"| a | b |\n",
"+---+---+\n",
"| c | d |\n",
"+---+---+\n",
"\"\"\")"
],
"language": "python",
"metadata": {},
"outputs": [
{
"javascript": [
"\n",
"var mdcell = new IPython.MarkdownCell();\n",
"mdcell.create_element();\n",
"mdcell.set_text('\\n+---+---+\\n| a | b |\\n+---+---+\\n| c | d |\\n+---+---+\\n');\n",
"mdcell.render();\n",
"$(element).append(mdcell.element)\n",
".removeClass()\n",
".css('left', '66%')\n",
".css('position', 'absolute')\n",
".css('width', '30%')\n",
"mdcell.element.prepend(\n",
" $('<div />')\n",
" .removeClass()\n",
" .css('background', '#AAAAFF')\n",
" .css('width', '100 %')\n",
" .html('Notebook Output')\n",
"\n",
");\n",
"container.show()\n"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.Javascript at 0x21ac210>"
]
},
{
"html": [
"<div style='display: inline-block; width: 30%; vertical-align: top;'><div style='background: #AAFFAA; width: 100%;'>NBConvert Latex Output</div><pre class='prettyprint lang-tex' style='background: #EEFFEE; border: 1px solid #DDEEDD;'><xmp>\\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}</xmp></pre></div><div style='display: inline-block; width: 2%;'></div><div style='display: inline-block; width: 30%; vertical-align: top;'><div style='background: #FFAAAA; width: 100%;'>NBViewer Output</div><div style='display: inline-block; width: 100%;'><table>\n",
"<col width=\"5%\" />\n",
"<col width=\"5%\" />\n",
"<tbody>\n",
"<tr class=\"odd\">\n",
"<td align=\"left\"><p>a</p></td>\n",
"<td align=\"left\"><p>b</p></td>\n",
"</tr>\n",
"<tr class=\"even\">\n",
"<td align=\"left\"><p>c</p></td>\n",
"<td align=\"left\"><p>d</p></td>\n",
"</tr>\n",
"</tbody>\n",
"</table></div></div>"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.HTML at 0x21ac210>"
]
},
{
"javascript": [
"\n",
" $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.Javascript at 0x21ac210>"
]
}
],
"prompt_number": 19
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"An alternative to basic ascii tables is pipe tables. Pipe tables can be recognized by Pandoc and are supported by marked, hence, this is the **best way to add tables**."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"compare_render(r\"\"\"\n",
"|Left |Center |Right|\n",
"|:----|:-----:|----:|\n",
"|Text1|Text2 |Text3|\n",
"\"\"\")"
],
"language": "python",
"metadata": {},
"outputs": [
{
"javascript": [
"\n",
"var mdcell = new IPython.MarkdownCell();\n",
"mdcell.create_element();\n",
"mdcell.set_text('\\n|Left |Center |Right|\\n|:----|:-----:|----:|\\n|Text1|Text2 |Text3|\\n');\n",
"mdcell.render();\n",
"$(element).append(mdcell.element)\n",
".removeClass()\n",
".css('left', '66%')\n",
".css('position', 'absolute')\n",
".css('width', '30%')\n",
"mdcell.element.prepend(\n",
" $('<div />')\n",
" .removeClass()\n",
" .css('background', '#AAAAFF')\n",
" .css('width', '100 %')\n",
" .html('Notebook Output')\n",
"\n",
");\n",
"container.show()\n"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.Javascript at 0x21ac150>"
]
},
{
"html": [
"<div style='display: inline-block; width: 30%; vertical-align: top;'><div style='background: #AAFFAA; width: 100%;'>NBConvert Latex Output</div><pre class='prettyprint lang-tex' style='background: #EEFFEE; border: 1px solid #DDEEDD;'><xmp>\\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}</xmp></pre></div><div style='display: inline-block; width: 2%;'></div><div style='display: inline-block; width: 30%; vertical-align: top;'><div style='background: #FFAAAA; width: 100%;'>NBViewer Output</div><div style='display: inline-block; width: 100%;'><table>\n",
"<thead>\n",
"<tr class=\"header\">\n",
"<th align=\"left\">Left</th>\n",
"<th align=\"center\">Center</th>\n",
"<th align=\"right\">Right</th>\n",
"</tr>\n",
"</thead>\n",
"<tbody>\n",
"<tr class=\"odd\">\n",
"<td align=\"left\">Text1</td>\n",
"<td align=\"center\">Text2</td>\n",
"<td align=\"right\">Text3</td>\n",
"</tr>\n",
"</tbody>\n",
"</table></div></div>"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.HTML at 0x21ac150>"
]
},
{
"javascript": [
"\n",
" $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.Javascript at 0x21ac150>"
]
}
],
"prompt_number": 20
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Pandoc recognizes cell alignment in simple tables. Since marked.js doesn't recognize ascii tables, it can't render this table."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"compare_render(r\"\"\"\n",
"Right Aligned Center Aligned Left Aligned\n",
"------------- -------------- ------------\n",
" Why does this\n",
" actually work? Who\n",
" knows ...\n",
"\"\"\")\n",
"\n",
"print(\"\\n\"*5)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"javascript": [
"\n",
"var mdcell = new IPython.MarkdownCell();\n",
"mdcell.create_element();\n",
"mdcell.set_text('\\nRight Aligned Center Aligned Left Aligned\\n------------- -------------- ------------\\n Why does this\\n actually work? Who\\n knows ...\\n');\n",
"mdcell.render();\n",
"$(element).append(mdcell.element)\n",
".removeClass()\n",
".css('left', '66%')\n",
".css('position', 'absolute')\n",
".css('width', '30%')\n",
"mdcell.element.prepend(\n",
" $('<div />')\n",
" .removeClass()\n",
" .css('background', '#AAAAFF')\n",
" .css('width', '100 %')\n",
" .html('Notebook Output')\n",
"\n",
");\n",
"container.show()\n"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.Javascript at 0x21ac450>"
]
},
{
"html": [
"<div style='display: inline-block; width: 30%; vertical-align: top;'><div style='background: #AAFFAA; width: 100%;'>NBConvert Latex Output</div><pre class='prettyprint lang-tex' style='background: #EEFFEE; border: 1px solid #DDEEDD;'><xmp>\\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}</xmp></pre></div><div style='display: inline-block; width: 2%;'></div><div style='display: inline-block; width: 30%; vertical-align: top;'><div style='background: #FFAAAA; width: 100%;'>NBViewer Output</div><div style='display: inline-block; width: 100%;'><table>\n",
"<thead>\n",
"<tr class=\"header\">\n",
"<th align=\"left\">Right Aligned</th>\n",
"<th align=\"left\">Center Aligned</th>\n",
"<th align=\"left\">Left Aligned</th>\n",
"</tr>\n",
"</thead>\n",
"<tbody>\n",
"<tr class=\"odd\">\n",
"<td align=\"left\">Why</td>\n",
"<td align=\"left\">does</td>\n",
"<td align=\"left\">this</td>\n",
"</tr>\n",
"<tr class=\"even\">\n",
"<td align=\"left\">actually</td>\n",
"<td align=\"left\">work?</td>\n",
"<td align=\"left\">Who</td>\n",
"</tr>\n",
"<tr class=\"odd\">\n",
"<td align=\"left\">knows</td>\n",
"<td align=\"left\">...</td>\n",
"<td align=\"left\"></td>\n",
"</tr>\n",
"</tbody>\n",
"</table></div></div>"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.HTML at 0x21ac450>"
]
},
{
"javascript": [
"\n",
" $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.Javascript at 0x21ac450>"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\n",
"\n",
"\n",
"\n",
"\n",
"\n"
]
}
],
"prompt_number": 21
},
{
"cell_type": "heading",
"level": 2,
"metadata": {},
"source": [
"Images"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Markdown images work on both. However, remote images are not allowed in $\\LaTeX$. Maybe add a preprocessor to download these.\n",
"The alternate text is displayed in nbviewer next to the image."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"compare_render(r\"\"\"\n",
"![Alternate Text](http://ipython.org/_static/IPy_header.png)\n",
"\"\"\")"
],
"language": "python",
"metadata": {},
"outputs": [
{
"javascript": [
"\n",
"var mdcell = new IPython.MarkdownCell();\n",
"mdcell.create_element();\n",
"mdcell.set_text('\\n![Alternate Text](http://ipython.org/_static/IPy_header.png)\\n');\n",
"mdcell.render();\n",
"$(element).append(mdcell.element)\n",
".removeClass()\n",
".css('left', '66%')\n",
".css('position', 'absolute')\n",
".css('width', '30%')\n",
"mdcell.element.prepend(\n",
" $('<div />')\n",
" .removeClass()\n",
" .css('background', '#AAAAFF')\n",
" .css('width', '100 %')\n",
" .html('Notebook Output')\n",
"\n",
");\n",
"container.show()\n"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.Javascript at 0x22b6690>"
]
},
{
"html": [
"<div style='display: inline-block; width: 30%; vertical-align: top;'><div style='background: #AAFFAA; width: 100%;'>NBConvert Latex Output</div><pre class='prettyprint lang-tex' style='background: #EEFFEE; border: 1px solid #DDEEDD;'><xmp>\\begin{figure}[htbp]\n",
"\\centering\n",
"\\includegraphics{http://ipython.org/_static/IPy_header.png}\n",
"\\caption{Alternate Text}\n",
"\\end{figure}</xmp></pre></div><div style='display: inline-block; width: 2%;'></div><div style='display: inline-block; width: 30%; vertical-align: top;'><div style='background: #FFAAAA; width: 100%;'>NBViewer Output</div><div style='display: inline-block; width: 100%;'><div class=\"figure\">\n",
"<img src=\"http://ipython.org/_static/IPy_header.png\" alt=\"Alternate Text\" /><p class=\"caption\">Alternate Text</p>\n",
"</div></div></div>"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.HTML at 0x21ac450>"
]
},
{
"javascript": [
"\n",
" $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.Javascript at 0x21ac450>"
]
}
],
"prompt_number": 22
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"HTML Images only work in the notebook."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"compare_render(r\"\"\"\n",
"<img src=\"http://ipython.org/_static/IPy_header.png\">\n",
"\"\"\")"
],
"language": "python",
"metadata": {},
"outputs": [
{
"javascript": [
"\n",
"var mdcell = new IPython.MarkdownCell();\n",
"mdcell.create_element();\n",
"mdcell.set_text('\\n<img src=\"http://ipython.org/_static/IPy_header.png\">\\n');\n",
"mdcell.render();\n",
"$(element).append(mdcell.element)\n",
".removeClass()\n",
".css('left', '66%')\n",
".css('position', 'absolute')\n",
".css('width', '30%')\n",
"mdcell.element.prepend(\n",
" $('<div />')\n",
" .removeClass()\n",
" .css('background', '#AAAAFF')\n",
" .css('width', '100 %')\n",
" .html('Notebook Output')\n",
"\n",
");\n",
"container.show()\n"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.Javascript at 0x22b65d0>"
]
},
{
"html": [
"<div style='display: inline-block; width: 30%; vertical-align: top;'><div style='background: #AAFFAA; width: 100%;'>NBConvert Latex Output</div><pre class='prettyprint lang-tex' style='background: #EEFFEE; border: 1px solid #DDEEDD;'><xmp></xmp></pre></div><div style='display: inline-block; width: 2%;'></div><div style='display: inline-block; width: 30%; vertical-align: top;'><div style='background: #FFAAAA; width: 100%;'>NBViewer Output</div><div style='display: inline-block; width: 100%;'><p><img src=\"http://ipython.org/_static/IPy_header.png\"></p></div></div>"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.HTML at 0x21ac450>"
]
},
{
"javascript": [
"\n",
" $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.Javascript at 0x21ac450>"
]
}
],
"prompt_number": 23
},
{
"cell_type": "heading",
"level": 2,
"metadata": {},
"source": [
"Math"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Simple inline and displaystyle maths work fine"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"compare_render(r\"\"\"\n",
"My equation:\n",
"$$ 5/x=2y $$\n",
"\n",
"It is inline $ 5/x=2y $ here.\n",
"\"\"\")"
],
"language": "python",
"metadata": {},
"outputs": [
{
"javascript": [
"\n",
"var mdcell = new IPython.MarkdownCell();\n",
"mdcell.create_element();\n",
"mdcell.set_text('\\nMy equation:\\n$$ 5/x=2y $$\\n\\nIt is inline $ 5/x=2y $ here.\\n');\n",
"mdcell.render();\n",
"$(element).append(mdcell.element)\n",
".removeClass()\n",
".css('left', '66%')\n",
".css('position', 'absolute')\n",
".css('width', '30%')\n",
"mdcell.element.prepend(\n",
" $('<div />')\n",
" .removeClass()\n",
" .css('background', '#AAAAFF')\n",
" .css('width', '100 %')\n",
" .html('Notebook Output')\n",
"\n",
");\n",
"container.show()\n"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.Javascript at 0x22b6950>"
]
},
{
"html": [
"<div style='display: inline-block; width: 30%; vertical-align: top;'><div style='background: #AAFFAA; width: 100%;'>NBConvert Latex Output</div><pre class='prettyprint lang-tex' style='background: #EEFFEE; border: 1px solid #DDEEDD;'><xmp>My equation: \\[ 5/x=2y \\]\n",
"\n",
"It is inline \\$ 5/x=2y \\$ here.</xmp></pre></div><div style='display: inline-block; width: 2%;'></div><div style='display: inline-block; width: 30%; vertical-align: top;'><div style='background: #FFAAAA; width: 100%;'>NBViewer Output</div><div style='display: inline-block; width: 100%;'><p>My equation: <span class=\"math\">\\[ 5/x=2y \\]</span></p>\n",
"<p>It is inline $ 5/x=2y $ here.</p></div></div>"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.HTML at 0x21ac450>"
]
},
{
"javascript": [
"\n",
" $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.Javascript at 0x21ac450>"
]
}
],
"prompt_number": 24
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"If the first \\$ is on a new line, the equation is not captured by md2tex, if both \\$s are on a new line md2html fails (Note the raw latex is dropped) but the notebook renders it correctly."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"compare_render(r\"\"\"\n",
"$5 \\cdot x=2$\n",
"\n",
"$\n",
"5 \\cdot x=2$\n",
"\n",
"$\n",
"5 \\cdot x=2\n",
"$\n",
"\"\"\")"
],
"language": "python",
"metadata": {},
"outputs": [
{
"javascript": [
"\n",
"var mdcell = new IPython.MarkdownCell();\n",
"mdcell.create_element();\n",
"mdcell.set_text('\\n$5 \\\\cdot x=2$\\n\\n$\\n5 \\\\cdot x=2$\\n\\n$\\n5 \\\\cdot x=2\\n$\\n');\n",
"mdcell.render();\n",
"$(element).append(mdcell.element)\n",
".removeClass()\n",
".css('left', '66%')\n",
".css('position', 'absolute')\n",
".css('width', '30%')\n",
"mdcell.element.prepend(\n",
" $('<div />')\n",
" .removeClass()\n",
" .css('background', '#AAAAFF')\n",
" .css('width', '100 %')\n",
" .html('Notebook Output')\n",
"\n",
");\n",
"container.show()\n"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.Javascript at 0x22b66d0>"
]
},
{
"html": [
"<div style='display: inline-block; width: 30%; vertical-align: top;'><div style='background: #AAFFAA; width: 100%;'>NBConvert Latex Output</div><pre class='prettyprint lang-tex' style='background: #EEFFEE; border: 1px solid #DDEEDD;'><xmp>$5 \\cdot x=2$\n",
"\n",
"\\$ 5 \\cdot x=2\\$\n",
"\n",
"\\$ 5 \\cdot x=2 \\$</xmp></pre></div><div style='display: inline-block; width: 2%;'></div><div style='display: inline-block; width: 30%; vertical-align: top;'><div style='background: #FFAAAA; width: 100%;'>NBViewer Output</div><div style='display: inline-block; width: 100%;'><p><span class=\"math\">\\(5 \\cdot x=2\\)</span></p>\n",
"<p>$ 5 x=2$</p>\n",
"<p>$ 5 x=2 $</p></div></div>"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.HTML at 0x21ac450>"
]
},
{
"javascript": [
"\n",
" $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.Javascript at 0x21ac450>"
]
}
],
"prompt_number": 25
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"MathJax permits some $\\LaTeX$ math constructs without \\$s, of course these raw $\\LaTeX$ is stripped when converting to html.\n",
"Moreove, the & are escaped by the lxml parsing [#4251](https://github.com/ipython/ipython/issues/4251)."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"compare_render(r\"\"\"\n",
"\\begin{align}\n",
"a & b\\\\\n",
"d & c\n",
"\\end{align}\n",
"\n",
"\\begin{eqnarray}\n",
"a & b \\\\\n",
"c & d\n",
"\\end{eqnarray}\n",
"\"\"\")"
],
"language": "python",
"metadata": {},
"outputs": [
{
"javascript": [
"\n",
"var mdcell = new IPython.MarkdownCell();\n",
"mdcell.create_element();\n",
"mdcell.set_text('\\n\\\\begin{align}\\na & b\\\\\\\\\\nd & c\\n\\\\end{align}\\n\\n\\\\begin{eqnarray}\\na & b \\\\\\\\\\nc & d\\n\\\\end{eqnarray}\\n');\n",
"mdcell.render();\n",
"$(element).append(mdcell.element)\n",
".removeClass()\n",
".css('left', '66%')\n",
".css('position', 'absolute')\n",
".css('width', '30%')\n",
"mdcell.element.prepend(\n",
" $('<div />')\n",
" .removeClass()\n",
" .css('background', '#AAAAFF')\n",
" .css('width', '100 %')\n",
" .html('Notebook Output')\n",
"\n",
");\n",
"container.show()\n"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.Javascript at 0x22b6690>"
]
},
{
"html": [
"<div style='display: inline-block; width: 30%; vertical-align: top;'><div style='background: #AAFFAA; width: 100%;'>NBConvert Latex Output</div><pre class='prettyprint lang-tex' style='background: #EEFFEE; border: 1px solid #DDEEDD;'><xmp>\\begin{align}\n",
"a &amp; b\\\\\n",
"d &amp; c\n",
"\\end{align}\n",
"\n",
"\\begin{eqnarray}\n",
"a &amp; b \\\\\n",
"c &amp; d\n",
"\\end{eqnarray}</xmp></pre></div><div style='display: inline-block; width: 2%;'></div><div style='display: inline-block; width: 30%; vertical-align: top;'><div style='background: #FFAAAA; width: 100%;'>NBViewer Output</div><div style='display: inline-block; width: 100%;'></div></div>"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.HTML at 0x21ac450>"
]
},
{
"javascript": [
"\n",
" $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.Javascript at 0x21ac450>"
]
}
],
"prompt_number": 26
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"There is another lxml issue, [#4283](https://github.com/ipython/ipython/issues/4283)"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"compare_render(r\"\"\"\n",
"1<2 is true, but 3>4 is false.\n",
"\n",
"$1<2$ is true, but $3>4$ is false.\n",
"\n",
"1<2 it is even worse if it is alone in a line.\n",
"\"\"\")"
],
"language": "python",
"metadata": {},
"outputs": [
{
"javascript": [
"\n",
"var mdcell = new IPython.MarkdownCell();\n",
"mdcell.create_element();\n",
"mdcell.set_text('\\n1<2 is true, but 3>4 is false.\\n\\n$1<2$ is true, but $3>4$ is false.\\n\\n1<2 it is even worse if it is alone in a line.\\n');\n",
"mdcell.render();\n",
"$(element).append(mdcell.element)\n",
".removeClass()\n",
".css('left', '66%')\n",
".css('position', 'absolute')\n",
".css('width', '30%')\n",
"mdcell.element.prepend(\n",
" $('<div />')\n",
" .removeClass()\n",
" .css('background', '#AAAAFF')\n",
" .css('width', '100 %')\n",
" .html('Notebook Output')\n",
"\n",
");\n",
"container.show()\n"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.Javascript at 0x22b6950>"
]
},
{
"html": [
"<div style='display: inline-block; width: 30%; vertical-align: top;'><div style='background: #AAFFAA; width: 100%;'>NBConvert Latex Output</div><pre class='prettyprint lang-tex' style='background: #EEFFEE; border: 1px solid #DDEEDD;'><xmp>14 is false.\n",
"\n",
"$14$ is false.\n",
"\n",
"1</xmp></pre></div><div style='display: inline-block; width: 2%;'></div><div style='display: inline-block; width: 30%; vertical-align: top;'><div style='background: #FFAAAA; width: 100%;'>NBViewer Output</div><div style='display: inline-block; width: 100%;'><p>1&lt;2 is true, but 3&gt;4 is false.</p>\n",
"<p><span class=\"math\">\\(1&lt;2\\)</span> is true, but <span class=\"math\">\\(3&gt;4\\)</span> is false.</p>\n",
"<p>1&lt;2 it is even worse if it is alone in a line.</p></div></div>"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.HTML at 0x21ac450>"
]
},
{
"javascript": [
"\n",
" $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.Javascript at 0x21ac450>"
]
}
],
"prompt_number": 27
},
{
"cell_type": "heading",
"level": 2,
"metadata": {},
"source": [
"Listings, and Code blocks"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"compare_render(r\"\"\"\n",
"some source code\n",
"\n",
"```\n",
"a = \"test\"\n",
"print(a)\n",
"```\n",
"\"\"\")"
],
"language": "python",
"metadata": {},
"outputs": [
{
"javascript": [
"\n",
"var mdcell = new IPython.MarkdownCell();\n",
"mdcell.create_element();\n",
"mdcell.set_text('\\nsome source code\\n\\n```\\na = \"test\"\\nprint(a)\\n```\\n');\n",
"mdcell.render();\n",
"$(element).append(mdcell.element)\n",
".removeClass()\n",
".css('left', '66%')\n",
".css('position', 'absolute')\n",
".css('width', '30%')\n",
"mdcell.element.prepend(\n",
" $('<div />')\n",
" .removeClass()\n",
" .css('background', '#AAAAFF')\n",
" .css('width', '100 %')\n",
" .html('Notebook Output')\n",
"\n",
");\n",
"container.show()\n"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.Javascript at 0x22b68d0>"
]
},
{
"html": [
"<div style='display: inline-block; width: 30%; vertical-align: top;'><div style='background: #AAFFAA; width: 100%;'>NBConvert Latex Output</div><pre class='prettyprint lang-tex' style='background: #EEFFEE; border: 1px solid #DDEEDD;'><xmp>some source code\n",
"\n",
"\\begin{verbatim}\n",
"a = \"test\"\n",
"print(a)\n",
"\\end{verbatim}</xmp></pre></div><div style='display: inline-block; width: 2%;'></div><div style='display: inline-block; width: 30%; vertical-align: top;'><div style='background: #FFAAAA; width: 100%;'>NBViewer Output</div><div style='display: inline-block; width: 100%;'><p>some source code</p>\n",
"<pre><code>a = &quot;test&quot;\n",
"print(a)</code></pre></div></div>"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.HTML at 0x21ac450>"
]
},
{
"javascript": [
"\n",
" $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.Javascript at 0x21ac450>"
]
}
],
"prompt_number": 28
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Language specific syntax highlighting by Pandoc requires additional dependencies to render correctly."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"compare_render(r\"\"\"\n",
"some source code\n",
"\n",
"```python\n",
"a = \"test\"\n",
"print(a)\n",
"```\n",
"\"\"\")"
],
"language": "python",
"metadata": {},
"outputs": [
{
"javascript": [
"\n",
"var mdcell = new IPython.MarkdownCell();\n",
"mdcell.create_element();\n",
"mdcell.set_text('\\nsome source code\\n\\n```python\\na = \"test\"\\nprint(a)\\n```\\n');\n",
"mdcell.render();\n",
"$(element).append(mdcell.element)\n",
".removeClass()\n",
".css('left', '66%')\n",
".css('position', 'absolute')\n",
".css('width', '30%')\n",
"mdcell.element.prepend(\n",
" $('<div />')\n",
" .removeClass()\n",
" .css('background', '#AAAAFF')\n",
" .css('width', '100 %')\n",
" .html('Notebook Output')\n",
"\n",
");\n",
"container.show()\n"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.Javascript at 0x22b6850>"
]
},
{
"html": [
"<div style='display: inline-block; width: 30%; vertical-align: top;'><div style='background: #AAFFAA; width: 100%;'>NBConvert Latex Output</div><pre class='prettyprint lang-tex' style='background: #EEFFEE; border: 1px solid #DDEEDD;'><xmp>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}</xmp></pre></div><div style='display: inline-block; width: 2%;'></div><div style='display: inline-block; width: 30%; vertical-align: top;'><div style='background: #FFAAAA; width: 100%;'>NBViewer Output</div><div style='display: inline-block; width: 100%;'><p>some source code</p>\n",
"<pre class=\"sourceCode python\"><code class=\"sourceCode python\">a = <span class=\"st\">&quot;test&quot;</span>\n",
"<span class=\"kw\">print</span>(a)</code></pre></div></div>"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.HTML at 0x21ac450>"
]
},
{
"javascript": [
"\n",
" $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.Javascript at 0x21ac450>"
]
}
],
"prompt_number": 29
}
],
"metadata": {}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment