Show More
@@ -88,7 +88,7 b' class NbConvertApp(BaseIPythonApplication):' | |||||
88 |
|
88 | |||
89 | def _classes_default(self): |
|
89 | def _classes_default(self): | |
90 | classes = [NbConvertBase, ProfileDir] |
|
90 | classes = [NbConvertBase, ProfileDir] | |
91 | for pkg in (exporters, preprocessors, writers): |
|
91 | for pkg in (exporters, preprocessors, writers, postprocessors): | |
92 | for name in dir(pkg): |
|
92 | for name in dir(pkg): | |
93 | cls = getattr(pkg, name) |
|
93 | cls = getattr(pkg, name) | |
94 | if isinstance(cls, type) and issubclass(cls, Configurable): |
|
94 | if isinstance(cls, type) and issubclass(cls, Configurable): |
@@ -15,6 +15,7 b' Contains writer for writing nbconvert output to PDF.' | |||||
15 |
|
15 | |||
16 | import subprocess |
|
16 | import subprocess | |
17 | import os |
|
17 | import os | |
|
18 | import sys | |||
18 |
|
19 | |||
19 | from IPython.utils.traitlets import Integer, List, Bool |
|
20 | from IPython.utils.traitlets import Integer, List, Bool | |
20 |
|
21 | |||
@@ -44,6 +45,9 b' class PDFPostProcessor(PostProcessorBase):' | |||||
44 | config=True, help=""" |
|
45 | config=True, help=""" | |
45 | Filename extensions of temp files to remove after running. |
|
46 | Filename extensions of temp files to remove after running. | |
46 | """) |
|
47 | """) | |
|
48 | pdf_open = Bool(False, config=True, help=""" | |||
|
49 | Whether or not to open the pdf after the compile call. | |||
|
50 | """) | |||
47 |
|
51 | |||
48 | def run_command(self, command_list, filename, count, log_function): |
|
52 | def run_command(self, command_list, filename, count, log_function): | |
49 | """Run command_list count times. |
|
53 | """Run command_list count times. | |
@@ -113,6 +117,16 b' class PDFPostProcessor(PostProcessorBase):' | |||||
113 | except OSError: |
|
117 | except OSError: | |
114 | pass |
|
118 | pass | |
115 |
|
119 | |||
|
120 | def open_pdf(self, filename): | |||
|
121 | """Open the pdf in the default viewer.""" | |||
|
122 | if sys.platform.startswith('darwin'): | |||
|
123 | subprocess.call(('open', filename)) | |||
|
124 | elif os.name == 'nt': | |||
|
125 | os.startfile(filename) | |||
|
126 | elif os.name == 'posix': | |||
|
127 | subprocess.call(('xdg-open', filename)) | |||
|
128 | return | |||
|
129 | ||||
116 | def postprocess(self, filename): |
|
130 | def postprocess(self, filename): | |
117 | """Build a PDF by running pdflatex and bibtex""" |
|
131 | """Build a PDF by running pdflatex and bibtex""" | |
118 | self.log.info("Building PDF") |
|
132 | self.log.info("Building PDF") | |
@@ -128,5 +142,8 b' class PDFPostProcessor(PostProcessorBase):' | |||||
128 | filename = os.path.splitext(filename)[0] |
|
142 | filename = os.path.splitext(filename)[0] | |
129 | if os.path.isfile(filename+'.pdf'): |
|
143 | if os.path.isfile(filename+'.pdf'): | |
130 | self.log.info('PDF successfully created') |
|
144 | self.log.info('PDF successfully created') | |
|
145 | if self.pdf_open: | |||
|
146 | self.log.info('Viewer called') | |||
|
147 | self.open_pdf(filename+'.pdf') | |||
131 | return |
|
148 | return | |
132 |
|
149 |
General Comments 0
You need to be logged in to leave comments.
Login now