latex.py
53 lines
| 2.0 KiB
| text/x-python
|
PythonLexer
|
r10674 | """Module that allows latex output notebooks to be conditioned before | ||
|
r9776 | they are converted. | ||
""" | ||||
|
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. | ||||
#----------------------------------------------------------------------------- | ||||
|
r9776 | |||
|
r10436 | #----------------------------------------------------------------------------- | ||
# Imports | ||||
#----------------------------------------------------------------------------- | ||||
|
r10674 | |||
|
r10436 | from __future__ import print_function, absolute_import | ||
|
r9776 | |||
|
r10436 | # Our own imports | ||
|
r9776 | # Needed to override transformer | ||
|
r11388 | from .base import (ConfigurableTransformer) | ||
|
r11089 | from IPython.nbconvert import filters | ||
|
r9776 | |||
|
r10436 | #----------------------------------------------------------------------------- | ||
# Classes | ||||
#----------------------------------------------------------------------------- | ||||
|
r10674 | |||
|
r11388 | class LatexTransformer(ConfigurableTransformer): | ||
|
r9776 | """ | ||
Converter for latex destined documents. | ||||
|
r9882 | """ | ||
|
r9779 | |||
|
r11367 | def transform_cell(self, cell, resources, index): | ||
|
r9776 | """ | ||
|
r9779 | Apply a transformation on each cell, | ||
|
r10674 | |||
Parameters | ||||
---------- | ||||
cell : NotebookNode cell | ||||
Notebook cell being processed | ||||
resources : dictionary | ||||
Additional resources used in the conversion process. Allows | ||||
transformers to pass variables into the Jinja engine. | ||||
index : int | ||||
Modified index of the cell being processed (see base.py) | ||||
|
r9776 | """ | ||
|
r10476 | |||
|
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. | ||||
|
r9779 | if hasattr(cell, "source") and cell.cell_type == "markdown": | ||
|
r11089 | cell.source = filters.rm_math_space(cell.source) | ||
|
r10674 | return cell, resources | ||