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