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