latex.py
47 lines
| 1.7 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 | |||
MinRK
|
r12864 | from .base import Preprocessor | ||
Jonathan Frederic
|
r9776 | |||
Jonathan Frederic
|
r10436 | #----------------------------------------------------------------------------- | ||
# Classes | ||||
#----------------------------------------------------------------------------- | ||||
Jonathan Frederic
|
r10674 | |||
Paul Ivanov
|
r12219 | class LatexPreprocessor(Preprocessor): | ||
MinRK
|
r12864 | """Preprocessor for latex destined documents. | ||
Mainly populates the `latex` key in the resources dict, | ||||
adding definitions for pygments highlight styles. | ||||
Matthias BUSSONNIER
|
r9882 | """ | ||
Jonathan Frederic
|
r9779 | |||
Jonathan Frederic
|
r12659 | def preprocess(self, nb, resources): | ||
MinRK
|
r12864 | """Preprocessing to apply on each notebook. | ||
Jonathan Frederic
|
r12659 | |||
Parameters | ||||
---------- | ||||
nb : NotebookNode | ||||
Notebook being converted | ||||
resources : dictionary | ||||
Additional resources used in the conversion process. Allows | ||||
preprocessors to pass variables into the Jinja engine. | ||||
""" | ||||
MinRK
|
r12864 | # Generate Pygments definitions for Latex | ||
from pygments.formatters import LatexFormatter | ||||
Jonathan Frederic
|
r10476 | |||
MinRK
|
r12864 | resources.setdefault("latex", {}) | ||
resources["latex"].setdefault("pygments_definitions", LatexFormatter().get_style_defs()) | ||||
return nb, resources | ||||