From 6a39e5a981c2785c94e3fc9bf255b390c2373160 2014-04-18 23:16:41 From: jon Date: 2014-04-18 23:16:41 Subject: [PATCH] Add nbconvert pandoc markdown notebook. closes #3503 --- diff --git a/tools/tests/Markdown Pandoc Limitations.ipynb b/tools/tests/Markdown Pandoc Limitations.ipynb new file mode 100644 index 0000000..529872f --- /dev/null +++ b/tools/tests/Markdown Pandoc Limitations.ipynb @@ -0,0 +1,2522 @@ +{ + "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", + "" + ] + }, + { + "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=\"
\" \\\n", + " \"
NBConvert Latex Output
\" \\\n", + " \"
\" + latex + \"
\"\\\n", + " \"
\" \\\n", + " \"
\" \\\n", + " \"
\" \\\n", + " \"
NBViewer Output
\" \\\n", + " \"
\" + html + \"
\" \\\n", + " \"
\"))\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", + " $('
')\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=\"
HTML Pandoc Output
\" \\\n", + " \"
\" + html + \"
\"))\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", + " $('
')\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": [ + "" + ] + }, + { + "html": [ + "
NBConvert Latex Output
\\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
NBViewer Output

Heading 1

\n", + "

Heading 2

\n", + "

Heading 3

\n", + "

Heading 4

\n", + "
Heading 5
\n", + "
Heading 6
" + ], + "metadata": {}, + "output_type": "display_data", + "text": [ + "" + ] + }, + { + "javascript": [ + "\n", + " $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n" + ], + "metadata": {}, + "output_type": "display_data", + "text": [ + "" + ] + } + ], + "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", + " $('
')\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": [ + "" + ] + }, + { + "html": [ + "
NBConvert Latex Output
\\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
NBViewer Output

Heading 1

\n", + "

Heading 2

\n", + "

Heading 3

\n", + "

Heading 4

\n", + "
Heading 5
\n", + "
Heading 6
" + ], + "metadata": {}, + "output_type": "display_data", + "text": [ + "" + ] + }, + { + "javascript": [ + "\n", + " $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n" + ], + "metadata": {}, + "output_type": "display_data", + "text": [ + "" + ] + }, + { + "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", + " $('
')\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": [ + "" + ] + }, + { + "html": [ + "
NBConvert Latex Output
\\href{http://127.0.0.1:8888/0a2d8086-ee24-4e5b-a32b-f66b525836cb\\#General-markdown}{Link2Heading}
NBViewer Output
" + ], + "metadata": {}, + "output_type": "display_data", + "text": [ + "" + ] + }, + { + "javascript": [ + "\n", + " $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n" + ], + "metadata": {}, + "output_type": "display_data", + "text": [ + "" + ] + } + ], + "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", + " $('
')\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": [ + "" + ] + }, + { + "html": [ + "
NBConvert Latex Output
This is Markdown \\textbf{bold} and \\emph{italic} text.
NBViewer Output

This is Markdown bold and italic text.

" + ], + "metadata": {}, + "output_type": "display_data", + "text": [ + "" + ] + }, + { + "javascript": [ + "\n", + " $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n" + ], + "metadata": {}, + "output_type": "display_data", + "text": [ + "" + ] + } + ], + "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", + " $('
')\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": [ + "" + ] + }, + { + "html": [ + "
NBConvert Latex Output
\\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}
NBViewer Output
    \n", + "
  • li 1
  • \n", + "
  • li 2\n", + "
      \n", + "
    1. li 3
    2. \n", + "
    3. li 4
    4. \n", + "
  • \n", + "
  • li 5
  • \n", + "
" + ], + "metadata": {}, + "output_type": "display_data", + "text": [ + "" + ] + }, + { + "javascript": [ + "\n", + " $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n" + ], + "metadata": {}, + "output_type": "display_data", + "text": [ + "" + ] + } + ], + "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", + " $('
')\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": [ + "" + ] + }, + { + "html": [ + "
NBConvert Latex Output
\u00fcberschu\u00df +\\emph{*}\\^{}\u00b0\u00b3\u00b3 \u03b1 \u03b2 \u03b8
NBViewer Output

\u00fcberschu\u00df +*^\u00b0\u00b3\u00b3 \u03b1 \u03b2 \u03b8

" + ], + "metadata": {}, + "output_type": "display_data", + "text": [ + "" + ] + }, + { + "javascript": [ + "\n", + " $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n" + ], + "metadata": {}, + "output_type": "display_data", + "text": [ + "" + ] + } + ], + "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", + " $('
')\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": [ + "" + ] + }, + { + "html": [ + "
NBConvert Latex Output
\\section{Heading 1 \\sout{strikeout}}
NBViewer Output

Heading 1 strikeout

" + ], + "metadata": {}, + "output_type": "display_data", + "text": [ + "" + ] + }, + { + "javascript": [ + "\n", + " $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n" + ], + "metadata": {}, + "output_type": "display_data", + "text": [ + "" + ] + } + ], + "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", + " $('
')\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": [ + "" + ] + }, + { + "html": [ + "
NBConvert Latex Output
above\n",
+        "\n",
+        "\\begin{center}\\rule{3in}{0.4pt}\\end{center}\n",
+        "\n",
+        "below
NBViewer Output

above

\n", + "
\n", + "

below

" + ], + "metadata": {}, + "output_type": "display_data", + "text": [ + "" + ] + }, + { + "javascript": [ + "\n", + " $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n" + ], + "metadata": {}, + "output_type": "display_data", + "text": [ + "" + ] + } + ], + "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", + " $('
')\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": [ + "" + ] + }, + { + "html": [ + "
NBConvert Latex Output
This is Markdown \\textsubscript{subscript} and\n",
+        "\\textsuperscript{superscript} text.
NBViewer Output

This is Markdown subscript and superscript text.

" + ], + "metadata": {}, + "output_type": "display_data", + "text": [ + "" + ] + }, + { + "javascript": [ + "\n", + " $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n" + ], + "metadata": {}, + "output_type": "display_data", + "text": [ + "" + ] + } + ], + "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", + " $('
')\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": [ + "" + ] + }, + { + "html": [ + "
NBConvert Latex Output
This is Markdown not\\_italic\\_.
NBViewer Output

This is Markdown not_italic_.

" + ], + "metadata": {}, + "output_type": "display_data", + "text": [ + "" + ] + }, + { + "javascript": [ + "\n", + " $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n" + ], + "metadata": {}, + "output_type": "display_data", + "text": [ + "" + ] + } + ], + "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", + " $('
')\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": [ + "" + ] + }, + { + "html": [ + "
NBConvert Latex Output
\\newcommand{\\tuple}[1]{\\langle #1 \\rangle}\n",
+        "\n",
+        "$\\tuple{a, b, c}$
NBViewer Output

\\(\\langle a, b, c \\rangle\\)

" + ], + "metadata": {}, + "output_type": "display_data", + "text": [ + "" + ] + }, + { + "javascript": [ + "\n", + " $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n" + ], + "metadata": {}, + "output_type": "display_data", + "text": [ + "" + ] + } + ], + "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", + " $('
')\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": [ + "" + ] + }, + { + "html": [ + "
NBConvert Latex Output
$\\newcommand{\\foo}[1]{...:: #1 ::...}$ $\\foo{bar}$
NBViewer Output

\\(\\newcommand{\\foo}[1]{...:: #1 ::...}\\) \\(\\foo{bar}\\)

" + ], + "metadata": {}, + "output_type": "display_data", + "text": [ + "" + ] + }, + { + "javascript": [ + "\n", + " $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n" + ], + "metadata": {}, + "output_type": "display_data", + "text": [ + "" + ] + } + ], + "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 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 HTML 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", + " $('
')\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": [ + "" + ] + }, + { + "html": [ + "
NBConvert Latex Output
This is HTML bold and italic text.
NBViewer Output

This is HTML bold and italic text.

" + ], + "metadata": {}, + "output_type": "display_data", + "text": [ + "" + ] + }, + { + "javascript": [ + "\n", + " $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n" + ], + "metadata": {}, + "output_type": "display_data", + "text": [ + "" + ] + } + ], + "prompt_number": 14 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Same for something like center" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "compare_render(r\"\"\"\n", + "
Center aligned
\n", + "\"\"\")" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "javascript": [ + "\n", + "var mdcell = new IPython.MarkdownCell();\n", + "mdcell.create_element();\n", + "mdcell.set_text('\\n
Center aligned
\\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", + " $('
')\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": [ + "" + ] + }, + { + "html": [ + "
NBConvert Latex Output
Center aligned
NBViewer Output
\n", + "Center aligned\n", + "
" + ], + "metadata": {}, + "output_type": "display_data", + "text": [ + "" + ] + }, + { + "javascript": [ + "\n", + " $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n" + ], + "metadata": {}, + "output_type": "display_data", + "text": [ + "" + ] + } + ], + "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", + " $('
')\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": [ + "" + ] + }, + { + "html": [ + "
NBConvert Latex Output
This is \\LaTeX \\bf{bold} and \\emph{italic} text.
NBViewer Output

This is

" + ], + "metadata": {}, + "output_type": "display_data", + "text": [ + "" + ] + }, + { + "javascript": [ + "\n", + " $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n" + ], + "metadata": {}, + "output_type": "display_data", + "text": [ + "" + ] + } + ], + "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\\$ar $$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\\\\$ar $$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", + " $('
')\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": [ + "" + ] + }, + { + "html": [ + "
NBConvert Latex Output
\\textbf{foo} $\\left( \\sum_{k=1}^n a_k b_k \\right)^2 \\leq$ b\\$ar \\[test\\]\n",
+        "\\cite{}
NBViewer Output

foo \\(\\left( \\sum_{k=1}^n a_k b_k \\right)^2 \\leq\\) b$ar \\[test\\]

" + ], + "metadata": {}, + "output_type": "display_data", + "text": [ + "" + ] + }, + { + "javascript": [ + "\n", + " $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n" + ], + "metadata": {}, + "output_type": "display_data", + "text": [ + "" + ] + } + ], + "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", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
ab
cd
\n", + "\"\"\")" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "javascript": [ + "\n", + "var mdcell = new IPython.MarkdownCell();\n", + "mdcell.create_element();\n", + "mdcell.set_text('\\n\\n \\n \\n \\n \\n \\n \\n \\n \\n
ab
cd
\\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", + " $('
')\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": [ + "" + ] + }, + { + "html": [ + "
NBConvert Latex Output
a\n",
+        "\n",
+        "b\n",
+        "\n",
+        "c\n",
+        "\n",
+        "d
NBViewer Output
\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
\n", + "a\n", + "\n", + "b\n", + "
\n", + "c\n", + "\n", + "d\n", + "
" + ], + "metadata": {}, + "output_type": "display_data", + "text": [ + "" + ] + }, + { + "javascript": [ + "\n", + " $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n" + ], + "metadata": {}, + "output_type": "display_data", + "text": [ + "" + ] + } + ], + "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", + " $('
')\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": [ + "" + ] + }, + { + "html": [ + "
NBConvert Latex Output
\\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}
NBViewer Output
\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "

a

b

c

d

" + ], + "metadata": {}, + "output_type": "display_data", + "text": [ + "" + ] + }, + { + "javascript": [ + "\n", + " $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n" + ], + "metadata": {}, + "output_type": "display_data", + "text": [ + "" + ] + } + ], + "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", + " $('
')\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": [ + "" + ] + }, + { + "html": [ + "
NBConvert Latex Output
\\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}
NBViewer Output
\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "
LeftCenterRight
Text1Text2Text3
" + ], + "metadata": {}, + "output_type": "display_data", + "text": [ + "" + ] + }, + { + "javascript": [ + "\n", + " $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n" + ], + "metadata": {}, + "output_type": "display_data", + "text": [ + "" + ] + } + ], + "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", + " $('
')\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": [ + "" + ] + }, + { + "html": [ + "
NBConvert Latex Output
\\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}
NBViewer Output
\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "
Right AlignedCenter AlignedLeft Aligned
Whydoesthis
actuallywork?Who
knows...
" + ], + "metadata": {}, + "output_type": "display_data", + "text": [ + "" + ] + }, + { + "javascript": [ + "\n", + " $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n" + ], + "metadata": {}, + "output_type": "display_data", + "text": [ + "" + ] + }, + { + "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", + " $('
')\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": [ + "" + ] + }, + { + "html": [ + "
NBConvert Latex Output
\\begin{figure}[htbp]\n",
+        "\\centering\n",
+        "\\includegraphics{http://ipython.org/_static/IPy_header.png}\n",
+        "\\caption{Alternate Text}\n",
+        "\\end{figure}
NBViewer Output
\n", + "\"Alternate

Alternate Text

\n", + "
" + ], + "metadata": {}, + "output_type": "display_data", + "text": [ + "" + ] + }, + { + "javascript": [ + "\n", + " $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n" + ], + "metadata": {}, + "output_type": "display_data", + "text": [ + "" + ] + } + ], + "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", + "\n", + "\"\"\")" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "javascript": [ + "\n", + "var mdcell = new IPython.MarkdownCell();\n", + "mdcell.create_element();\n", + "mdcell.set_text('\\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", + " $('
')\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": [ + "" + ] + }, + { + "html": [ + "
NBConvert Latex Output
NBViewer Output

" + ], + "metadata": {}, + "output_type": "display_data", + "text": [ + "" + ] + }, + { + "javascript": [ + "\n", + " $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n" + ], + "metadata": {}, + "output_type": "display_data", + "text": [ + "" + ] + } + ], + "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", + " $('
')\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": [ + "" + ] + }, + { + "html": [ + "
NBConvert Latex Output
My equation: \\[ 5/x=2y \\]\n",
+        "\n",
+        "It is inline \\$ 5/x=2y \\$ here.
NBViewer Output

My equation: \\[ 5/x=2y \\]

\n", + "

It is inline $ 5/x=2y $ here.

" + ], + "metadata": {}, + "output_type": "display_data", + "text": [ + "" + ] + }, + { + "javascript": [ + "\n", + " $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n" + ], + "metadata": {}, + "output_type": "display_data", + "text": [ + "" + ] + } + ], + "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", + " $('
')\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": [ + "" + ] + }, + { + "html": [ + "
NBConvert Latex Output
$5 \\cdot x=2$\n",
+        "\n",
+        "\\$ 5 \\cdot x=2\\$\n",
+        "\n",
+        "\\$ 5 \\cdot x=2 \\$
NBViewer Output

\\(5 \\cdot x=2\\)

\n", + "

$ 5 x=2$

\n", + "

$ 5 x=2 $

" + ], + "metadata": {}, + "output_type": "display_data", + "text": [ + "" + ] + }, + { + "javascript": [ + "\n", + " $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n" + ], + "metadata": {}, + "output_type": "display_data", + "text": [ + "" + ] + } + ], + "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", + " $('
')\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": [ + "" + ] + }, + { + "html": [ + "
NBConvert Latex Output
\\begin{align}\n",
+        "a & b\\\\\n",
+        "d & c\n",
+        "\\end{align}\n",
+        "\n",
+        "\\begin{eqnarray}\n",
+        "a & b \\\\\n",
+        "c & d\n",
+        "\\end{eqnarray}
NBViewer Output
" + ], + "metadata": {}, + "output_type": "display_data", + "text": [ + "" + ] + }, + { + "javascript": [ + "\n", + " $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n" + ], + "metadata": {}, + "output_type": "display_data", + "text": [ + "" + ] + } + ], + "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", + " $('
')\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": [ + "" + ] + }, + { + "html": [ + "
NBConvert Latex Output
14 is false.\n",
+        "\n",
+        "$14$ is false.\n",
+        "\n",
+        "1
NBViewer Output

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.

" + ], + "metadata": {}, + "output_type": "display_data", + "text": [ + "" + ] + }, + { + "javascript": [ + "\n", + " $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n" + ], + "metadata": {}, + "output_type": "display_data", + "text": [ + "" + ] + } + ], + "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", + " $('
')\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": [ + "" + ] + }, + { + "html": [ + "
NBConvert Latex Output
some source code\n",
+        "\n",
+        "\\begin{verbatim}\n",
+        "a = \"test\"\n",
+        "print(a)\n",
+        "\\end{verbatim}
NBViewer Output

some source code

\n", + "
a = "test"\n",
+        "print(a)
" + ], + "metadata": {}, + "output_type": "display_data", + "text": [ + "" + ] + }, + { + "javascript": [ + "\n", + " $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n" + ], + "metadata": {}, + "output_type": "display_data", + "text": [ + "" + ] + } + ], + "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", + " $('
')\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": [ + "" + ] + }, + { + "html": [ + "
NBConvert Latex Output
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}
NBViewer Output

some source code

\n", + "
a = "test"\n",
+        "print(a)
" + ], + "metadata": {}, + "output_type": "display_data", + "text": [ + "" + ] + }, + { + "javascript": [ + "\n", + " $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n" + ], + "metadata": {}, + "output_type": "display_data", + "text": [ + "" + ] + } + ], + "prompt_number": 29 + } + ], + "metadata": {} + } + ] +} \ No newline at end of file