##// END OF EJS Templates
Merge pull request #4271 from takluyver/piped-tests-headings...
Merge pull request #4271 from takluyver/piped-tests-headings Hopefully fix ordering of output on ShiningPanda

File last commit:

r12742:c74425a8
r12789:7ab1fd22 merge
Show More
latex.py
74 lines | 2.7 KiB | text/x-python | PythonLexer
Jonathan Frederic
Cleanup and refactor, transformers
r10674 """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.
"""
Jonathan Frederic
Transformer refactor
r10436 #-----------------------------------------------------------------------------
# Copyright (c) 2013, the IPython Development Team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file COPYING.txt, distributed with this software.
#-----------------------------------------------------------------------------
Jonathan Frederic
Added code to fix the math $ in the notebook so it...
r9776
Jonathan Frederic
Transformer refactor
r10436 #-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
Jonathan Frederic
Cleanup and refactor, transformers
r10674
Jonathan Frederic
Transformer refactor
r10436 from __future__ import print_function, absolute_import
Jonathan Frederic
Include mdframed with nbconvert, reference directly
r12684 import os
Jonathan Frederic
Added code to fix the math $ in the notebook so it...
r9776
Jonathan Frederic
Move the pygments definition importing logic from the...
r12659 # Third-party import, needed for Pygments latex definitions.
from pygments.formatters import LatexFormatter
# ipy imports
Paul Ivanov
replace 'transformer' with 'preprocessor'
r12219 from .base import (Preprocessor)
Brian E. Granger
Fixing import for nbconvert.
r11089 from IPython.nbconvert import filters
Jonathan Frederic
Added code to fix the math $ in the notebook so it...
r9776
Jonathan Frederic
Transformer refactor
r10436 #-----------------------------------------------------------------------------
# Classes
#-----------------------------------------------------------------------------
Jonathan Frederic
Cleanup and refactor, transformers
r10674
Paul Ivanov
replace 'transformer' with 'preprocessor'
r12219 class LatexPreprocessor(Preprocessor):
Jonathan Frederic
Added code to fix the math $ in the notebook so it...
r9776 """
Converter for latex destined documents.
Matthias BUSSONNIER
fix remove math space
r9882 """
Jonathan Frederic
Unecessary re-coding, inherits from base now.
r9779
Jonathan Frederic
Move the pygments definition importing logic from the...
r12659 def preprocess(self, nb, resources):
"""
Preprocessing to apply on each notebook.
Parameters
----------
nb : NotebookNode
Notebook being converted
resources : dictionary
Additional resources used in the conversion process. Allows
preprocessors to pass variables into the Jinja engine.
"""
# Generate Pygments definitions for Latex
Jonathan Frederic
Load pygment definitions in latex base
r12669 resources["latex"] = {}
Jonathan Frederic
s/pygment/pygments
r12742 resources["latex"]["pygments_definitions"] = LatexFormatter().get_style_defs()
Jonathan Frederic
Move the pygments definition importing logic from the...
r12659 return super(LatexPreprocessor, self).preprocess(nb, resources)
Paul Ivanov
replace 'transformer' with 'preprocessor'
r12219 def preprocess_cell(self, cell, resources, index):
Jonathan Frederic
Added code to fix the math $ in the notebook so it...
r9776 """
Paul Ivanov
fixup minor typos from search/replace
r12220 Apply a transformation on each cell,
Jonathan Frederic
Cleanup and refactor, transformers
r10674
Parameters
----------
cell : NotebookNode cell
Notebook cell being processed
resources : dictionary
Additional resources used in the conversion process. Allows
Paul Ivanov
replace 'transformer' with 'preprocessor'
r12219 preprocessors to pass variables into the Jinja engine.
Jonathan Frederic
Cleanup and refactor, transformers
r10674 index : int
Modified index of the cell being processed (see base.py)
Jonathan Frederic
Added code to fix the math $ in the notebook so it...
r9776 """
Jonathan Frederic
Added spaces between comments.
r10476
Jonathan Frederic
Cleanup and refactor, transformers
r10674 #If the cell is a markdown cell, preprocess the ampersands used to
#remove the space between them and their contents. Latex will complain
#if spaces exist between the ampersands and the math content.
#See filters.latex.rm_math_space for more information.
Jonathan Frederic
Unecessary re-coding, inherits from base now.
r9779 if hasattr(cell, "source") and cell.cell_type == "markdown":
Jonathan Frederic
Filter names cleanup
r11685 cell.source = filters.strip_math_space(cell.source)
Jonathan Frederic
Cleanup and refactor, transformers
r10674 return cell, resources