##// END OF EJS Templates
Removed "profiles"... Templates that are shipped with nbconvert by default should...
Removed "profiles"... Templates that are shipped with nbconvert by default should have settings built into exporter.py class. If the user wants to add a new template and use profile setting with it, the "profile" (config file) should be specified via the commandline when calling the exporter.

File last commit:

r10390:fdc94c1d
r10435:896aaed3
Show More
latex.py
75 lines | 2.4 KiB | text/x-python | PythonLexer
Jonathan Frederic
Added code to fix the math $ in the notebook so it...
r9776 """
Matthias BUSSONNIER
fix remove math space
r9882 Module that allows latex output notebooks to be conditioned before
Jonathan Frederic
Added code to fix the math $ in the notebook so it...
r9776 they are converted.
"""
Matthias BUSSONNIER
fix some relative path issues
r9819 from __future__ import absolute_import
Jonathan Frederic
Added code to fix the math $ in the notebook so it...
r9776
# Configurable traitlets
# Needed to override transformer
Matthias BUSSONNIER
fix some relative path issues
r9819 from .transformers import (ActivatableTransformer)
Jonathan Frederic
Added code to fix the math $ in the notebook so it...
r9776
class LatexTransformer(ActivatableTransformer):
"""
Converter for latex destined documents.
Matthias BUSSONNIER
fix remove math space
r9882 """
Jonathan Frederic
Unecessary re-coding, inherits from base now.
r9779
def cell_transform(self, cell, other, index):
Jonathan Frederic
Added code to fix the math $ in the notebook so it...
r9776 """
Jonathan Frederic
Unecessary re-coding, inherits from base now.
r9779 Apply a transformation on each cell,
receive the current cell, the resource dict and the index of current cell as parameter.
Returns modified cell and resource dict.
Jonathan Frederic
Added code to fix the math $ in the notebook so it...
r9776 """
Jonathan Frederic
Unecessary re-coding, inherits from base now.
r9779 if hasattr(cell, "source") and cell.cell_type == "markdown":
Jonathan Frederic
Renamed remove_math_space to rm_math_space...
r9953 cell.source = rm_math_space(cell.source)
Jonathan Frederic
Unecessary re-coding, inherits from base now.
r9779 return cell, other
Jonathan Frederic
Renamed remove_math_space to rm_math_space...
r9953 def rm_math_space(text):
Matthias BUSSONNIER
fix remove math space
r9882 """
Remove the space between latex math commands and enclosing $ symbols.
"""
# First, scan through the markdown looking for $. If
# a $ symbol is found, without a preceding \, assume
# it is the start of a math block. UNLESS that $ is
# not followed by another within two math_lines.
math_regions = []
math_lines = 0
within_math = False
math_start_index = 0
ptext = ''
last_character = ""
skip = False
for index, char in enumerate(text):
#Make sure the character isn't preceeded by a backslash
if (char == "$" and last_character != "\\"):
# Close the math region if this is an ending $
if within_math:
within_math = False
skip = True
ptext = ptext+'$'+text[math_start_index+1:index].strip()+'$'
math_regions.append([math_start_index, index+1])
Jonathan Frederic
Added code to fix the math $ in the notebook so it...
r9776 else:
Matthias BUSSONNIER
fix remove math space
r9882 # Start a new math region
within_math = True
math_start_index = index
math_lines = 0
# If we are in a math region, count the number of lines parsed.
# Cancel the math region if we find two line breaks!
elif char == "\n":
if within_math:
math_lines += 1
if math_lines > 1:
within_math = False
Matthias BUSSONNIER
fix latex_transformer and add test
r9888 ptext = ptext+text[math_start_index:index]
Matthias BUSSONNIER
fix write binary and non math $...
r9885
Matthias BUSSONNIER
fix remove math space
r9882 # Remember the last character so we can easily watch
# for backslashes
last_character = char
if not within_math and not skip:
ptext = ptext+char
if skip:
skip = False
return ptext