##// END OF EJS Templates
Moved latex code into latex exporter
Jonathan Frederic -
Show More
@@ -38,24 +38,14 b' from markdown import markdown'
38 # local import (pre-transformers)
38 # local import (pre-transformers)
39 from exceptions import ConversionException
39 from exceptions import ConversionException
40 from . import transformers as trans #TODO
40 from . import transformers as trans #TODO
41 from .utils import highlight2latex #TODO
42 from .utils import get_lines #TODO
41 from .utils import get_lines #TODO
43 from .utils import remove_ansi #TODO
42 from .utils import remove_ansi #TODO
44 from .utils import highlight, ansi2html #TODO
43 from .utils import highlight, ansi2html #TODO
45
44
46 from .transformers.latex import LatexTransformer, rm_math_space
47
48 import .utils.strings as strings
45 import .utils.strings as strings
49 import .utils.markdown as markdown_utils
46 import .utils.markdown as markdown_utils
50 import .utils.datatypefilter.DataTypeFilter as DataTypeFilter
47 import .utils.datatypefilter.DataTypeFilter as DataTypeFilter
51
48
52 #Try to import the Sphinx exporter. If the user doesn't have Sphinx isntalled
53 #on his/her machine, fail silently.
54 try:
55 from .sphinx_transformer import (SphinxTransformer) #TODO
56 except ImportError:
57 SphinxTransformer = None
58
59 #-----------------------------------------------------------------------------
49 #-----------------------------------------------------------------------------
60 # Globals and constants
50 # Globals and constants
61 #-----------------------------------------------------------------------------
51 #-----------------------------------------------------------------------------
@@ -65,29 +55,9 b' TEMPLATE_PATH = "/../templates/"'
65 TEMPLATE_SKELETON_PATH = "/../templates/skeleton/"
55 TEMPLATE_SKELETON_PATH = "/../templates/skeleton/"
66 TEMPLATE_EXTENSION = ".tpl"
56 TEMPLATE_EXTENSION = ".tpl"
67
57
68 #Latex Jinja2 constants
69 LATEX_TEMPLATE_PATH = "/../templates/tex/"
70 LATEX_TEMPLATE_SKELETON_PATH = "/../templates/tex/skeleton/"
71 LATEX_TEMPLATE_EXTENSION = ".tplx"
72
73 #Special Jinja2 syntax that will not conflict when exporting latex.
74 LATEX_JINJA_COMMENT_BLOCK = ["((=", "=))"]
75 LATEX_JINJA_VARIABLE_BLOCK = ["(((", ")))"]
76 LATEX_JINJA_LOGIC_BLOCK = ["((*", "*))"]
77
78 #Jinja2 extensions to load.
58 #Jinja2 extensions to load.
79 JINJA_EXTENSIONS = ['jinja2.ext.loopcontrols']
59 JINJA_EXTENSIONS = ['jinja2.ext.loopcontrols']
80
60
81 #Latex substitutions for escaping latex.
82 LATEX_SUBS = (
83 (re.compile(r'\\'), r'\\textbackslash'),
84 (re.compile(r'([{}_#%&$])'), r'\\\1'),
85 (re.compile(r'~'), r'\~{}'),
86 (re.compile(r'\^'), r'\^{}'),
87 (re.compile(r'"'), r"''"),
88 (re.compile(r'\.\.\.+'), r'\\ldots'),
89 )
90
91 #-----------------------------------------------------------------------------
61 #-----------------------------------------------------------------------------
92 # Classes and functions
62 # Classes and functions
93 #-----------------------------------------------------------------------------
63 #-----------------------------------------------------------------------------
@@ -107,6 +77,7 b' class Exporter(Configurable):'
107 """
77 """
108 )
78 )
109
79
80 #TODO: Flagged for removal.
110 tex_environement = Bool(
81 tex_environement = Bool(
111 False,
82 False,
112 config=True,
83 config=True,
@@ -168,34 +139,15 b' class Exporter(Configurable):'
168 #Call the base class constructor
139 #Call the base class constructor
169 super(Exporter, self).__init__(config=config, **kw)
140 super(Exporter, self).__init__(config=config, **kw)
170
141
171 #Create a Latex environment if the user is exporting latex.
142 #Standard environment
172 if self.tex_environement:
143 self.ext = TEMPLATE_EXTENSION
173 self.ext = LATEX_TEMPLATE_EXTENSION
144 self.env = Environment(
174 self.env = Environment(
145 loader=FileSystemLoader([
175 loader=FileSystemLoader([
146 os.path.dirname(os.path.realpath(__file__)) + TEMPLATE_PATH,
176 os.path.dirname(os.path.realpath(__file__)) + LATEX_TEMPLATE_PATH,
147 os.path.dirname(os.path.realpath(__file__)) + TEMPLATE_SKELETON_PATH,
177 os.path.dirname(os.path.realpath(__file__)) + LATEX_TEMPLATE_SKELETON_PATH,
148 ]),
178 ]),
149 extensions=JINJA_EXTENSIONS
179 extensions=JINJA_EXTENSIONS
150 )
180 )
181
182 #Set special Jinja2 syntax that will not conflict with latex.
183 self.env.block_start_string = LATEX_JINJA_LOGIC_BLOCK[0]
184 self.env.block_end_string = LATEX_JINJA_LOGIC_BLOCK[1]
185 self.env.variable_start_string = LATEX_JINJA_VARIABLE_BLOCK[0]
186 self.env.variable_end_string = LATEX_JINJA_VARIABLE_BLOCK[1]
187 self.env.comment_start_string = LATEX_JINJA_COMMENT_BLOCK[0]
188 self.env.comment_end_string = LATEX_JINJA_COMMENT_BLOCK[1]
189
190 else: #Standard environment
191 self.ext = TEMPLATE_EXTENSION
192 self.env = Environment(
193 loader=FileSystemLoader([
194 os.path.dirname(os.path.realpath(__file__)) + TEMPLATE_PATH,
195 os.path.dirname(os.path.realpath(__file__)) + TEMPLATE_SKELETON_PATH,
196 ]),
197 extensions=JINJA_EXTENSIONS
198 )
199
151
200 for name in self.pre_transformer_order:
152 for name in self.pre_transformer_order:
201 # get the user-defined transformer first
153 # get the user-defined transformer first
General Comments 0
You need to be logged in to leave comments. Login now