我正在尝试使用nbconvert应用程序将笔记本导出到乳胶文件。创建了tex,但存在以下问题。
代码:
sourcefile = "test.ipynb" # file to be converted
with open(sourcefile) as nb_file:
nb_contents = nb_file.read()
import nbformat
# Convert using the ordinary exporter
notebook = nbformat.reads(nb_contents, as_version=4)
# create a configuration object to extract figures as files
from traitlets.config import Config
c = Config()
c.LatexExporter.preprocessors = ['nbconvert.preprocessors.ExtractOutputPreprocessor']
# ref: https://nbconvert.readthedocs.io/en/latest/nbconvert_library.html#Quick-overview
# 1. Import the exporter
from nbconvert import LatexExporter
# 2. Instantiate the exporter.
latex_exporter = LatexExporter(config=c)
latex_exporter.template_file = 'ipy2tex_converter.tplx'
# 3. Process the notebook we loaded earlier
(body, resources) = latex_exporter.from_notebook_node(notebook)
# 4. write the tex file
import ntpath
foldername = ntpath.basename(sourcefile).split('.ipynb')[0]
basename = foldername +'.tex'
with open(basename, 'w') as output_file:
output_file.write(body)
代码link