Automating ipython output to pdf

前端 未结 2 793
没有蜡笔的小新
没有蜡笔的小新 2021-02-15 04:30

I have a little program that basically does all kinds of statistical calculation and prints out results and charts.

At present, a convenient way to get a nice pdf output

2条回答
  •  攒了一身酷
    2021-02-15 05:20

    If you have an IPython notebook, you can make a small python or bash script that first executes and then produces the PDF. For me, this bash script works:

    jupyter nbconvert --ExecutePreprocessor.timeout=500 --to notebook --execute my_file.ipynb
    jupyter nbconvert --to pdf my_file.nbconvert.ipynb
    rm my_file.nbconvert.ipynb
    

    If you want to customise the output using a template, I have found that converting the file first to markdown and then using pandoc to create a PDF avoids some issues:

    jupyter nbconvert --ExecutePreprocessor.timeout=500 --to notebook --execute my_file.ipynb
    jupyter nbconvert  --to markdown my_file.nbconvert.ipynb  --template="mytemplate.tpl"
    pandoc --toc --template=mytemplate.tex markdown my_file.nbconvert.ipynb --latex-engine=pdflatex -o final file.pdf
    

提交回复
热议问题