Windows + Jupyter Notebook + MiKTeX + Pandoc output PDF

Source: Internet
Author: User
Tags jupyter jupyter notebook

1. Install miktex1. Download install MikTeX2. Update maintenance (Admin), MiKTeX Update (Admin) 3. Configure Chinese

Maintenance (Admin), Settings (admin), select Packages tab, select the option under Language support "Chinese,japanese, Korea N "Application

the next step is to open the Command window (execute as Administrator) "

Initexmf-u

INITEXMF--edit-config-file Updmap

A notebook will appear, and we will enter the font to be enabled:

 for Help . Map cwmu.mapmap cwku.mapmap cwfsu.mapmap cwhbu.mapmap cwyu.map

Save, close, and then enter the command in the console:

INITEXMF--mkmaps

And then it's waiting, and when the order is done, it's finished.

2. Installing Pandoc

Open ARTICLE.TPLX (\python27\lib\site-packages\nbconvert\templates\latex\) with a text editor and change to

\documentclass{ctexart}

3.try1. Try the command line

Compiling IPYNB to Tex

Ipython nbconvert--to Latex example.ipynb

Compiling Tex, generating PDF

Xelatex Example.tex

2.Jupyter Notebook Test

3. Take another pose, one more time.

ipynb2pdf.py

#Coding:utf-8ImportSYSImportOSImportReImportShutilnotebook= Sys.argv[1]texfile= Notebook.replace ('. IPYNB','. Tex')#1.convert. ipynb to Latex file. Tex#Convert ipynb file to Tex filePrint '1. Convert'+ Notebook +' to'+TexfilePrint '------\ n'Os.system (R'jupyter nbconvert--to latex'+notebook)Print 'Convert over'#2. Add Chinese support by adding the string below#Add the referenced package to enable Chinese (direct conversion to Chinese will be lost)#\usepackage{fontspec, Xunicode, Xltxtra}#\setmainfont{microsoft Yahei}#\usepackage{ctex}Print '2. Add Chinese support to. tex file' Print '------'file= Open (Texfile,'R') Str_file=file.read () strinfo= Re.compile ('(documentclass[\d\d]+\{article\})')#find the character line0m=Re.findall (strinfo,str_file)ifLen (m) = =0:PrintR'can not find documentclass[**pt]{article}'Sys.exit (1) Str_file= Strinfo.sub ('\\1 \ \\usepackage{fontspec, Xunicode, Xltxtra} \ n \\setmainfont{microsoft Yahei} \ r \\usepackage{ctex}', Str_file)#Replace the character line1file.close () file= Open (Texfile,'W') File.write (str_file) file.close ()Print 'add Chinese support successed'#3. Convert Tex to. pdf by Xelatex#compile the. tex file using the Xelatex command to get a PDFPrint  '3. Convert Tex to PDF'Print '------'Os.system ('Xelatex'+texfile)Print  'Convert PDF successed'#4. Delete the auxiliary files#clean up the resulting intermediate file#Change There if latex file is neededPrint '4. Delete auxiliary files'Print '------'Os.remove (Notebook.replace ('. IPYNB','. Aux')) Os.remove (Notebook.replace ('. IPYNB','. Log')) Os.remove (Notebook.replace ('. IPYNB','. out'))#Change There if latex file is neededOs.remove (Notebook.replace ('. IPYNB','. Tex'))ifOs.path.isdir (Notebook.replace ('. IPYNB','_files')): Shutil.rmtree (Notebook.replace ('. IPYNB','_files'))Print 'Delete auxiliary files successed'
View Code

Python ipynb2pdf.py example.ipynb

is also converted to an executable file after use

Ipynb2pdf.exe EXAMPLE.IPYNB

Windows + Jupyter Notebook + MiKTeX + Pandoc output PDF

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.