##// END OF EJS Templates
Merge pull request #3554 from damianavila/fix_os_import...
Jonathan Frederic -
r11205:6dc32e04 merge
parent child Browse files
Show More
@@ -1,105 +1,108 b''
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
20 import os
21
19 # IPython imports
22 # IPython imports
20 from IPython.utils.traitlets import Unicode
23 from IPython.utils.traitlets import Unicode
21 from IPython.config import Config
24 from IPython.config import Config
22
25
23 from IPython.nbconvert import filters, transformers
26 from IPython.nbconvert import filters, transformers
24 from .exporter import Exporter
27 from .exporter import Exporter
25
28
26 #-----------------------------------------------------------------------------
29 #-----------------------------------------------------------------------------
27 # Classes and functions
30 # Classes and functions
28 #-----------------------------------------------------------------------------
31 #-----------------------------------------------------------------------------
29
32
30 class LatexExporter(Exporter):
33 class LatexExporter(Exporter):
31 """
34 """
32 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
33 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
34 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.
35 If you don't need custom tranformers/filters, just change the
38 If you don't need custom tranformers/filters, just change the
36 'template_file' config option. Place your template in the special "/latex"
39 'template_file' config option. Place your template in the special "/latex"
37 subfolder of the "../templates" folder.
40 subfolder of the "../templates" folder.
38 """
41 """
39
42
40 file_extension = Unicode(
43 file_extension = Unicode(
41 'tex', config=True,
44 'tex', config=True,
42 help="Extension of the file that should be written to disk")
45 help="Extension of the file that should be written to disk")
43
46
44 template_file = Unicode(
47 template_file = Unicode(
45 'base', config=True,
48 'base', config=True,
46 help="Name of the template file to use")
49 help="Name of the template file to use")
47
50
48 #Latex constants
51 #Latex constants
49 template_path = Unicode(
52 template_path = Unicode(
50 os.path.join("..", "templates", "latex"), config=True,
53 os.path.join("..", "templates", "latex"), config=True,
51 help="Path where the template files are located.")
54 help="Path where the template files are located.")
52
55
53 template_skeleton_path = Unicode(
56 template_skeleton_path = Unicode(
54 os.path.join("..", "templates", "latex", "skeleton"), config=True,
57 os.path.join("..", "templates", "latex", "skeleton"), config=True,
55 help="Path where the template skeleton files are located.")
58 help="Path where the template skeleton files are located.")
56
59
57 #Special Jinja2 syntax that will not conflict when exporting latex.
60 #Special Jinja2 syntax that will not conflict when exporting latex.
58 jinja_comment_block_start = Unicode("((=", config=True)
61 jinja_comment_block_start = Unicode("((=", config=True)
59 jinja_comment_block_end = Unicode("=))", config=True)
62 jinja_comment_block_end = Unicode("=))", config=True)
60 jinja_variable_block_start = Unicode("(((", config=True)
63 jinja_variable_block_start = Unicode("(((", config=True)
61 jinja_variable_block_end = Unicode(")))", config=True)
64 jinja_variable_block_end = Unicode(")))", config=True)
62 jinja_logic_block_start = Unicode("((*", config=True)
65 jinja_logic_block_start = Unicode("((*", config=True)
63 jinja_logic_block_end = Unicode("*))", config=True)
66 jinja_logic_block_end = Unicode("*))", config=True)
64
67
65 #Extension that the template files use.
68 #Extension that the template files use.
66 template_extension = Unicode(".tplx", config=True)
69 template_extension = Unicode(".tplx", config=True)
67
70
68 def _register_filters(self):
71 def _register_filters(self):
69 """
72 """
70 Register all of the filters required for the exporter.
73 Register all of the filters required for the exporter.
71 """
74 """
72
75
73 #Register the filters of the base class.
76 #Register the filters of the base class.
74 super(LatexExporter, self)._register_filters()
77 super(LatexExporter, self)._register_filters()
75
78
76 #Add latex filters to the Jinja2 environment
79 #Add latex filters to the Jinja2 environment
77 self.register_filter('escape_tex', filters.escape_latex)
80 self.register_filter('escape_tex', filters.escape_latex)
78 self.register_filter('highlight', filters.highlight2latex)
81 self.register_filter('highlight', filters.highlight2latex)
79
82
80
83
81 def _register_transformers(self):
84 def _register_transformers(self):
82 """
85 """
83 Register all of the transformers needed for this exporter.
86 Register all of the transformers needed for this exporter.
84 """
87 """
85
88
86 #Register the transformers of the base class.
89 #Register the transformers of the base class.
87 super(LatexExporter, self)._register_transformers()
90 super(LatexExporter, self)._register_transformers()
88
91
89 #Register latex transformer
92 #Register latex transformer
90 self.register_transformer(transformers.LatexTransformer)
93 self.register_transformer(transformers.LatexTransformer)
91
94
92 @property
95 @property
93 def default_config(self):
96 def default_config(self):
94 c = Config({
97 c = Config({
95 'GlobalConfigurable': {
98 'GlobalConfigurable': {
96 'display_data_priority' : ['latex', 'svg', 'png', 'jpg', 'jpeg' , 'text']
99 'display_data_priority' : ['latex', 'svg', 'png', 'jpg', 'jpeg' , 'text']
97 },
100 },
98 'ExtractFigureTransformer': {
101 'ExtractFigureTransformer': {
99 'enabled':True,
102 'enabled':True,
100 'extra_ext_map':{'svg':'pdf'},
103 'extra_ext_map':{'svg':'pdf'},
101 }
104 }
102 })
105 })
103 c.merge(super(LatexExporter,self).default_config)
106 c.merge(super(LatexExporter,self).default_config)
104 return c
107 return c
105
108
General Comments 0
You need to be logged in to leave comments. Login now