Show More
@@ -1,94 +1,94 | |||
|
1 | 1 | """ |
|
2 | 2 | Exporter that allows Latex Jinja templates to work. Contains logic to |
|
3 | 3 | appropriately prepare IPYNB files for export to LaTeX. Including but |
|
4 | 4 | not limited to escaping LaTeX, fixing math region tags, using special |
|
5 | 5 | tags to circumvent Jinja/Latex syntax conflicts. |
|
6 | 6 | """ |
|
7 | 7 | #----------------------------------------------------------------------------- |
|
8 | 8 | # Copyright (c) 2013, the IPython Development Team. |
|
9 | 9 | # |
|
10 | 10 | # Distributed under the terms of the Modified BSD License. |
|
11 | 11 | # |
|
12 | 12 | # The full license is in the file COPYING.txt, distributed with this software. |
|
13 | 13 | #----------------------------------------------------------------------------- |
|
14 | 14 | |
|
15 | 15 | #----------------------------------------------------------------------------- |
|
16 | 16 | # Imports |
|
17 | 17 | #----------------------------------------------------------------------------- |
|
18 | 18 | |
|
19 | 19 | # Stdlib imports |
|
20 | 20 | import os |
|
21 | 21 | |
|
22 | 22 | # IPython imports |
|
23 | 23 | from IPython.utils.traitlets import Unicode, List |
|
24 | 24 | from IPython.config import Config |
|
25 | 25 | |
|
26 | 26 | from IPython.nbconvert import filters, preprocessors |
|
27 | 27 | from .templateexporter import TemplateExporter |
|
28 | 28 | |
|
29 | 29 | #----------------------------------------------------------------------------- |
|
30 | 30 | # Classes and functions |
|
31 | 31 | #----------------------------------------------------------------------------- |
|
32 | 32 | |
|
33 | 33 | class LatexExporter(TemplateExporter): |
|
34 | 34 | """ |
|
35 | 35 | Exports to a Latex template. Inherit from this class if your template is |
|
36 | 36 | LaTeX based and you need custom tranformers/filters. Inherit from it if |
|
37 | 37 | you are writing your own HTML template and need custom tranformers/filters. |
|
38 | 38 | If you don't need custom tranformers/filters, just change the |
|
39 | 39 | 'template_file' config option. Place your template in the special "/latex" |
|
40 | 40 | subfolder of the "../templates" folder. |
|
41 | 41 | """ |
|
42 | 42 | |
|
43 | 43 | file_extension = Unicode( |
|
44 | 44 | 'tex', config=True, |
|
45 | 45 | help="Extension of the file that should be written to disk") |
|
46 | 46 | |
|
47 | 47 | default_template = Unicode('article', config=True, help="""Template of the |
|
48 |
data format to use. I.E. 'article' or ' |
|
|
48 | data format to use. I.E. 'article' or 'report'""") | |
|
49 | 49 | |
|
50 | 50 | #Latex constants |
|
51 | 51 | default_template_path = Unicode( |
|
52 | 52 | os.path.join("..", "templates", "latex"), config=True, |
|
53 | 53 | help="Path where the template files are located.") |
|
54 | 54 | |
|
55 | 55 | template_skeleton_path = Unicode( |
|
56 | 56 | os.path.join("..", "templates", "latex", "skeleton"), config=True, |
|
57 | 57 | help="Path where the template skeleton files are located.") |
|
58 | 58 | |
|
59 | 59 | #Special Jinja2 syntax that will not conflict when exporting latex. |
|
60 | 60 | jinja_comment_block_start = Unicode("((=", config=True) |
|
61 | 61 | jinja_comment_block_end = Unicode("=))", config=True) |
|
62 | 62 | jinja_variable_block_start = Unicode("(((", config=True) |
|
63 | 63 | jinja_variable_block_end = Unicode(")))", config=True) |
|
64 | 64 | jinja_logic_block_start = Unicode("((*", config=True) |
|
65 | 65 | jinja_logic_block_end = Unicode("*))", config=True) |
|
66 | 66 | |
|
67 | 67 | #Extension that the template files use. |
|
68 | 68 | template_extension = Unicode(".tplx", config=True) |
|
69 | 69 | |
|
70 | 70 | |
|
71 | 71 | @property |
|
72 | 72 | def default_config(self): |
|
73 | 73 | c = Config({ |
|
74 | 74 | 'NbConvertBase': { |
|
75 | 75 | 'display_data_priority' : ['latex', 'pdf', 'png', 'jpg', 'svg', 'jpeg', 'text'] |
|
76 | 76 | }, |
|
77 | 77 | 'ExtractOutputPreprocessor': { |
|
78 | 78 | 'enabled':True |
|
79 | 79 | }, |
|
80 | 80 | 'SVG2PDFPreprocessor': { |
|
81 | 81 | 'enabled':True |
|
82 | 82 | }, |
|
83 | 83 | 'LatexPreprocessor': { |
|
84 | 84 | 'enabled':True |
|
85 | 85 | }, |
|
86 | 86 | 'SphinxPreprocessor': { |
|
87 | 87 | 'enabled':True |
|
88 | 88 | }, |
|
89 | 89 | 'HighlightMagicsPreprocessor': { |
|
90 | 90 | 'enabled':True |
|
91 | 91 | } |
|
92 | 92 | }) |
|
93 | 93 | c.merge(super(LatexExporter,self).default_config) |
|
94 | 94 | return c |
@@ -1,68 +1,68 | |||
|
1 | 1 | """ |
|
2 | 2 | Module with tests for latex.py |
|
3 | 3 | """ |
|
4 | 4 | |
|
5 | 5 | #----------------------------------------------------------------------------- |
|
6 | 6 | # Copyright (c) 2013, the IPython Development Team. |
|
7 | 7 | # |
|
8 | 8 | # Distributed under the terms of the Modified BSD License. |
|
9 | 9 | # |
|
10 | 10 | # The full license is in the file COPYING.txt, distributed with this software. |
|
11 | 11 | #----------------------------------------------------------------------------- |
|
12 | 12 | |
|
13 | 13 | #----------------------------------------------------------------------------- |
|
14 | 14 | # Imports |
|
15 | 15 | #----------------------------------------------------------------------------- |
|
16 | 16 | |
|
17 | 17 | from .base import ExportersTestsBase |
|
18 | 18 | from ..latex import LatexExporter |
|
19 | 19 | from IPython.testing.decorators import onlyif_cmds_exist |
|
20 | 20 | |
|
21 | 21 | #----------------------------------------------------------------------------- |
|
22 | 22 | # Class |
|
23 | 23 | #----------------------------------------------------------------------------- |
|
24 | 24 | |
|
25 | 25 | class TestLatexExporter(ExportersTestsBase): |
|
26 | 26 | """Contains test functions for latex.py""" |
|
27 | 27 | |
|
28 | 28 | def test_constructor(self): |
|
29 | 29 | """ |
|
30 | 30 | Can a LatexExporter be constructed? |
|
31 | 31 | """ |
|
32 | 32 | LatexExporter() |
|
33 | 33 | |
|
34 | 34 | |
|
35 | 35 | @onlyif_cmds_exist('pandoc') |
|
36 | 36 | def test_export(self): |
|
37 | 37 | """ |
|
38 | 38 | Can a LatexExporter export something? |
|
39 | 39 | """ |
|
40 | 40 | (output, resources) = LatexExporter().from_filename(self._get_notebook()) |
|
41 | 41 | assert len(output) > 0 |
|
42 | 42 | |
|
43 | 43 | |
|
44 | 44 | @onlyif_cmds_exist('pandoc') |
|
45 | 45 | def test_export_book(self): |
|
46 | 46 | """ |
|
47 |
Can a LatexExporter export using ' |
|
|
47 | Can a LatexExporter export using 'report' template? | |
|
48 | 48 | """ |
|
49 |
(output, resources) = LatexExporter(template_file=' |
|
|
49 | (output, resources) = LatexExporter(template_file='report').from_filename(self._get_notebook()) | |
|
50 | 50 | assert len(output) > 0 |
|
51 | 51 | |
|
52 | 52 | |
|
53 | 53 | @onlyif_cmds_exist('pandoc') |
|
54 | 54 | def test_export_basic(self): |
|
55 | 55 | """ |
|
56 | 56 | Can a LatexExporter export using 'article' template? |
|
57 | 57 | """ |
|
58 | 58 | (output, resources) = LatexExporter(template_file='article').from_filename(self._get_notebook()) |
|
59 | 59 | assert len(output) > 0 |
|
60 | 60 | |
|
61 | 61 | |
|
62 | 62 | @onlyif_cmds_exist('pandoc') |
|
63 | 63 | def test_export_article(self): |
|
64 | 64 | """ |
|
65 | 65 | Can a LatexExporter export using 'article' template? |
|
66 | 66 | """ |
|
67 | 67 | (output, resources) = LatexExporter(template_file='article').from_filename(self._get_notebook()) |
|
68 | 68 | assert len(output) > 0 No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now