2 回答
TA贡献1796条经验 获得超7个赞
您也可以使用 nbconvert 在 colab 本身中创建 pdf。
!apt update
!apt install texlive-xetex texlive-fonts-recommended texlive-generic-recommended
import re, pathlib, shutil
# Get a list of all your Notebooks
notebooks = [x for x in pathlib.Path("/content/drive/My Drive/Colab Notebooks").iterdir() if
re.search(r"\.ipynb", x.name, flags = re.I)]
for i, n in enumerate(notebooks):
print(f"\nProcessing [{i+1:{len(str(len(notebooks)))}d}/{len(notebooks)}] {n.name}\n")
# Optionally copy your notebooks from gdrive to your vm
shutil.copy(n, n.name)
n = pathlib.Path(n.name)
!jupyter nbconvert "{n.as_posix()}" --to pdf --output "{n.stem.replace(" ", "_")}"
除了使用魔法来运行nbconvert之外,您还可以使用subprocess
s = subprocess.Popen(shlex.split(
f'jupyter nbconvert "{n.as_posix()}" --to pdf --output "{n.stem.replace(" ", "_")}"'
), shell = False, stdout = subprocess.PIPE, stderr = subprocess.PIPE)
s.wait()
s.stdout.read()
还有更多关于xetex的软件包,以防您使用非常复杂的模板。
sudo apt install pandoc nbconvert texlive texlive-latex-extra texlive-generic-extra
添加回答
举报