diff --git a/IPython/nbconvert/nbconvertapp.py b/IPython/nbconvert/nbconvertapp.py index 6aeadd5..3f85d8e 100755 --- a/IPython/nbconvert/nbconvertapp.py +++ b/IPython/nbconvert/nbconvertapp.py @@ -54,6 +54,11 @@ nbconvert_flags.update({ 'stdout' : ( {'NbConvertApp' : {'writer_class' : "StdoutWriter"}}, "Write notebook output to stdout instead of files." + ), + + 'pdf' : ( + {'NbConvertApp' : {'writer_class' : "PDFWriter"}}, + "Compile notebook output to a PDF." ) }) @@ -99,6 +104,10 @@ class NbConvertApp(BaseIPythonApplication): You can also pipe the output to stdout, rather than a file > ipython nbconvert mynotebook.ipynb --stdout + + or to a PDF + + > ipython nbconvert mynotebook.ipynb --pdf Multiple notebooks can be given at the command line in a couple of different ways: @@ -120,6 +129,7 @@ class NbConvertApp(BaseIPythonApplication): help="""Writer class used to write the results of the conversion""") writer_aliases = {'FilesWriter': 'IPython.nbconvert.writers.files.FilesWriter', + 'PDFWriter': 'IPython.nbconvert.writers.pdf.PDFWriter', 'DebugWriter': 'IPython.nbconvert.writers.debug.DebugWriter', 'StdoutWriter': 'IPython.nbconvert.writers.stdout.StdoutWriter'} writer_factory = Type() diff --git a/IPython/nbconvert/templates/latex/latex_basic.tplx b/IPython/nbconvert/templates/latex/latex_basic.tplx index f04bc20..81412db 100644 --- a/IPython/nbconvert/templates/latex/latex_basic.tplx +++ b/IPython/nbconvert/templates/latex/latex_basic.tplx @@ -1,5 +1,7 @@ ((*- extends 'display_priority.tplx' -*)) +\nonstopmode + ((* block in_prompt *))((* endblock in_prompt *)) ((* block output_prompt *))((* endblock output_prompt *)) diff --git a/IPython/nbconvert/templates/latex/sphinx.tplx b/IPython/nbconvert/templates/latex/sphinx.tplx index 1fd248b..6df9058 100644 --- a/IPython/nbconvert/templates/latex/sphinx.tplx +++ b/IPython/nbconvert/templates/latex/sphinx.tplx @@ -9,6 +9,8 @@ Note: For best display, use latex syntax highlighting. =)) ((*- extends 'display_priority.tplx' -*)) +\nonstopmode + %============================================================================== % Declarations %============================================================================== diff --git a/IPython/nbconvert/writers/__init__.py b/IPython/nbconvert/writers/__init__.py index f0bc939..155cf89 100644 --- a/IPython/nbconvert/writers/__init__.py +++ b/IPython/nbconvert/writers/__init__.py @@ -1,2 +1,3 @@ from .files import FilesWriter from .stdout import StdoutWriter +from .pdf import PDFWriter diff --git a/IPython/nbconvert/writers/files.py b/IPython/nbconvert/writers/files.py index f6e1da5..fda1e99 100644 --- a/IPython/nbconvert/writers/files.py +++ b/IPython/nbconvert/writers/files.py @@ -100,3 +100,4 @@ class FilesWriter(WriterBase): # Write conversion results. with io.open(dest, 'w') as f: f.write(output) + return dest \ No newline at end of file diff --git a/IPython/nbconvert/writers/pdf.py b/IPython/nbconvert/writers/pdf.py new file mode 100644 index 0000000..d6cb5fa --- /dev/null +++ b/IPython/nbconvert/writers/pdf.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python +""" +Contains writer for writing nbconvert output to PDF. +""" +#----------------------------------------------------------------------------- +#Copyright (c) 2013, the IPython Development Team. +# +#Distributed under the terms of the Modified BSD License. +# +#The full license is in the file COPYING.txt, distributed with this software. +#----------------------------------------------------------------------------- + +#----------------------------------------------------------------------------- +# Imports +#----------------------------------------------------------------------------- + +import subprocess +import os + +from IPython.utils.traitlets import Integer + +from .files import FilesWriter + +#----------------------------------------------------------------------------- +# Classes +#----------------------------------------------------------------------------- +class PDFWriter(FilesWriter): + """Writer designed to write to PDF files""" + + iteration_count = Integer(3, config=True, help=""" + How many times pdflatex will be called. + """) + + def write(self, output, resources, notebook_name=None, **kw): + """ + Consume and write Jinja output a PDF. + See files.py for more... + """ + dest = super(PDFWriter, self).write(output, resources, notebook_name=notebook_name, **kw) + command = 'pdflatex ' + dest + for index in range(self.iteration_count): + subprocess.Popen(command, shell=True, stdout=open(os.devnull, 'wb'))