##// END OF EJS Templates
Fixed errors after testing...
Jonathan Frederic -
Show More
@@ -0,0 +1,42 b''
1 #!/usr/bin/env python
2 """
3 Contains writer for writing nbconvert output to PDF.
4 """
5 #-----------------------------------------------------------------------------
6 #Copyright (c) 2013, the IPython Development Team.
7 #
8 #Distributed under the terms of the Modified BSD License.
9 #
10 #The full license is in the file COPYING.txt, distributed with this software.
11 #-----------------------------------------------------------------------------
12
13 #-----------------------------------------------------------------------------
14 # Imports
15 #-----------------------------------------------------------------------------
16
17 import subprocess
18 import os
19
20 from IPython.utils.traitlets import Integer
21
22 from .files import FilesWriter
23
24 #-----------------------------------------------------------------------------
25 # Classes
26 #-----------------------------------------------------------------------------
27 class PDFWriter(FilesWriter):
28 """Writer designed to write to PDF files"""
29
30 iteration_count = Integer(3, config=True, help="""
31 How many times pdflatex will be called.
32 """)
33
34 def write(self, output, resources, notebook_name=None, **kw):
35 """
36 Consume and write Jinja output a PDF.
37 See files.py for more...
38 """
39 dest = super(PDFWriter, self).write(output, resources, notebook_name=notebook_name, **kw)
40 command = 'pdflatex ' + dest
41 for index in range(self.iteration_count):
42 subprocess.Popen(command, shell=True, stdout=open(os.devnull, 'wb'))
@@ -54,6 +54,11 b' nbconvert_flags.update({'
54 54 'stdout' : (
55 55 {'NbConvertApp' : {'writer_class' : "StdoutWriter"}},
56 56 "Write notebook output to stdout instead of files."
57 ),
58
59 'pdf' : (
60 {'NbConvertApp' : {'writer_class' : "PDFWriter"}},
61 "Compile notebook output to a PDF."
57 62 )
58 63 })
59 64
@@ -99,6 +104,10 b' class NbConvertApp(BaseIPythonApplication):'
99 104 You can also pipe the output to stdout, rather than a file
100 105
101 106 > ipython nbconvert mynotebook.ipynb --stdout
107
108 or to a PDF
109
110 > ipython nbconvert mynotebook.ipynb --pdf
102 111
103 112 Multiple notebooks can be given at the command line in a couple of
104 113 different ways:
@@ -120,6 +129,7 b' class NbConvertApp(BaseIPythonApplication):'
120 129 help="""Writer class used to write the
121 130 results of the conversion""")
122 131 writer_aliases = {'FilesWriter': 'IPython.nbconvert.writers.files.FilesWriter',
132 'PDFWriter': 'IPython.nbconvert.writers.pdf.PDFWriter',
123 133 'DebugWriter': 'IPython.nbconvert.writers.debug.DebugWriter',
124 134 'StdoutWriter': 'IPython.nbconvert.writers.stdout.StdoutWriter'}
125 135 writer_factory = Type()
@@ -1,5 +1,7 b''
1 1 ((*- extends 'display_priority.tplx' -*))
2 2
3 \nonstopmode
4
3 5 ((* block in_prompt *))((* endblock in_prompt *))
4 6
5 7 ((* block output_prompt *))((* endblock output_prompt *))
@@ -9,6 +9,8 b' Note: For best display, use latex syntax highlighting. =))'
9 9
10 10 ((*- extends 'display_priority.tplx' -*))
11 11
12 \nonstopmode
13
12 14 %==============================================================================
13 15 % Declarations
14 16 %==============================================================================
@@ -1,2 +1,3 b''
1 1 from .files import FilesWriter
2 2 from .stdout import StdoutWriter
3 from .pdf import PDFWriter
@@ -100,3 +100,4 b' class FilesWriter(WriterBase):'
100 100 # Write conversion results.
101 101 with io.open(dest, 'w') as f:
102 102 f.write(output)
103 return dest No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now