Sitemap
Sparisoma Viridi

Sparisoma Viridi

butiran-x.github.io

Install Pandoc for Jupyter Notebook

A short step-by-step guide for Windows 11

6 min readAug 11, 2024

--

A notebook can be converted to other format using nbconvert, which uses Pandoc under the hood for certain conversion tasks (GPT 4–0, 2024). In this story steps to install Pandoc executable and related Pyhton packages, MiKTeX executable and also its packages, and how use them in a notebook to convert the notebook to PDF are given.

Requirements

It is assumed that you have already a Python virtual environment with nbconvert, where in this story it is named tf, created for learning TensorFlow. You can replace it with any available of your virtual environments. If you like to use thetf virtual environment, clone it first (Viridi, 2024).

Download Pandoc installer

Visit download page for available Pandoc installers https://github.com/jgm/pandoc/releases/tag/3.3.

Press enter or click to view image in full size

For Windows 11, you can choose pandoc-3.3-windows-x86_64.msi. Download it to your local folder.

Press enter or click to view image in full size

Save it to your installer folder if necessary for future use in the case when internet connection is not available.

Install Pandoc

Click the file pandoc-3.3-windows-x86_64.msi to start the installation.

Press enter or click to view image in full size

Scroll down, check “I accept the terms in the License Agreement”, and click Install button.

Press enter or click to view image in full size

Wait for the installation process.

Press enter or click to view image in full size

Click Finish button to end the installation.

V:\>pandoc --version
'pandoc' is not recognized as an internal or external command,
operable program or batch file.

V:\>

It confirms that opened cmd or Powershell window requires restart.

Press enter or click to view image in full size

After reopen the cmd window, it shows that pandoc command is recognized.

Install Python package

It is not necessary to visit https://pypi.org/project/pandoc/ for downloading the package.

Press enter or click to view image in full size

Open cmd and activate the tf virtual environment or any of yours.

Press enter or click to view image in full size

Check whether Pandoc package already installed.

Press enter or click to view image in full size

It shows that Pandoc package is not installed. Then install the package.

Press enter or click to view image in full size

It installs pandoc-2.4 and two required packages plumbum-1.8.3 and ply-3.11.

Press enter or click to view image in full size

pip shows also pandoc is installed and it requires plumbum and ply.

Download and install MiKTeX

In order to use XeLaTeX required by nbconvert and pandoc you require to install MiKTex. Visit https://miktex.org/download.

Press enter or click to view image in full size

Download the file basic-miktex-24.1-x64.exe to your local folder.

Press enter or click to view image in full size

Click the installer and start the installation.

Press enter or click to view image in full size

Read the Copying conditions and check “I accept the MiKTex copying conditions”. Then click Next button.

Press enter or click to view image in full size

Use default option and click Next button.

Press enter or click to view image in full size

Change location to install MiKTex or simply click Next button to continue.

Press enter or click to view image in full size

Use recommended options and click Next button.

Press enter or click to view image in full size

Review the settings, if any changes required click Back button and do the changes, or click Start button to proceed the installation.

Press enter or click to view image in full size

Wait for the installation process.

Press enter or click to view image in full size

Click Next button to continue.

Press enter or click to view image in full size

Click Next button to check updates.

Press enter or click to view image in full size

Click Close button to exit installation wizard.

Press enter or click to view image in full size

You can support MixTeX project. Close the window. To check whether it can be accessed via cmd, open a cmd window.

Press enter or click to view image in full size

It shows that MiKTeX 24.1 is available in the system.

Install MiXTeX packages

While use pandoc for converting Notebook according to PDF (Fahrizain, 2022)

(tf) M:\edu-flow-lake>jupyter nbconvert --to pdf src\exercise_1\create
_simple_report_on_admission.ipynb

it still requires package installation for MiKTeX, e.g. pdfcol, and a window pops up as follow.

Press enter or click to view image in full size

Solve the problem by clicking Install button to proceed. But it will also further ask for ltxcmds, infwarerr, parskip, kvoptions, kvsetkeys, caption, float, geometry, upquote, eurosym, unicode-math, fancyvrb, grffile, adjustbox, collectbox, ifoddpage, varwidth, kvdefinekeys, pdfescape, hycolor, letltxmacro, auxhook, refcount, gettitlestring, intcalc, bitset, bigintcalc, stringenc, rerunfilechek, uniquecounter, titling, booktabs, enumitem, ulem, soul, etexcmds, jknappen, ..

Get Sparisoma Viridi’s stories in your inbox

Join Medium for free to get updates from this writer.

To use more efficient way use MiKTeX console. Use Windows Key ⊞ and tyle miktex console, press Enter key.

Press enter or click to view image in full size

Click Check for updates.

Press enter or click to view image in full size

Click Updates (113) on navigation menu. And click Update now button.

Press enter or click to view image in full size

Wait for the installation progress.

Press enter or click to view image in full size

Click OK to close MiKTeX console.

Launch Jupyter Notebook

Open cmd, activate virtual environment, and use

(tf) M:\edu-flow-lake>jupyter notebook

to launch Jupyter Notebook.

Press enter or click to view image in full size

In this story the example is simple_report_on_admission.ipynb. Click it to open.

Press enter or click to view image in full size

Above is beginng of the notebook file and below is the end.

Press enter or click to view image in full size

Cell [2] is for converting notebook to latex, while cell [3] is for converting from latex to pdf, since the direct way (Fahrizain, 2022) does not work.

Press enter or click to view image in full size

Two pages of the PDF output are shown above.

Following are the files

that you can further explore.

Summaries

After read this story you are able to

  • install Pandoc executable and related Python packages,
  • install MiKTeX,
  • use Pandoc via nbconvert to convert notebook to latex,
  • use XeLaTeX (in MiKTeX) to convert latex to pdf.

Error messages

Some error messages are obtained during installation.

  • Before installing Pandoc.
..
File "V:\tf\Lib\site-packages\nbconvert\utils\pandoc.py",
line 75, in get_pandoc_version raise PandocMissing()
nbconvert.utils.pandoc.PandocMissing: Pandoc wasn't found.
Please check that pandoc is installed:
https://pandoc.org/installing.html
  • Before installing MiKTeX.
..
File "V:\tf\Lib\site-packages\nbconvert\exporters\pdf.py",
line 120, in run_command raise OSError(msg)
OSError: xelatex not found on PATH, if you have not installed
xelatex you may need to do so. Find further instructions at
https://nbconvert.readthedocs.io/en/latest/install.html#installing-tex.
  • After installing MiKTeX packages using MiKTeX console.
  File "V:\tf\Lib\site-packages\nbconvert\exporters\pdf.py",
line 156, in run_command raise raise_on_failure(msg)
nbconvert.exporters.pdf.LatexFailed: PDF creating failed,
captured latex output:
Failed to run "xelatex notebook.tex -quiet"
command:

Above error messages are kept for documentation only. A direct conversion from from notebook to latex can not be performed.

Thanks to Affandy Fahrizain for the clue.

--

--