jupyter / nbconvert

Jupyter Notebook Conversion
https://nbconvert.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
1.75k stars 568 forks source link

Unable to convert .ipynb to .pdf on Mac #2102

Open gigifang925 opened 9 months ago

gigifang925 commented 9 months ago

Hello today I did the following installations brew install --cask mactex-no-gui pip install nbconvert PyPDF2

I can find nbconvert and pyPDF2 in my anaconda (base) environment. However, I failed to convert a very simple .ipynb file with print('hello world') to pdf. The error message is as follows. As a beginner, I may have made basic mistakes in this process. I would appreciate your guidance on fixing that.

nbconvert failed: PDF creating failed, captured latex output: Failed to run "['xelatex', 'notebook.tex', '-quiet']" command: This is XeTeX, Version 3.141592653-2.6-0.999995 (TeX Live 2023) (preloaded format=xelatex) restricted \write18 enabled. entering extended mode (./notebook.tex LaTeX2e <2022-11-01> patch level 1 L3 programming layer <2023-02-22> (/usr/local/texlive/2023/texmf-dist/tex/latex/base/article.cls Document Class: article 2022/07/02 v1.4n Standard LaTeX document class (/usr/local/texlive/2023/texmf-dist/tex/latex/base/size11.clo)) (/usr/local/texlive/2023/texmf-dist/tex/latex/tcolorbox/tcolorbox.sty (/usr/local/texlive/2023/texmf-dist/tex/latex/pgf/basiclayer/pgf.sty (/usr/local/texlive/2023/texmf-dist/tex/latex/pgf/utilities/pgfrcs.sty (/usr/local/texlive/2023/texmf-dist/tex/generic/pgf/utilities/pgfutil-common.te x) (/usr/local/texlive/2023/texmf-dist/tex/generic/pgf/utilities/pgfutil-latex.def ) (/usr/local/texlive/2023/texmf-dist/tex/generic/pgf/utilities/pgfrcs.code.tex (/usr/local/texlive/2023/texmf-dist/tex/generic/pgf/pgf.revision.tex))) (/usr/local/texlive/2023/texmf-dist/tex/latex/pgf/basiclayer/pgfcore.sty (/usr/local/texlive/2023/texmf-dist/tex/latex/graphics/graphicx.sty (/usr/local/texlive/2023/texmf-dist/tex/latex/graphics/keyval.sty) (/usr/local/texlive/2023/texmf-dist/tex/latex/graphics/graphics.sty (/usr/local/texlive/2023/texmf-dist/tex/latex/graphics/trig.sty) (/usr/local/texlive/2023/texmf-dist/tex/latex/graphics-cfg/graphics.cfg) (/usr/local/texlive/2023/texmf-dist/tex/latex/graphics-def/xetex.def))) (/usr/local/texlive/2023/texmf-dist/tex/latex/pgf/systemlayer/pgfsys.sty (/usr/local/texlive/2023/texmf-dist/tex/generic/pgf/systemlayer/pgfsys.code.tex (/usr/local/texlive/2023/texmf-dist/tex/generic/pgf/utilities/pgfkeys.code.tex (/usr/local/texlive/2023/texmf-dist/tex/generic/pgf/utilities/pgfkeyslibraryfil tered.code.tex)) (/usr/local/texlive/2023/texmf-dist/tex/generic/pgf/systemlayer/pgf.cfg) (/usr/local/texlive/2023/texmf-dist/tex/generic/pgf/systemlayer/pgfsys-xetex.de f (/usr/local/texlive/2023/texmf-dist/tex/generic/pgf/systemlayer/pgfsys-dvipdfmx .def (/usr/local/texlive/2023/texmf-dist/tex/generic/pgf/systemlayer/pgfsys-common-p df.def)))) (/usr/local/texlive/2023/texmf-dist/tex/generic/pgf/systemlayer/pgfsyssoftpath. code.tex) (/usr/local/texlive/2023/texmf-dist/tex/generic/pgf/systemlayer/pgfsysprotocol. code.tex)) (/usr/local/texlive/2023/texmf-dist/tex/latex/xcolor/xcolor.sty (/usr/local/texlive/2023/texmf-dist/tex/latex/graphics-cfg/color.cfg) (/usr/local/texlive/2023/texmf-dist/tex/latex/graphics/mathcolor.ltx)) (/usr/local/texlive/2023/texmf-dist/tex/generic/pgf/basiclayer/pgfcore.code.tex (/usr/local/texlive/2023/texmf-dist/tex/generic/pgf/math/pgfmath.code.tex (/usr/local/texlive/2023/texmf-dist/tex/generic/pgf/math/pgfmathutil.code.tex) (/usr/local/texlive/2023/texmf-dist/tex/generic/pgf/math/pgfmathparser.code.tex ) (/usr/local/texlive/2023/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.code. tex) (/usr/local/texlive/2023/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.basic .code.tex) (/usr/local/texlive/2023/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.trigo nometric.code.tex) (/usr/local/texlive/2023/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.rando m.code.tex) (/usr/local/texlive/2023/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.compa rison.code.tex) (/usr/local/texlive/2023/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.base. code.tex) (/usr/local/texlive/2023/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.round .code.tex) (/usr/local/texlive/2023/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.misc. code.tex) (/usr/local/texlive/2023/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.integ erarithmetics.code.tex) (/usr/local/texlive/2023/texmf-dist/tex/generic/pgf/math/pgfmathcalc.code.tex) (/usr/local/texlive/2023/texmf-dist/tex/generic/pgf/math/pgfmathfloat.code.tex) ) (/usr/local/texlive/2023/texmf-dist/tex/generic/pgf/math/pgfint.code.tex) (/usr/local/texlive/2023/texmf-dist/tex/generic/pgf/basiclayer/pgfcorepoints.co de.tex) (/usr/local/texlive/2023/texmf-dist/tex/generic/pgf/basiclayer/pgfcorepathconst ruct.code.tex) (/usr/local/texlive/2023/texmf-dist/tex/generic/pgf/basiclayer/pgfcorepathusage .code.tex) (/usr/local/texlive/2023/texmf-dist/tex/generic/pgf/basiclayer/pgfcorescopes.co de.tex) (/usr/local/texlive/2023/texmf-dist/tex/generic/pgf/basiclayer/pgfcoregraphicst ate.code.tex) (/usr/local/texlive/2023/texmf-dist/tex/generic/pgf/basiclayer/pgfcoretransform ations.code.tex) (/usr/local/texlive/2023/texmf-dist/tex/generic/pgf/basiclayer/pgfcorequick.cod e.tex) (/usr/local/texlive/2023/texmf-dist/tex/generic/pgf/basiclayer/pgfcoreobjects.c ode.tex) (/usr/local/texlive/2023/texmf-dist/tex/generic/pgf/basiclayer/pgfcorepathproce ssing.code.tex) (/usr/local/texlive/2023/texmf-dist/tex/generic/pgf/basiclayer/pgfcorearrows.co de.tex) (/usr/local/texlive/2023/texmf-dist/tex/generic/pgf/basiclayer/pgfcoreshade.cod e.tex) (/usr/local/texlive/2023/texmf-dist/tex/generic/pgf/basiclayer/pgfcoreimage.cod e.tex) (/usr/local/texlive/2023/texmf-dist/tex/generic/pgf/basiclayer/pgfcoreexternal. code.tex) (/usr/local/texlive/2023/texmf-dist/tex/generic/pgf/basiclayer/pgfcorelayers.co de.tex) (/usr/local/texlive/2023/texmf-dist/tex/generic/pgf/basiclayer/pgfcoretranspare ncy.code.tex) (/usr/local/texlive/2023/texmf-dist/tex/generic/pgf/basiclayer/pgfcorepatterns. code.tex) (/usr/local/texlive/2023/texmf-dist/tex/generic/pgf/basiclayer/pgfcorerdf.code. tex))) (/usr/local/texlive/2023/texmf-dist/tex/generic/pgf/modules/pgfmoduleshapes.cod e.tex) (/usr/local/texlive/2023/texmf-dist/tex/generic/pgf/modules/pgfmoduleplot.code. tex) (/usr/local/texlive/2023/texmf-dist/tex/latex/pgf/compatibility/pgfcomp-version -0-65.sty) (/usr/local/texlive/2023/texmf-dist/tex/latex/pgf/compatibility/pgfcomp-version -1-18.sty)) (/usr/local/texlive/2023/texmf-dist/tex/latex/tools/verbatim.sty) (/usr/local/texlive/2023/texmf-dist/tex/latex/environ/environ.sty (/usr/local/texlive/2023/texmf-dist/tex/latex/trimspaces/trimspaces.sty)) (/usr/local/texlive/2023/texmf-dist/tex/latex/etoolbox/etoolbox.sty) (/usr/local/texlive/2023/texmf-dist/tex/latex/tcolorbox/tcbbreakable.code.tex Library (tcolorbox): 'tcbbreakable.code.tex' version '6.0.1' (/usr/local/texlive/2023/texmf-dist/tex/latex/pdfcol/pdfcol.sty (/usr/local/texlive/2023/texmf-dist/tex/generic/ltxcmds/ltxcmds.sty) (/usr/local/texlive/2023/texmf-dist/tex/generic/infwarerr/infwarerr.sty) (/usr/local/texlive/2023/texmf-dist/tex/generic/iftex/iftex.sty)))) (/usr/local/texlive/2023/texmf-dist/tex/latex/parskip/parskip.sty (/usr/local/texlive/2023/texmf-dist/tex/latex/kvoptions/kvoptions.sty (/usr/local/texlive/2023/texmf-dist/tex/latex/kvsetkeys/kvsetkeys.sty))) (/usr/local/texlive/2023/texmf-dist/tex/latex/fontspec/fontspec.sty (/usr/local/texlive/2023/texmf-dist/tex/latex/l3packages/xparse/xparse.sty (/usr/local/texlive/2023/texmf-dist/tex/latex/l3kernel/expl3.sty (/usr/local/texlive/2023/texmf-dist/tex/latex/l3backend/l3backend-xetex.def))) (/usr/local/texlive/2023/texmf-dist/tex/latex/fontspec/fontspec-xetex.sty (/usr/local/texlive/2023/texmf-dist/tex/latex/base/fontenc.sty) (/usr/local/texlive/2023/texmf-dist/tex/latex/fontspec/fontspec.cfg))) (/usr/local/texlive/2023/texmf-dist/tex/latex/caption/caption.sty (/usr/local/texlive/2023/texmf-dist/tex/latex/caption/caption3.sty)) (/usr/local/texlive/2023/texmf-dist/tex/latex/float/float.sty) (/usr/local/texlive/2023/texmf-dist/tex/latex/tools/enumerate.sty) (/usr/local/texlive/2023/texmf-dist/tex/latex/geometry/geometry.sty (/usr/local/texlive/2023/texmf-dist/tex/generic/iftex/ifvtex.sty)) (/usr/local/texlive/2023/texmf-dist/tex/latex/amsmath/amsmath.sty For additional information on amsmath, use the `?' option. (/usr/local/texlive/2023/texmf-dist/tex/latex/amsmath/amstext.sty (/usr/local/texlive/2023/texmf-dist/tex/latex/amsmath/amsgen.sty)) (/usr/local/texlive/2023/texmf-dist/tex/latex/amsmath/amsbsy.sty) (/usr/local/texlive/2023/texmf-dist/tex/latex/amsmath/amsopn.sty)) (/usr/local/texlive/2023/texmf-dist/tex/latex/amsfonts/amssymb.sty (/usr/local/texlive/2023/texmf-dist/tex/latex/amsfonts/amsfonts.sty)) (/usr/local/texlive/2023/texmf-dist/tex/latex/base/textcomp.sty) (/usr/local/texlive/2023/texmf-dist/tex/latex/upquote/upquote.sty) (/usr/local/texlive/2023/texmf-dist/tex/latex/eurosym/eurosym.sty) (/usr/local/texlive/2023/texmf-dist/tex/latex/ucs/ucs.sty (/usr/local/texlive/2023/texmf-dist/tex/latex/ucs/data/uni-global.def)) (/usr/local/texlive/2023/texmf-dist/tex/latex/fancyvrb/fancyvrb.sty) (/usr/local/texlive/2023/texmf-dist/tex/latex/grffile/grffile.sty) (/usr/local/texlive/2023/texmf-dist/tex/latex/adjustbox/adjustbox.sty (/usr/local/texlive/2023/texmf-dist/tex/latex/xkeyval/xkeyval.sty (/usr/local/texlive/2023/texmf-dist/tex/generic/xkeyval/xkeyval.tex (/usr/local/texlive/2023/texmf-dist/tex/generic/xkeyval/xkvutils.tex))) (/usr/local/texlive/2023/texmf-dist/tex/latex/adjustbox/adjcalc.sty) (/usr/local/texlive/2023/texmf-dist/tex/latex/adjustbox/trimclip.sty (/usr/local/texlive/2023/texmf-dist/tex/latex/collectbox/collectbox.sty) (/usr/local/texlive/2023/texmf-dist/tex/latex/adjustbox/tc-xetex.def)) (/usr/local/texlive/2023/texmf-dist/tex/latex/ifoddpage/ifoddpage.sty) (/usr/local/texlive/2023/texmf-dist/tex/latex/varwidth/varwidth.sty)) (/usr/local/texlive/2023/texmf-dist/tex/latex/hyperref/hyperref.sty (/usr/local/texlive/2023/texmf-dist/tex/generic/pdftexcmds/pdftexcmds.sty) (/usr/local/texlive/2023/texmf-dist/tex/generic/kvdefinekeys/kvdefinekeys.sty) (/usr/local/texlive/2023/texmf-dist/tex/generic/pdfescape/pdfescape.sty) (/usr/local/texlive/2023/texmf-dist/tex/latex/hycolor/hycolor.sty) (/usr/local/texlive/2023/texmf-dist/tex/latex/letltxmacro/letltxmacro.sty) (/usr/local/texlive/2023/texmf-dist/tex/latex/auxhook/auxhook.sty) (/usr/local/texlive/2023/texmf-dist/tex/latex/hyperref/nameref.sty (/usr/local/texlive/2023/texmf-dist/tex/latex/refcount/refcount.sty) (/usr/local/texlive/2023/texmf-dist/tex/generic/gettitlestring/gettitlestring.s ty)) (/usr/local/texlive/2023/texmf-dist/tex/latex/hyperref/pd1enc.def) (/usr/local/texlive/2023/texmf-dist/tex/generic/intcalc/intcalc.sty) (/usr/local/texlive/2023/texmf-dist/tex/generic/etexcmds/etexcmds.sty) (/usr/local/texlive/2023/texmf-dist/tex/latex/hyperref/puenc.def) (/usr/local/texlive/2023/texmf-dist/tex/latex/url/url.sty) (/usr/local/texlive/2023/texmf-dist/tex/generic/bitset/bitset.sty (/usr/local/texlive/2023/texmf-dist/tex/generic/bigintcalc/bigintcalc.sty)) (/usr/local/texlive/2023/texmf-dist/tex/latex/base/atbegshi-ltx.sty)) (/usr/local/texlive/2023/texmf-dist/tex/latex/hyperref/hxetex.def (/usr/local/texlive/2023/texmf-dist/tex/generic/stringenc/stringenc.sty) (/usr/local/texlive/2023/texmf-dist/tex/latex/rerunfilecheck/rerunfilecheck.sty (/usr/local/texlive/2023/texmf-dist/tex/latex/base/atveryend-ltx.sty) (/usr/local/texlive/2023/texmf-dist/tex/generic/uniquecounter/uniquecounter.sty ))) (/usr/local/texlive/2023/texmf-dist/tex/latex/titling/titling.sty) (/usr/local/texlive/2023/texmf-dist/tex/latex/tools/longtable.sty) (/usr/local/texlive/2023/texmf-dist/tex/latex/booktabs/booktabs.sty) (/usr/local/texlive/2023/texmf-dist/tex/latex/enumitem/enumitem.sty) (/usr/local/texlive/2023/texmf-dist/tex/generic/ulem/ulem.sty) (/usr/local/texlive/2023/texmf-dist/tex/latex/jknapltx/mathrsfs.sty) No file notebook.aux. (/usr/local/texlive/2023/texmf-dist/tex/latex/base/ts1cmr.fd) (/usr/local/texlive/2023/texmf-dist/tex/latex/caption/ltcaption.sty) geometry driver: auto-detecting geometry detected driver: xetex geometry verbose mode - [ preamble ] result:

(/usr/local/texlive/2023/texmf-dist/tex/latex/ucs/ucsencs.def)

Package hyperref Warning: Rerun to get /PageLabels entry.

(/usr/local/texlive/2023/texmf-dist/tex/latex/amsfonts/umsa.fd) (/usr/local/texlive/2023/texmf-dist/tex/latex/amsfonts/umsb.fd) (/usr/local/texlive/2023/texmf-dist/tex/latex/jknapltx/ursfs.fd)

LaTeX Warning: No \author given.

! Undefined control sequence. \HyPsd@expand@utfvii ... {~{####1}}}\UTFviii@loop \count@ "E0 \@tempcnta "F0... l.394 \end{document}

? ! Emergency stop. \HyPsd@expand@utfvii ... {~{####1}}}\UTFviii@loop \count@ "E0 \@tempcnta "F0... l.394 \end{document}

No pages of output. Transcript written on notebook.log.

wgmitchener commented 5 months ago

nbconvert includes boilerplate code that uses package ucs. There is some problem with this package and TeX engines like XeTeX that handle Unicode.

A workaround is to convert the .ipynb file to LaTeX. Edit the .tex file and comment out or delete the line with \usepackage[...]{ucs}. Then compile the .tex file directly.

I'm puzzled because in the file share/jupyter/nbconvert/templates/latex/base.tex.j2 in this repository, the line for \usepackage[...]{ucs} is inside of \ifPDFTex ... which should fix this problem. It looks like commit 5fe7c81 specifically fixed this problem, and it's dated 2021. However, in version 7.16.0 of nbconvert, which is what I got with pip install --user nbconvert, that file is rather different and the line for \usepackage[...]{ucs} is executed unconditionally.

I ran pip install --user -U nbconvert and it updated to version 7.16.4 of nbconvert, and that version includes the fix, and I can convert my notebook directly to PDF.