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 | 'stdout' : ( |
|
54 | 'stdout' : ( | |
55 | {'NbConvertApp' : {'writer_class' : "StdoutWriter"}}, |
|
55 | {'NbConvertApp' : {'writer_class' : "StdoutWriter"}}, | |
56 | "Write notebook output to stdout instead of files." |
|
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 | You can also pipe the output to stdout, rather than a file |
|
104 | You can also pipe the output to stdout, rather than a file | |
100 |
|
105 | |||
101 | > ipython nbconvert mynotebook.ipynb --stdout |
|
106 | > ipython nbconvert mynotebook.ipynb --stdout | |
|
107 | ||||
|
108 | or to a PDF | |||
|
109 | ||||
|
110 | > ipython nbconvert mynotebook.ipynb --pdf | |||
102 |
|
111 | |||
103 | Multiple notebooks can be given at the command line in a couple of |
|
112 | Multiple notebooks can be given at the command line in a couple of | |
104 | different ways: |
|
113 | different ways: | |
@@ -120,6 +129,7 b' class NbConvertApp(BaseIPythonApplication):' | |||||
120 | help="""Writer class used to write the |
|
129 | help="""Writer class used to write the | |
121 | results of the conversion""") |
|
130 | results of the conversion""") | |
122 | writer_aliases = {'FilesWriter': 'IPython.nbconvert.writers.files.FilesWriter', |
|
131 | writer_aliases = {'FilesWriter': 'IPython.nbconvert.writers.files.FilesWriter', | |
|
132 | 'PDFWriter': 'IPython.nbconvert.writers.pdf.PDFWriter', | |||
123 | 'DebugWriter': 'IPython.nbconvert.writers.debug.DebugWriter', |
|
133 | 'DebugWriter': 'IPython.nbconvert.writers.debug.DebugWriter', | |
124 | 'StdoutWriter': 'IPython.nbconvert.writers.stdout.StdoutWriter'} |
|
134 | 'StdoutWriter': 'IPython.nbconvert.writers.stdout.StdoutWriter'} | |
125 | writer_factory = Type() |
|
135 | writer_factory = Type() |
@@ -1,5 +1,7 b'' | |||||
1 | ((*- extends 'display_priority.tplx' -*)) |
|
1 | ((*- extends 'display_priority.tplx' -*)) | |
2 |
|
2 | |||
|
3 | \nonstopmode | |||
|
4 | ||||
3 | ((* block in_prompt *))((* endblock in_prompt *)) |
|
5 | ((* block in_prompt *))((* endblock in_prompt *)) | |
4 |
|
6 | |||
5 | ((* block output_prompt *))((* endblock output_prompt *)) |
|
7 | ((* block output_prompt *))((* endblock output_prompt *)) |
@@ -9,6 +9,8 b' Note: For best display, use latex syntax highlighting. =))' | |||||
9 |
|
9 | |||
10 | ((*- extends 'display_priority.tplx' -*)) |
|
10 | ((*- extends 'display_priority.tplx' -*)) | |
11 |
|
11 | |||
|
12 | \nonstopmode | |||
|
13 | ||||
12 | %============================================================================== |
|
14 | %============================================================================== | |
13 | % Declarations |
|
15 | % Declarations | |
14 | %============================================================================== |
|
16 | %============================================================================== |
General Comments 0
You need to be logged in to leave comments.
Login now