Convert Jupyter Notebook with CJK to PDF on MacOS
Install Dependencies
Follow nbconvert Installation Guide to install dependencies.
|
|
Install CJK Font
Use system font or install any CJK font. I recommend Sarasa Gothic (更纱黑体 / 更紗黑體 / 更紗ゴシック / 사라사고딕).
|
|
Convert the Notebook to PDF
-
Convert the notebook to tex
1
jupyter nbconvert --to latex notebook-to-convert.ipynb
-
Modify the tex file to add CJK package and set CJK font
Insert the 2nd and 3rd lines below into notebook-to-convert.tex. Make sure the font is available in system.
1 2 3 4 5
\documentclass[11pt]{article} \usepackage[slantfont, boldfont]{xeCJK} \setCJKmainfont{Sarasa UI SC} \usepackage[breakable]{tcolorbox} \usepackage{parskip} % Stop auto-indenting (to mimic markdown behaviour)
-
Convert tex to pdf
1
xelatex notebook-to-convert.tex
Shell Script Helper
|
|