{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "**WARNING: This document will not render correctly using nbviewer or nbconvert. To render this notebook correctly, open in `IPython Notebook` and run `Cell->Run All` from the menu bar.**" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Introduction" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The IPython Notebook allows Markdown, HTML, and inline LaTeX in *Mardown Cells*. The inline LaTeX is parsed with [MathJax](http://www.mathjax.org/) and Markdown is parsed with [marked](https://github.com/chjj/marked). Any inline HTML is left to the web browser to parse. NBConvert is a utility that allows users to easily convert their notebooks to various formats. Pandoc is used to parse markdown text in NBConvert. Since what the notebook web interface supports is a mix of Markdown, HTML, and LaTeX, Pandoc has trouble converting notebook markdown. This results in incomplete representations of the notebook in nbviewer or a compiled Latex PDF.\n", "\n", "This isn't a Pandoc flaw; Pandoc isn't designed to parse and convert a mixed format document. Unfortunately, this means that Pandoc can only support a subset of the markup supported in the notebook web interface. This notebook compares output of Pandoc to the notebook web interface.\n", "\n", "**Changes:**\n", "\n", "05102013\n", "\n", " * heading anchors\n", " * note on remote images\n", "\n", "06102013\n", "\n", " * remove strip_math_space filter\n", " * add lxml test\n", " \n", "" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Utilities" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Define functions to render Markdown using the notebook and Pandoc." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from IPython.nbconvert.utils.pandoc import pandoc\n", "from IPython.display import HTML, Javascript, display\n", "\n", "from IPython.nbconvert.filters import citation2latex, strip_files_prefix, \\\n", " markdown2html, markdown2latex\n", "\n", "def pandoc_render(markdown):\n", " \"\"\"Render Pandoc Markdown->LaTeX content.\"\"\"\n", " \n", " ## Convert the markdown directly to latex. This is what nbconvert does.\n", " #latex = pandoc(markdown, \"markdown\", \"latex\")\n", " #html = pandoc(markdown, \"markdown\", \"html\", [\"--mathjax\"])\n", " \n", " # nbconvert template conversions\n", " html = strip_files_prefix(markdown2html(markdown))\n", " latex = markdown2latex(citation2latex(markdown))\n", " display(HTML(data=\"
\" \\\n", " \"
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)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Outputs" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "LXML found!\n" ] } ], "source": [ "try:\n", " import lxml\n", " print 'LXML found!'\n", "except:\n", " print 'Warning! No LXML found - the old citation2latex filter will not work'" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## General markdown" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Heading level 6 is not supported by Pandoc." ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [ { "data": { "application/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" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "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
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "\n", " $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "compare_render(r\"\"\"\n", "\n", "# Heading 1 \n", "## Heading 2 \n", "### Heading 3 \n", "#### Heading 4 \n", "##### Heading 5 \n", "###### Heading 6\"\"\")" ] }, { "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", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [ { "data": { "application/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" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "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
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "\n", " $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n" ] } ], "source": [ "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)" ] }, { "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", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { "data": { "application/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" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
NBConvert Latex Output
\\href{http://127.0.0.1:8888/0a2d8086-ee24-4e5b-a32b-f66b525836cb\\#General-markdown}{Link2Heading}
NBViewer Output
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "\n", " $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "compare_render(r\"\"\"\n", "[Link2Heading](http://127.0.0.1:8888/0a2d8086-ee24-4e5b-a32b-f66b525836cb#General-markdown)\n", "\"\"\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Basic Markdown bold and italic works." ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [ { "data": { "application/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" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
NBConvert Latex Output
This is Markdown \\textbf{bold} and \\emph{italic} text.
NBViewer Output

This is Markdown bold and italic text.

" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "\n", " $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "compare_render(r\"\"\"\n", "This is Markdown **bold** and *italic* text.\n", "\"\"\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Nested lists work as well" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false }, "outputs": [ { "data": { "application/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" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "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", "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "\n", " $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "compare_render(r\"\"\"\n", "- li 1\n", "- li 2\n", " 1. li 3\n", " 1. li 4\n", "- li 5\n", "\"\"\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Unicode support" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": false }, "outputs": [ { "data": { "application/javascript": [ "\n", "var mdcell = new IPython.MarkdownCell();\n", "mdcell.create_element();\n", "mdcell.set_text('\\nüberschuß +***^°³³ α β θ\\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" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
NBConvert Latex Output
überschuß +\\emph{*}\\^{}°³³ α β θ
NBViewer Output

überschuß +*^°³³ α β θ

" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "\n", " $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "compare_render(ur\"\"\"\n", "überschuß +***^°³³ α β θ\n", "\"\"\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Pandoc may produce invalid latex, e.g \\sout is not allowed in headings" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": false }, "outputs": [ { "data": { "application/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" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
NBConvert Latex Output
\\section{Heading 1 \\sout{strikeout}}
NBViewer Output

Heading 1 strikeout

" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "\n", " $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "compare_render(r\"\"\"\n", "\n", "# Heading 1 ~~strikeout~~\n", "\"\"\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Horizontal lines work just fine" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "collapsed": false }, "outputs": [ { "data": { "application/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" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "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

" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "\n", " $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "compare_render(r\"\"\"\n", "above\n", "\n", "--------\n", "\n", "below\n", "\"\"\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Extended markdown of pandoc" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "(maybe we should deactivate this) " ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "collapsed": false }, "outputs": [ { "data": { "application/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" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "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.

" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "\n", " $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "compare_render(r\"\"\"\n", "This is Markdown ~subscript~ and ^superscript^ text.\n", "\"\"\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "No space before underline behaves inconsistent (Pandoc extension: intraword_underscores - deactivate?)" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "collapsed": false }, "outputs": [ { "data": { "application/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" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
NBConvert Latex Output
This is Markdown not\\_italic\\_.
NBViewer Output

This is Markdown not_italic_.

" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "\n", " $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "compare_render(r\"\"\"\n", "This is Markdown not_italic_.\n", "\"\"\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Pandoc allows to define tex macros which are respected for all output formats, the notebook not. " ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "collapsed": false }, "outputs": [ { "data": { "application/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" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "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\\)

" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "\n", " $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "compare_render(r\"\"\"\n", "\\newcommand{\\tuple}[1]{\\langle #1 \\rangle}\n", "\n", "$\\tuple{a, b, c}$\n", "\"\"\")" ] }, { "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", "execution_count": 13, "metadata": { "collapsed": false }, "outputs": [ { "data": { "application/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" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
NBConvert Latex Output
$\\newcommand{\\foo}[1]{...:: #1 ::...}$ $\\foo{bar}$
NBViewer Output

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

" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "\n", " $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "compare_render(r\"\"\"\n", "$\\newcommand{\\foo}[1]{...:: #1 ::...}$\n", "$\\foo{bar}$\n", "\"\"\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## HTML or LaTeX injections" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Raw HTML gets dropped entirely when converting to $\\LaTeX$." ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "collapsed": false }, "outputs": [ { "data": { "application/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" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
NBConvert Latex Output
This is HTML bold and italic text.
NBViewer Output

This is HTML bold and italic text.

" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "\n", " $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "compare_render(r\"\"\"\n", "This is HTML bold and italic text.\n", "\"\"\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Same for something like center" ] }, { "cell_type": "code", "execution_count": 15, "metadata": { "collapsed": false }, "outputs": [ { "data": { "application/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" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
NBConvert Latex Output
Center aligned
NBViewer Output
\n", "Center aligned\n", "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "\n", " $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "compare_render(r\"\"\"\n", "
Center aligned
\n", "\"\"\")" ] }, { "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", "execution_count": 16, "metadata": { "collapsed": false }, "outputs": [ { "data": { "application/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" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
NBConvert Latex Output
This is \\LaTeX \\bf{bold} and \\emph{italic} text.
NBViewer Output

This is

" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "\n", " $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "compare_render(r\"\"\"\n", "This is \\LaTeX \\bf{bold} and \\emph{italic} text.\n", "\"\"\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "A combination of raw $\\LaTeX$ and raw HTML" ] }, { "cell_type": "code", "execution_count": 17, "metadata": { "collapsed": false }, "outputs": [ { "data": { "application/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" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "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\\]

" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "\n", " $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "compare_render(r\"\"\"\n", "**foo** $\\left( \\sum_{k=1}^n a_k b_k \\right)^2 \\leq$ b\\$ar $$test$$ \n", "\\cite{}\n", "\"\"\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Tables" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "HTML tables render in the notebook, but not in Pandoc." ] }, { "cell_type": "code", "execution_count": 18, "metadata": { "collapsed": false }, "outputs": [ { "data": { "application/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" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "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", "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "\n", " $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "compare_render(r\"\"\"\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
ab
cd
\n", "\"\"\")" ] }, { "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", "execution_count": 19, "metadata": { "collapsed": false }, "outputs": [ { "data": { "application/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" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "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

" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "\n", " $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "compare_render(r\"\"\"\n", "+---+---+\n", "| a | b |\n", "+---+---+\n", "| c | d |\n", "+---+---+\n", "\"\"\")" ] }, { "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", "execution_count": 20, "metadata": { "collapsed": false }, "outputs": [ { "data": { "application/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" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "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
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "\n", " $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "compare_render(r\"\"\"\n", "|Left |Center |Right|\n", "|:----|:-----:|----:|\n", "|Text1|Text2 |Text3|\n", "\"\"\")" ] }, { "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", "execution_count": 21, "metadata": { "collapsed": false }, "outputs": [ { "data": { "application/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" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "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...
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "\n", " $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "\n", "\n", "\n", "\n", "\n", "\n" ] } ], "source": [ "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)" ] }, { "cell_type": "markdown", "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", "execution_count": 22, "metadata": { "collapsed": false }, "outputs": [ { "data": { "application/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" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "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", "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "\n", " $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "compare_render(r\"\"\"\n", "![Alternate Text](http://ipython.org/_static/IPy_header.png)\n", "\"\"\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "HTML Images only work in the notebook." ] }, { "cell_type": "code", "execution_count": 23, "metadata": { "collapsed": false }, "outputs": [ { "data": { "application/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" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
NBConvert Latex Output
NBViewer Output

" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "\n", " $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "compare_render(r\"\"\"\n", "\n", "\"\"\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Math" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Simple inline and displaystyle maths work fine" ] }, { "cell_type": "code", "execution_count": 24, "metadata": { "collapsed": false }, "outputs": [ { "data": { "application/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" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "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.

" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "\n", " $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "compare_render(r\"\"\"\n", "My equation:\n", "$$ 5/x=2y $$\n", "\n", "It is inline $ 5/x=2y $ here.\n", "\"\"\")" ] }, { "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", "execution_count": 25, "metadata": { "collapsed": false }, "outputs": [ { "data": { "application/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" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "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 $

" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "\n", " $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "compare_render(r\"\"\"\n", "$5 \\cdot x=2$\n", "\n", "$\n", "5 \\cdot x=2$\n", "\n", "$\n", "5 \\cdot x=2\n", "$\n", "\"\"\")" ] }, { "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", "execution_count": 26, "metadata": { "collapsed": false }, "outputs": [ { "data": { "application/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" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "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
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "\n", " $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "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", "\"\"\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "There is another lxml issue, [#4283](https://github.com/ipython/ipython/issues/4283)" ] }, { "cell_type": "code", "execution_count": 27, "metadata": { "collapsed": false }, "outputs": [ { "data": { "application/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" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "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.

" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "\n", " $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "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", "\"\"\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Listings, and Code blocks" ] }, { "cell_type": "code", "execution_count": 28, "metadata": { "collapsed": false }, "outputs": [ { "data": { "application/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" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "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)
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "\n", " $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "compare_render(r\"\"\"\n", "some source code\n", "\n", "```\n", "a = \"test\"\n", "print(a)\n", "```\n", "\"\"\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Language specific syntax highlighting by Pandoc requires additional dependencies to render correctly." ] }, { "cell_type": "code", "execution_count": 29, "metadata": { "collapsed": false }, "outputs": [ { "data": { "application/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" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "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)
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "\n", " $.getScript(\"https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js\");\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "compare_render(r\"\"\"\n", "some source code\n", "\n", "```python\n", "a = \"test\"\n", "print(a)\n", "```\n", "\"\"\")" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.4.2" } }, "nbformat": 4, "nbformat_minor": 0 }