Show More
@@ -1,220 +1,227 b'' | |||||
1 | """Base classes for the notebook conversion pipeline. |
|
1 | """Base classes for the notebook conversion pipeline. | |
2 |
|
2 | |||
3 | This module defines Converter, from which all objects designed to implement |
|
3 | This module defines Converter, from which all objects designed to implement | |
4 | a conversion of IPython notebooks to some other format should inherit. |
|
4 | a conversion of IPython notebooks to some other format should inherit. | |
5 | """ |
|
5 | """ | |
6 | #----------------------------------------------------------------------------- |
|
6 | #----------------------------------------------------------------------------- | |
7 | # Copyright (c) 2012, the IPython Development Team. |
|
7 | # Copyright (c) 2012, the IPython Development Team. | |
8 | # |
|
8 | # | |
9 | # Distributed under the terms of the Modified BSD License. |
|
9 | # Distributed under the terms of the Modified BSD License. | |
10 | # |
|
10 | # | |
11 | # The full license is in the file COPYING.txt, distributed with this software. |
|
11 | # The full license is in the file COPYING.txt, distributed with this software. | |
12 | #----------------------------------------------------------------------------- |
|
12 | #----------------------------------------------------------------------------- | |
13 |
|
13 | |||
14 | #----------------------------------------------------------------------------- |
|
14 | #----------------------------------------------------------------------------- | |
15 | # Imports |
|
15 | # Imports | |
16 | #----------------------------------------------------------------------------- |
|
16 | #----------------------------------------------------------------------------- | |
17 |
|
17 | |||
18 | from __future__ import print_function, absolute_import |
|
18 | from __future__ import print_function, absolute_import | |
19 | from .transformers import extract_figure_transformer |
|
|||
20 | import converters.transformers as trans |
|
19 | import converters.transformers as trans | |
21 | from converters.jinja_filters import (python_comment, indent, |
|
20 | from converters.jinja_filters import (python_comment, indent, | |
22 | rm_fake, remove_ansi, markdown, highlight, |
|
21 | rm_fake, remove_ansi, markdown, highlight, | |
23 | ansi2html, markdown2latex, escape_tex) |
|
22 | ansi2html, markdown2latex, escape_tex) | |
24 |
|
23 | |||
25 |
|
24 | |||
|
25 | ||||
26 | # Stdlib imports |
|
26 | # Stdlib imports | |
27 | import io |
|
27 | import io | |
28 | import os |
|
28 | import os | |
29 | from IPython.utils import path |
|
29 | from IPython.utils import path | |
|
30 | from IPython.utils.traitlets import MetaHasTraits | |||
30 |
|
31 | |||
31 | from jinja2 import Environment, FileSystemLoader |
|
32 | from jinja2 import Environment, FileSystemLoader | |
32 | env = Environment( |
|
33 | env = Environment( | |
33 | loader=FileSystemLoader([ |
|
34 | loader=FileSystemLoader([ | |
34 | './templates/', |
|
35 | './templates/', | |
35 | './templates/skeleton/', |
|
36 | './templates/skeleton/', | |
36 | ]), |
|
37 | ]), | |
37 | extensions=['jinja2.ext.loopcontrols'] |
|
38 | extensions=['jinja2.ext.loopcontrols'] | |
38 | ) |
|
39 | ) | |
39 |
|
40 | |||
40 | texenv = Environment( |
|
41 | texenv = Environment( | |
41 | loader=FileSystemLoader([ |
|
42 | loader=FileSystemLoader([ | |
42 | './templates/tex/', |
|
43 | './templates/tex/', | |
43 | './templates/skeleton/tex/', |
|
44 | './templates/skeleton/tex/', | |
44 | ]), |
|
45 | ]), | |
45 | extensions=['jinja2.ext.loopcontrols'] |
|
46 | extensions=['jinja2.ext.loopcontrols'] | |
46 | ) |
|
47 | ) | |
47 |
|
48 | |||
48 | # IPython imports |
|
49 | # IPython imports | |
49 | from IPython.nbformat import current as nbformat |
|
50 | from IPython.nbformat import current as nbformat | |
50 | from IPython.config.configurable import Configurable |
|
51 | from IPython.config.configurable import Configurable | |
51 | from IPython.utils.traitlets import ( Unicode, Any, List, Bool) |
|
52 | from IPython.utils.traitlets import ( Unicode, Any, List, Bool) | |
52 |
|
53 | |||
53 | #----------------------------------------------------------------------------- |
|
54 | #----------------------------------------------------------------------------- | |
54 | # Class declarations |
|
55 | # Class declarations | |
55 | #----------------------------------------------------------------------------- |
|
56 | #----------------------------------------------------------------------------- | |
56 | class ConversionException(Exception): |
|
57 | class ConversionException(Exception): | |
57 | pass |
|
58 | pass | |
58 |
|
59 | |||
59 |
|
60 | |||
60 | def header_body(): |
|
61 | def header_body(): | |
61 | """Return the body of the header as a list of strings.""" |
|
62 | """Return the body of the header as a list of strings.""" | |
62 |
|
63 | |||
63 | from pygments.formatters import HtmlFormatter |
|
64 | from pygments.formatters import HtmlFormatter | |
64 |
|
65 | |||
65 | header = [] |
|
66 | header = [] | |
66 | static = os.path.join(path.get_ipython_package_dir(), |
|
67 | static = os.path.join(path.get_ipython_package_dir(), | |
67 | 'frontend', 'html', 'notebook', 'static', |
|
68 | 'frontend', 'html', 'notebook', 'static', | |
68 | ) |
|
69 | ) | |
69 | here = os.path.split(os.path.realpath(__file__))[0] |
|
70 | here = os.path.split(os.path.realpath(__file__))[0] | |
70 | css = os.path.join(static, 'css') |
|
71 | css = os.path.join(static, 'css') | |
71 | for sheet in [ |
|
72 | for sheet in [ | |
72 | # do we need jquery and prettify? |
|
73 | # do we need jquery and prettify? | |
73 | # os.path.join(static, 'jquery', 'css', 'themes', 'base', |
|
74 | # os.path.join(static, 'jquery', 'css', 'themes', 'base', | |
74 | # 'jquery-ui.min.css'), |
|
75 | # 'jquery-ui.min.css'), | |
75 | # os.path.join(static, 'prettify', 'prettify.css'), |
|
76 | # os.path.join(static, 'prettify', 'prettify.css'), | |
76 | os.path.join(css, 'boilerplate.css'), |
|
77 | os.path.join(css, 'boilerplate.css'), | |
77 | os.path.join(css, 'fbm.css'), |
|
78 | os.path.join(css, 'fbm.css'), | |
78 | os.path.join(css, 'notebook.css'), |
|
79 | os.path.join(css, 'notebook.css'), | |
79 | os.path.join(css, 'renderedhtml.css'), |
|
80 | os.path.join(css, 'renderedhtml.css'), | |
80 | # our overrides: |
|
81 | # our overrides: | |
81 | os.path.join(here, '..', 'css', 'static_html.css'), |
|
82 | os.path.join(here, '..', 'css', 'static_html.css'), | |
82 | ]: |
|
83 | ]: | |
83 |
|
84 | |||
84 | with io.open(sheet, encoding='utf-8') as f: |
|
85 | with io.open(sheet, encoding='utf-8') as f: | |
85 | s = f.read() |
|
86 | s = f.read() | |
86 | header.append(s) |
|
87 | header.append(s) | |
87 |
|
88 | |||
88 | pygments_css = HtmlFormatter().get_style_defs('.highlight') |
|
89 | pygments_css = HtmlFormatter().get_style_defs('.highlight') | |
89 | header.append(pygments_css) |
|
90 | header.append(pygments_css) | |
90 | return header |
|
91 | return header | |
91 |
|
92 | |||
92 |
|
93 | |||
93 |
|
94 | |||
94 |
|
95 | |||
95 |
|
96 | |||
96 | inlining = {} |
|
97 | inlining = {} | |
97 | inlining['css'] = header_body() |
|
98 | inlining['css'] = header_body() | |
98 |
|
99 | |||
99 |
|
100 | |||
100 |
|
101 | |||
101 | texenv.block_start_string = '((*' |
|
102 | texenv.block_start_string = '((*' | |
102 | texenv.block_end_string = '*))' |
|
103 | texenv.block_end_string = '*))' | |
103 | texenv.variable_start_string = '(((' |
|
104 | texenv.variable_start_string = '(((' | |
104 | texenv.variable_end_string = ')))' |
|
105 | texenv.variable_end_string = ')))' | |
105 | texenv.comment_start_string = '((=' |
|
106 | texenv.comment_start_string = '((=' | |
106 | texenv.comment_end_string = '=))' |
|
107 | texenv.comment_end_string = '=))' | |
107 | texenv.filters['escape_tex'] = escape_tex |
|
108 | texenv.filters['escape_tex'] = escape_tex | |
108 |
|
109 | |||
109 |
|
110 | |||
110 | class ConverterTemplate(Configurable): |
|
111 | class ConverterTemplate(Configurable): | |
111 | """ A Jinja2 base converter templates""" |
|
112 | """ A Jinja2 base converter templates""" | |
112 |
|
113 | |||
113 | display_data_priority = List(['html', 'pdf', 'svg', 'latex', 'png', 'jpg', 'jpeg' , 'text'], |
|
114 | display_data_priority = List(['html', 'pdf', 'svg', 'latex', 'png', 'jpg', 'jpeg' , 'text'], | |
114 | config=True, |
|
115 | config=True, | |
115 | help= """ |
|
116 | help= """ | |
116 | An ordered list of prefered output type, the first |
|
117 | An ordered list of prefered output type, the first | |
117 | encounterd will usually be used when converting discarding |
|
118 | encounterd will usually be used when converting discarding | |
118 | the others. |
|
119 | the others. | |
119 | """ |
|
120 | """ | |
120 | ) |
|
121 | ) | |
121 |
|
122 | |||
122 | pre_transformer_order = List(['haspyout_transformer'], |
|
123 | pre_transformer_order = List(['haspyout_transformer', 'Foobar'], | |
123 | config=True, |
|
124 | config=True, | |
124 | help= """ |
|
125 | help= """ | |
125 | An ordered list of pre transformer to apply to the ipynb |
|
126 | An ordered list of pre transformer to apply to the ipynb | |
126 | file befor running through templates |
|
127 | file befor running through templates | |
127 | """ |
|
128 | """ | |
128 | ) |
|
129 | ) | |
129 |
|
130 | |||
130 | extract_figures = Bool(False, |
|
131 | extract_figures = Bool(False, | |
131 | config=True, |
|
132 | config=True, | |
132 | help= """ |
|
133 | help= """ | |
133 | wether to remove figure data from ipynb and store them in auxiliary |
|
134 | wether to remove figure data from ipynb and store them in auxiliary | |
134 | dictionnary |
|
135 | dictionnary | |
135 | """ |
|
136 | """ | |
136 | ) |
|
137 | ) | |
137 |
|
138 | |||
138 | tex_environement = Bool(False, |
|
139 | tex_environement = Bool(False, | |
139 | config=True, |
|
140 | config=True, | |
140 | help=""" is this a tex environment or not """) |
|
141 | help=""" is this a tex environment or not """) | |
141 |
|
142 | |||
142 | template_file = Unicode('', |
|
143 | template_file = Unicode('', | |
143 | config=True, |
|
144 | config=True, | |
144 | help=""" whetever """ ) |
|
145 | help=""" whetever """ ) | |
145 | #------------------------------------------------------------------------- |
|
146 | #------------------------------------------------------------------------- | |
146 | # Instance-level attributes that are set in the constructor for this |
|
147 | # Instance-level attributes that are set in the constructor for this | |
147 | # class. |
|
148 | # class. | |
148 | #------------------------------------------------------------------------- |
|
149 | #------------------------------------------------------------------------- | |
149 | infile = Any() |
|
150 | infile = Any() | |
150 |
|
151 | |||
151 |
|
152 | |||
152 | infile_dir = Unicode() |
|
153 | infile_dir = Unicode() | |
153 |
|
154 | |||
154 | def filter_data_type(self, output): |
|
155 | def filter_data_type(self, output): | |
155 | for fmt in self.display_data_priority: |
|
156 | for fmt in self.display_data_priority: | |
156 | if fmt in output: |
|
157 | if fmt in output: | |
157 | return [fmt] |
|
158 | return [fmt] | |
158 |
|
159 | |||
159 | def __init__(self, preprocessors=[], config=None, **kw): |
|
160 | def __init__(self, preprocessors=[], config=None, **kw): | |
160 | """ |
|
161 | """ | |
161 | config: the Configurable confg object to pass around |
|
162 | config: the Configurable confg object to pass around | |
162 |
|
163 | |||
163 | preprocessors: list of function to run on ipynb json data before conversion |
|
164 | preprocessors: list of function to run on ipynb json data before conversion | |
164 | to extract/inline file, |
|
165 | to extract/inline file, | |
165 |
|
166 | |||
166 | """ |
|
167 | """ | |
167 | super(ConverterTemplate, self).__init__(config=config, **kw) |
|
168 | super(ConverterTemplate, self).__init__(config=config, **kw) | |
168 | self.env = texenv if self.tex_environement else env |
|
169 | self.env = texenv if self.tex_environement else env | |
169 | self.ext = '.tplx' if self.tex_environement else '.tpl' |
|
170 | self.ext = '.tplx' if self.tex_environement else '.tpl' | |
170 | self.nb = None |
|
171 | self.nb = None | |
171 | self.preprocessors = preprocessors |
|
172 | self.preprocessors = preprocessors | |
|
173 | ||||
172 | for name in self.pre_transformer_order: |
|
174 | for name in self.pre_transformer_order: | |
173 |
|
|
175 | tr = getattr(trans, name) | |
|
176 | if isinstance(tr, MetaHasTraits): | |||
|
177 | tr = tr(config=config) | |||
|
178 | self.preprocessors.append(tr) | |||
174 | if self.extract_figures: |
|
179 | if self.extract_figures: | |
175 |
self.preprocessors.append( |
|
180 | self.preprocessors.append(trans.ExtractFigureTransformer(config=config)) | |
176 |
|
181 | |||
177 | self.env.filters['filter_data_type'] = self.filter_data_type |
|
182 | self.env.filters['filter_data_type'] = self.filter_data_type | |
178 | self.env.filters['pycomment'] = python_comment |
|
183 | self.env.filters['pycomment'] = python_comment | |
179 | self.env.filters['indent'] = indent |
|
184 | self.env.filters['indent'] = indent | |
180 | self.env.filters['rm_fake'] = rm_fake |
|
185 | self.env.filters['rm_fake'] = rm_fake | |
181 | self.env.filters['rm_ansi'] = remove_ansi |
|
186 | self.env.filters['rm_ansi'] = remove_ansi | |
182 | self.env.filters['markdown'] = markdown |
|
187 | self.env.filters['markdown'] = markdown | |
183 | self.env.filters['highlight'] = highlight |
|
188 | self.env.filters['highlight'] = highlight | |
184 | self.env.filters['ansi2html'] = ansi2html |
|
189 | self.env.filters['ansi2html'] = ansi2html | |
185 | self.env.filters['markdown2latex'] = markdown2latex |
|
190 | self.env.filters['markdown2latex'] = markdown2latex | |
186 |
|
191 | |||
187 | self.template = self.env.get_template(self.template_file+self.ext) |
|
192 | self.template = self.env.get_template(self.template_file+self.ext) | |
188 |
|
193 | |||
189 |
|
194 | |||
190 | def process(self): |
|
195 | def process(self): | |
191 | """ |
|
196 | """ | |
192 | preprocess the notebook json for easier use with the templates. |
|
197 | preprocess the notebook json for easier use with the templates. | |
193 | will call all the `preprocessor`s in order before returning it. |
|
198 | will call all the `preprocessor`s in order before returning it. | |
194 | """ |
|
199 | """ | |
195 | nb = self.nb |
|
200 | nb = self.nb | |
196 |
|
201 | |||
197 | # dict of 'resources' that could be made by the preprocessors |
|
202 | # dict of 'resources' that could be made by the preprocessors | |
198 | # like key/value data to extract files from ipynb like in latex conversion |
|
203 | # like key/value data to extract files from ipynb like in latex conversion | |
199 | resources = {} |
|
204 | resources = {} | |
200 |
|
205 | |||
201 | for preprocessor in self.preprocessors: |
|
206 | for preprocessor in self.preprocessors: | |
202 | nb, resources = preprocessor(nb, resources) |
|
207 | nb, resources = preprocessor(nb, resources) | |
203 |
|
208 | |||
204 | return nb, resources |
|
209 | return nb, resources | |
205 |
|
210 | |||
206 | def convert(self): |
|
211 | def convert(self): | |
207 | """ convert the ipynb file |
|
212 | """ convert the ipynb file | |
208 |
|
213 | |||
209 | return both the converted ipynb file and a dict containing potential |
|
214 | return both the converted ipynb file and a dict containing potential | |
210 | other resources |
|
215 | other resources | |
211 | """ |
|
216 | """ | |
212 | nb, resources = self.process() |
|
217 | nb, resources = self.process() | |
213 | return self.template.render(nb=nb, inlining=inlining), resources |
|
218 | return self.template.render(nb=nb, inlining=inlining), resources | |
214 |
|
219 | |||
215 |
|
220 | |||
216 | def read(self, filename): |
|
221 | def read(self, filename): | |
217 | "read and parse notebook into NotebookNode called self.nb" |
|
222 | "read and parse notebook into NotebookNode called self.nb" | |
218 | with io.open(filename) as f: |
|
223 | with io.open(filename) as f: | |
219 | self.nb = nbformat.read(f, 'json') |
|
224 | self.nb = nbformat.read(f, 'json') | |
220 |
|
225 | |||
|
226 | ||||
|
227 |
@@ -1,64 +1,125 b'' | |||||
1 | """ |
|
1 | """ | |
2 |
|
2 | |||
3 | """ |
|
3 | """ | |
4 |
|
4 | |||
|
5 | from __future__ import print_function | |||
|
6 | ||||
|
7 | from IPython.config.configurable import Configurable | |||
|
8 | from IPython.utils.traitlets import Unicode, Bool, Dict | |||
|
9 | ||||
|
10 | class ConfigurableTransformers(Configurable): | |||
|
11 | """ A configurable transformer """ | |||
|
12 | ||||
|
13 | def __init__(self, config=None, **kw): | |||
|
14 | super(ConfigurableTransformers, self).__init__(config=config, **kw) | |||
|
15 | ||||
|
16 | def __call__(self, nb, other): | |||
|
17 | try : | |||
|
18 | for worksheet in nb.worksheets : | |||
|
19 | for index, cell in enumerate(worksheet.cells): | |||
|
20 | worksheet.cells[index], other = self.cell_transform(cell, other, index) | |||
|
21 | return nb, other | |||
|
22 | except NotImplementedError as error : | |||
|
23 | raise NotImplementedError('should be implemented by subclass') | |||
|
24 | ||||
|
25 | def cell_transform(self, cell, other, index): | |||
|
26 | """ | |||
|
27 | Overwrite if you want to apply a transformation on each cell | |||
|
28 | """ | |||
|
29 | raise NotImplementedError('should be implemented by subclass') | |||
|
30 | ||||
|
31 | ||||
|
32 | class Foobar(ConfigurableTransformers): | |||
|
33 | message = Unicode('-- nothing', config=True) | |||
|
34 | ||||
|
35 | ||||
|
36 | def cell_transform(self, cell, other, index): | |||
|
37 | return cell, other | |||
|
38 | ||||
|
39 | ||||
5 | def cell_preprocessor(function): |
|
40 | def cell_preprocessor(function): | |
6 | """ wrap a function to be executed on all cells of a notebook |
|
41 | """ wrap a function to be executed on all cells of a notebook | |
7 |
|
42 | |||
8 | wrapped function parameters : |
|
43 | wrapped function parameters : | |
9 | cell : the cell |
|
44 | cell : the cell | |
10 | other : external resources |
|
45 | other : external resources | |
11 | index : index of the cell |
|
46 | index : index of the cell | |
12 | """ |
|
47 | """ | |
13 | def wrappedfunc(nb, other): |
|
48 | def wrappedfunc(nb, other): | |
14 | for worksheet in nb.worksheets : |
|
49 | for worksheet in nb.worksheets : | |
15 | for index, cell in enumerate(worksheet.cells): |
|
50 | for index, cell in enumerate(worksheet.cells): | |
16 | worksheet.cells[index], other = function(cell, other, index) |
|
51 | worksheet.cells[index], other = function(cell, other, index) | |
17 | return nb, other |
|
52 | return nb, other | |
18 | return wrappedfunc |
|
53 | return wrappedfunc | |
19 |
|
54 | |||
20 |
|
55 | |||
21 | @cell_preprocessor |
|
56 | @cell_preprocessor | |
22 | def haspyout_transformer(cell, other, count): |
|
57 | def haspyout_transformer(cell, other, count): | |
23 | """ |
|
58 | """ | |
24 | Add a haspyout flag to cell that have it |
|
59 | Add a haspyout flag to cell that have it | |
25 |
|
60 | |||
26 | Easier for templating, where you can't know in advance |
|
61 | Easier for templating, where you can't know in advance | |
27 | wether to write the out prompt |
|
62 | wether to write the out prompt | |
28 |
|
63 | |||
29 | """ |
|
64 | """ | |
30 | cell.type = cell.cell_type |
|
65 | cell.type = cell.cell_type | |
31 | cell.haspyout = False |
|
66 | cell.haspyout = False | |
32 | for out in cell.get('outputs', []): |
|
67 | for out in cell.get('outputs', []): | |
33 | if out.output_type == 'pyout': |
|
68 | if out.output_type == 'pyout': | |
34 | cell.haspyout = True |
|
69 | cell.haspyout = True | |
35 | break |
|
70 | break | |
36 | return cell, other |
|
71 | return cell, other | |
37 |
|
72 | |||
38 |
|
73 | |||
39 | # todo, make the key part configurable. |
|
74 | # todo, make the key part configurable. | |
40 | def _new_figure(data, fmt, count): |
|
|||
41 | """Create a new figure file in the given format. |
|
|||
42 |
|
75 | |||
43 | Returns a path relative to the input file. |
|
76 | class ExtractFigureTransformer(ConfigurableTransformers): | |
44 | """ |
|
77 | enabled = Bool(False, | |
45 | figname = '_fig_%02i.%s' % (count, fmt) |
|
78 | config=True, | |
|
79 | help=""" If set to false, this transformer will be no-op """ | |||
|
80 | ) | |||
46 |
|
81 | |||
47 | # Binary files are base64-encoded, SVG is already XML |
|
82 | extra_ext_map = Dict({}, | |
48 | if fmt in ('png', 'jpg', 'pdf'): |
|
83 | config=True, | |
49 | data = data.decode('base64') |
|
84 | help="""extra map to override extension based on type. | |
|
85 | Usefull for latex where svg will be converted to pdf before inclusion | |||
|
86 | """ | |||
|
87 | ) | |||
50 |
|
88 | |||
51 | return figname, data |
|
|||
52 |
|
89 | |||
53 | @cell_preprocessor |
|
90 | #to do change this to .format {} syntax | |
54 | def extract_figure_transformer(cell, other, count): |
|
91 | key_tpl = Unicode('_fig_%02i.%s', config=True) | |
55 | for i, out in enumerate(cell.get('outputs', [])): |
|
92 | ||
56 | for type in ['html', 'pdf', 'svg', 'latex', 'png', 'jpg', 'jpeg']: |
|
93 | def _get_ext(self, ext): | |
57 | if out.hasattr(type): |
|
94 | if ext in self.extra_ext_map : | |
58 | figname, data = _new_figure(out[type], type, count) |
|
95 | return self.extra_ext_map[ext] | |
59 | cell.outputs[i][type] = figname |
|
96 | return ext | |
60 | out['key_'+type] = figname |
|
97 | ||
61 | other[figname] = data |
|
98 | def _new_figure(self, data, fmt, count): | |
62 | count = count+1 |
|
99 | """Create a new figure file in the given format. | |
63 | return cell, other |
|
100 | ||
|
101 | Returns a path relative to the input file. | |||
|
102 | """ | |||
|
103 | figname = self.key_tpl % (count, self._get_ext(fmt)) | |||
|
104 | key = self.key_tpl % (count, fmt) | |||
|
105 | ||||
|
106 | # Binary files are base64-encoded, SVG is already XML | |||
|
107 | if fmt in ('png', 'jpg', 'pdf'): | |||
|
108 | data = data.decode('base64') | |||
|
109 | ||||
|
110 | return figname, key, data | |||
|
111 | ||||
|
112 | ||||
|
113 | def cell_transform(self, cell, other, count): | |||
|
114 | if not self.enabled: | |||
|
115 | return cell, other | |||
|
116 | for i, out in enumerate(cell.get('outputs', [])): | |||
|
117 | for type in ['html', 'pdf', 'svg', 'latex', 'png', 'jpg', 'jpeg']: | |||
|
118 | if out.hasattr(type): | |||
|
119 | figname, key, data = self._new_figure(out[type], type, count) | |||
|
120 | cell.outputs[i][type] = figname | |||
|
121 | out['key_'+type] = figname | |||
|
122 | other[key] = data | |||
|
123 | count = count+1 | |||
|
124 | return cell, other | |||
64 |
|
125 |
@@ -1,5 +1,8 b'' | |||||
1 | c = get_config() |
|
1 | c = get_config() | |
2 |
|
2 | |||
|
3 | ||||
3 | c.ConverterTemplate.extract_figures=False |
|
4 | c.ConverterTemplate.extract_figures=False | |
4 | c.ConverterTemplate.template_file='fullhtml' |
|
5 | c.ConverterTemplate.template_file='fullhtml' | |
5 | c.ConverterTemplate.tex_environement=False |
|
6 | c.ConverterTemplate.tex_environement=False | |
|
7 | ||||
|
8 | c.ExtractFigureTransformer.enabled = False |
@@ -1,5 +1,7 b'' | |||||
1 | c = get_config() |
|
1 | c = get_config() | |
2 |
|
2 | |||
3 |
c.ConverterTemplate.extract_figures= |
|
3 | c.ConverterTemplate.extract_figures=True | |
4 | c.ConverterTemplate.template_file='latex_base' |
|
4 | c.ConverterTemplate.template_file='latex_base' | |
5 | c.ConverterTemplate.tex_environement=True |
|
5 | c.ConverterTemplate.tex_environement=True | |
|
6 | ||||
|
7 | c.ExtractFigureTransformer.extra_ext_map={'svg':'pdf'} |
@@ -1,94 +1,94 b'' | |||||
1 | #!/usr/bin/env python |
|
1 | #!/usr/bin/env python | |
2 | #----------------------------------------------------------------------------- |
|
2 | #----------------------------------------------------------------------------- | |
3 | # Imports |
|
3 | # Imports | |
4 | #----------------------------------------------------------------------------- |
|
4 | #----------------------------------------------------------------------------- | |
5 | from __future__ import print_function |
|
5 | from __future__ import print_function | |
6 | import sys |
|
6 | import sys | |
7 | import io |
|
7 | import io | |
8 | import os |
|
8 | import os | |
9 |
|
9 | |||
10 | from converters.template import * |
|
10 | from converters.template import * | |
11 | from converters.template import ConverterTemplate |
|
11 | from converters.template import ConverterTemplate | |
12 | from converters.html import ConverterHTML |
|
12 | from converters.html import ConverterHTML | |
13 | # From IPython |
|
13 | # From IPython | |
14 |
|
14 | |||
15 | # All the stuff needed for the configurable things |
|
15 | # All the stuff needed for the configurable things | |
16 | from IPython.config.application import Application |
|
16 | from IPython.config.application import Application | |
17 | from IPython.config.loader import ConfigFileNotFound |
|
17 | from IPython.config.loader import ConfigFileNotFound | |
18 | from IPython.utils.traitlets import List, Unicode, Type, Bool, Dict, CaselessStrEnum |
|
18 | from IPython.utils.traitlets import List, Unicode, Type, Bool, Dict, CaselessStrEnum | |
19 |
|
19 | |||
|
20 | from converters.transformers import (ConfigurableTransformers,Foobar,ExtractFigureTransformer) | |||
|
21 | ||||
20 |
|
22 | |||
21 | class NbconvertApp(Application): |
|
23 | class NbconvertApp(Application): | |
22 |
|
24 | |||
23 |
|
25 | |||
24 | def __init__(self, **kwargs): |
|
26 | def __init__(self, **kwargs): | |
25 | super(NbconvertApp, self).__init__(**kwargs) |
|
27 | super(NbconvertApp, self).__init__(**kwargs) | |
26 | self.classes.insert(0,ConverterTemplate) |
|
28 | self.classes.insert(0,ConverterTemplate) | |
|
29 | # register class here to have help with help all | |||
|
30 | self.classes.insert(0,ExtractFigureTransformer) | |||
|
31 | self.classes.insert(0,Foobar) | |||
27 | # ensure those are registerd |
|
32 | # ensure those are registerd | |
28 |
|
33 | |||
29 | def load_config_file(self, profile_name): |
|
34 | def load_config_file(self, profile_name): | |
30 | try: |
|
35 | try: | |
31 | Application.load_config_file( |
|
36 | Application.load_config_file( | |
32 | self, |
|
37 | self, | |
33 | profile_name+'.nbcv', |
|
38 | profile_name+'.nbcv', | |
34 | path=[os.path.join(os.getcwdu(),'profile')] |
|
39 | path=[os.path.join(os.getcwdu(),'profile')] | |
35 | ) |
|
40 | ) | |
36 | except ConfigFileNotFound: |
|
41 | except ConfigFileNotFound: | |
37 | self.log.warn("Config file for profile '%s' not found, giving up ",profile_name) |
|
42 | self.log.warn("Config file for profile '%s' not found, giving up ",profile_name) | |
38 | exit(1) |
|
43 | exit(1) | |
39 |
|
44 | |||
40 |
|
45 | |||
41 | def initialize(self, argv=None): |
|
46 | def initialize(self, argv=None): | |
42 | self.parse_command_line(argv) |
|
47 | self.parse_command_line(argv) | |
43 | cl_config = self.config |
|
48 | cl_config = self.config | |
44 | profile_file = sys.argv[1] |
|
49 | profile_file = sys.argv[1] | |
45 | self.load_config_file(profile_file) |
|
50 | self.load_config_file(profile_file) | |
46 | self.update_config(cl_config) |
|
51 | self.update_config(cl_config) | |
47 |
|
52 | |||
48 |
|
53 | |||
49 |
|
54 | |||
50 | def run(self): |
|
55 | def run(self): | |
51 | """Convert a notebook to html in one step""" |
|
56 | """Convert a notebook to html in one step""" | |
52 | template_file = (self.extra_args or [None])[0] |
|
57 | template_file = (self.extra_args or [None])[0] | |
53 | ipynb_file = (self.extra_args or [None])[1] |
|
58 | ipynb_file = (self.extra_args or [None])[1] | |
54 |
|
59 | |||
55 | template_file = sys.argv[1] |
|
60 | template_file = sys.argv[1] | |
56 |
|
61 | |||
57 | if template_file.startswith('latex'): |
|
|||
58 | tex_environement=True |
|
|||
59 | else: |
|
|||
60 | tex_environement=False |
|
|||
61 |
|
||||
62 | C = ConverterTemplate(tplfile=sys.argv[1], |
|
62 | C = ConverterTemplate(tplfile=sys.argv[1], | |
63 | config=self.config) |
|
63 | config=self.config) | |
64 | C.read(ipynb_file) |
|
64 | C.read(ipynb_file) | |
65 |
|
65 | |||
66 | output,resources = C.convert() |
|
66 | output,resources = C.convert() | |
67 |
|
67 | |||
68 | print(output.encode('utf-8')) |
|
68 | print(output.encode('utf-8')) | |
69 |
|
69 | |||
70 | keys = resources.keys() |
|
70 | keys = resources.keys() | |
71 | if keys : |
|
71 | if keys : | |
72 | print(''' |
|
72 | print(''' | |
73 | ====================== Keys in Resources ================================== |
|
73 | ====================== Keys in Resources ================================== | |
74 | ''') |
|
74 | ''') | |
75 | print(resources.keys()) |
|
75 | print(resources.keys()) | |
76 | print(""" |
|
76 | print(""" | |
77 | =========================================================================== |
|
77 | =========================================================================== | |
78 | you are responsible from writing those data do a file in the right place if |
|
78 | you are responsible from writing those data do a file in the right place if | |
79 | they need to be. |
|
79 | they need to be. | |
80 | =========================================================================== |
|
80 | =========================================================================== | |
81 | """) |
|
81 | """) | |
82 |
|
82 | |||
83 | def main(): |
|
83 | def main(): | |
84 | """Convert a notebook to html in one step""" |
|
84 | """Convert a notebook to html in one step""" | |
85 | app = NbconvertApp.instance() |
|
85 | app = NbconvertApp.instance() | |
86 | app.initialize() |
|
86 | app.initialize() | |
87 | app.start() |
|
87 | app.start() | |
88 | app.run() |
|
88 | app.run() | |
89 | #----------------------------------------------------------------------------- |
|
89 | #----------------------------------------------------------------------------- | |
90 | # Script main |
|
90 | # Script main | |
91 | #----------------------------------------------------------------------------- |
|
91 | #----------------------------------------------------------------------------- | |
92 |
|
92 | |||
93 | if __name__ == '__main__': |
|
93 | if __name__ == '__main__': | |
94 | main() |
|
94 | main() |
@@ -1,207 +1,214 b'' | |||||
1 | ((*- extends 'display_priority.tplx' -*)) |
|
1 | ((*- extends 'display_priority.tplx' -*)) | |
2 |
|
2 | |||
3 | ((* block in_prompt *))((* endblock in_prompt *)) |
|
3 | ((* block in_prompt *))((* endblock in_prompt *)) | |
4 |
|
4 | |||
5 | ((* block output_prompt *))((* endblock output_prompt *)) |
|
5 | ((* block output_prompt *))((* endblock output_prompt *)) | |
6 |
|
6 | |||
7 | ((* block codecell *))\begin{codecell}((( super() ))) |
|
7 | ((* block codecell *))\begin{codecell}((( super() ))) | |
8 | \end{codecell} |
|
8 | \end{codecell} | |
9 | ((* endblock *)) |
|
9 | ((* endblock *)) | |
10 |
|
10 | |||
11 | ((* block input *)) |
|
11 | ((* block input *)) | |
12 | \begin{codeinput} |
|
12 | \begin{codeinput} | |
13 | \begin{lstlisting} |
|
13 | \begin{lstlisting} | |
14 | ((( cell.input ))) |
|
14 | ((( cell.input ))) | |
15 | \end{lstlisting} |
|
15 | \end{lstlisting} | |
16 | \end{codeinput} |
|
16 | \end{codeinput} | |
17 | ((* endblock input *)) |
|
17 | ((* endblock input *)) | |
18 |
|
18 | |||
19 |
|
19 | |||
20 | ((= Those Two are for error displaying |
|
20 | ((= Those Two are for error displaying | |
21 | even if the first one seem to do nothing, |
|
21 | even if the first one seem to do nothing, | |
22 | it introduces a new line |
|
22 | it introduces a new line | |
23 |
|
23 | |||
24 | =)) |
|
24 | =)) | |
25 | ((* block pyerr *))((( super() ))) |
|
25 | ((* block pyerr *))((( super() ))) | |
26 | ((* endblock pyerr *)) |
|
26 | ((* endblock pyerr *)) | |
27 |
|
27 | |||
28 | ((* block traceback_line *)) |
|
28 | ((* block traceback_line *)) | |
29 | ((( line |indent| rm_ansi )))((* endblock traceback_line *)) |
|
29 | ((( line |indent| rm_ansi )))((* endblock traceback_line *)) | |
30 | ((= .... =)) |
|
30 | ((= .... =)) | |
31 |
|
31 | |||
32 |
|
32 | |||
33 | ((*- block output_group -*)) |
|
33 | ((*- block output_group -*)) | |
34 | \begin{codeoutput} |
|
34 | \begin{codeoutput} | |
35 | ((( super() ))) |
|
35 | ((( super() ))) | |
36 | \end{codeoutput}((* endblock *)) |
|
36 | \end{codeoutput}((* endblock *)) | |
37 |
|
37 | |||
38 | ((*- block data_png -*)) |
|
38 | ((*- block data_png -*)) | |
39 | \begin{center} |
|
39 | \begin{center} | |
40 | \includegraphics[width=0.7\textwidth]{(((output.png)))} |
|
40 | \includegraphics[width=0.7\textwidth]{(((output.key_png)))} | |
|
41 | \par | |||
|
42 | \end{center} | |||
|
43 | ((*- endblock -*)) | |||
|
44 | ||||
|
45 | ((*- block data_svg -*)) | |||
|
46 | \begin{center} | |||
|
47 | \includegraphics[width=0.7\textwidth]{(((output.key_svg)))} | |||
41 | \par |
|
48 | \par | |
42 | \end{center} |
|
49 | \end{center} | |
43 | ((*- endblock -*)) |
|
50 | ((*- endblock -*)) | |
44 |
|
51 | |||
45 | ((* block pyout *)) |
|
52 | ((* block pyout *)) | |
46 | ((( output.text))) |
|
53 | ((( output.text))) | |
47 | ((* endblock pyout *)) |
|
54 | ((* endblock pyout *)) | |
48 |
|
55 | |||
49 | ((* block data_text *)) |
|
56 | ((* block data_text *)) | |
50 | \begin{verbatim} |
|
57 | \begin{verbatim} | |
51 | ((( output.text ))) |
|
58 | ((( output.text ))) | |
52 | \end{verbatim} |
|
59 | \end{verbatim} | |
53 | ((* endblock *)) |
|
60 | ((* endblock *)) | |
54 |
|
61 | |||
55 | ((* block stream *)) |
|
62 | ((* block stream *)) | |
56 | \begin{verbatim} |
|
63 | \begin{verbatim} | |
57 | ((( output.text))) |
|
64 | ((( output.text))) | |
58 | \end{verbatim} |
|
65 | \end{verbatim} | |
59 | ((* endblock stream *)) |
|
66 | ((* endblock stream *)) | |
60 |
|
67 | |||
61 |
|
68 | |||
62 |
|
69 | |||
63 |
|
70 | |||
64 | ((* block markdowncell scoped *))((( cell.source | markdown2latex ))) |
|
71 | ((* block markdowncell scoped *))((( cell.source | markdown2latex ))) | |
65 | ((* endblock markdowncell *)) |
|
72 | ((* endblock markdowncell *)) | |
66 |
|
73 | |||
67 | ((* block headingcell scoped *)) |
|
74 | ((* block headingcell scoped *)) | |
68 | \section{((( cell.source)))} |
|
75 | \section{((( cell.source)))} | |
69 | ((* endblock headingcell *)) |
|
76 | ((* endblock headingcell *)) | |
70 |
|
77 | |||
71 | ((* block rawcell scoped *)) |
|
78 | ((* block rawcell scoped *)) | |
72 | ((( cell.source | pycomment ))) |
|
79 | ((( cell.source | pycomment ))) | |
73 | ((* endblock rawcell *)) |
|
80 | ((* endblock rawcell *)) | |
74 |
|
81 | |||
75 | ((* block unknowncell scoped *)) |
|
82 | ((* block unknowncell scoped *)) | |
76 | unknown type (((cell.type))) |
|
83 | unknown type (((cell.type))) | |
77 | ((* endblock unknowncell *)) |
|
84 | ((* endblock unknowncell *)) | |
78 |
|
85 | |||
79 |
|
86 | |||
80 |
|
87 | |||
81 | ((* block body *))\begin{document} |
|
88 | ((* block body *))\begin{document} | |
82 | ((( super() ))) |
|
89 | ((( super() ))) | |
83 | \end{document} |
|
90 | \end{document} | |
84 | ((* endblock*)) |
|
91 | ((* endblock*)) | |
85 |
|
92 | |||
86 | ((* block header *)) |
|
93 | ((* block header *)) | |
87 | %% This file was auto-generated by IPython. |
|
94 | %% This file was auto-generated by IPython. | |
88 | %% Conversion from the original notebook file: |
|
95 | %% Conversion from the original notebook file: | |
89 | %% tests/ipynbref/Gun_Data.orig.ipynb |
|
96 | %% tests/ipynbref/Gun_Data.orig.ipynb | |
90 | %% |
|
97 | %% | |
91 | \documentclass[11pt,english]{article} |
|
98 | \documentclass[11pt,english]{article} | |
92 |
|
99 | |||
93 | %% This is the automatic preamble used by IPython. Note that it does *not* |
|
100 | %% This is the automatic preamble used by IPython. Note that it does *not* | |
94 | %% include a documentclass declaration, that is added at runtime to the overall |
|
101 | %% include a documentclass declaration, that is added at runtime to the overall | |
95 | %% document. |
|
102 | %% document. | |
96 |
|
103 | |||
97 | \usepackage{amsmath} |
|
104 | \usepackage{amsmath} | |
98 | \usepackage{amssymb} |
|
105 | \usepackage{amssymb} | |
99 | \usepackage{graphicx} |
|
106 | \usepackage{graphicx} | |
100 | \usepackage{ucs} |
|
107 | \usepackage{ucs} | |
101 | \usepackage[utf8x]{inputenc} |
|
108 | \usepackage[utf8x]{inputenc} | |
102 |
|
109 | |||
103 | % needed for markdown enumerations to work |
|
110 | % needed for markdown enumerations to work | |
104 | \usepackage{enumerate} |
|
111 | \usepackage{enumerate} | |
105 |
|
112 | |||
106 | % Slightly bigger margins than the latex defaults |
|
113 | % Slightly bigger margins than the latex defaults | |
107 | \usepackage{geometry} |
|
114 | \usepackage{geometry} | |
108 | \geometry{verbose,tmargin=3cm,bmargin=3cm,lmargin=2.5cm,rmargin=2.5cm} |
|
115 | \geometry{verbose,tmargin=3cm,bmargin=3cm,lmargin=2.5cm,rmargin=2.5cm} | |
109 |
|
116 | |||
110 | % Define a few colors for use in code, links and cell shading |
|
117 | % Define a few colors for use in code, links and cell shading | |
111 | \usepackage{color} |
|
118 | \usepackage{color} | |
112 | \definecolor{orange}{cmyk}{0,0.4,0.8,0.2} |
|
119 | \definecolor{orange}{cmyk}{0,0.4,0.8,0.2} | |
113 | \definecolor{darkorange}{rgb}{.71,0.21,0.01} |
|
120 | \definecolor{darkorange}{rgb}{.71,0.21,0.01} | |
114 | \definecolor{darkgreen}{rgb}{.12,.54,.11} |
|
121 | \definecolor{darkgreen}{rgb}{.12,.54,.11} | |
115 | \definecolor{myteal}{rgb}{.26, .44, .56} |
|
122 | \definecolor{myteal}{rgb}{.26, .44, .56} | |
116 | \definecolor{gray}{gray}{0.45} |
|
123 | \definecolor{gray}{gray}{0.45} | |
117 | \definecolor{lightgray}{gray}{.95} |
|
124 | \definecolor{lightgray}{gray}{.95} | |
118 | \definecolor{mediumgray}{gray}{.8} |
|
125 | \definecolor{mediumgray}{gray}{.8} | |
119 | \definecolor{inputbackground}{rgb}{.95, .95, .85} |
|
126 | \definecolor{inputbackground}{rgb}{.95, .95, .85} | |
120 | \definecolor{outputbackground}{rgb}{.95, .95, .95} |
|
127 | \definecolor{outputbackground}{rgb}{.95, .95, .95} | |
121 | \definecolor{traceback}{rgb}{1, .95, .95} |
|
128 | \definecolor{traceback}{rgb}{1, .95, .95} | |
122 |
|
129 | |||
123 | % Framed environments for code cells (inputs, outputs, errors, ...). The |
|
130 | % Framed environments for code cells (inputs, outputs, errors, ...). The | |
124 | % various uses of \unskip (or not) at the end were fine-tuned by hand, so don't |
|
131 | % various uses of \unskip (or not) at the end were fine-tuned by hand, so don't | |
125 | % randomly change them unless you're sure of the effect it will have. |
|
132 | % randomly change them unless you're sure of the effect it will have. | |
126 | \usepackage{framed} |
|
133 | \usepackage{framed} | |
127 |
|
134 | |||
128 | % remove extraneous vertical space in boxes |
|
135 | % remove extraneous vertical space in boxes | |
129 | \setlength\fboxsep{0pt} |
|
136 | \setlength\fboxsep{0pt} | |
130 |
|
137 | |||
131 | % codecell is the whole input+output set of blocks that a Code cell can |
|
138 | % codecell is the whole input+output set of blocks that a Code cell can | |
132 | % generate. |
|
139 | % generate. | |
133 |
|
140 | |||
134 | % TODO: unfortunately, it seems that using a framed codecell environment breaks |
|
141 | % TODO: unfortunately, it seems that using a framed codecell environment breaks | |
135 | % the ability of the frames inside of it to be broken across pages. This |
|
142 | % the ability of the frames inside of it to be broken across pages. This | |
136 | % causes at least the problem of having lots of empty space at the bottom of |
|
143 | % causes at least the problem of having lots of empty space at the bottom of | |
137 | % pages as new frames are moved to the next page, and if a single frame is too |
|
144 | % pages as new frames are moved to the next page, and if a single frame is too | |
138 | % long to fit on a page, will completely stop latex from compiling the |
|
145 | % long to fit on a page, will completely stop latex from compiling the | |
139 | % document. So unless we figure out a solution to this, we'll have to instead |
|
146 | % document. So unless we figure out a solution to this, we'll have to instead | |
140 | % leave the codecell env. as empty. I'm keeping the original codecell |
|
147 | % leave the codecell env. as empty. I'm keeping the original codecell | |
141 | % definition here (a thin vertical bar) for reference, in case we find a |
|
148 | % definition here (a thin vertical bar) for reference, in case we find a | |
142 | % solution to the page break issue. |
|
149 | % solution to the page break issue. | |
143 |
|
150 | |||
144 | %% \newenvironment{codecell}{% |
|
151 | %% \newenvironment{codecell}{% | |
145 | %% \def\FrameCommand{\color{mediumgray} \vrule width 1pt \hspace{5pt}}% |
|
152 | %% \def\FrameCommand{\color{mediumgray} \vrule width 1pt \hspace{5pt}}% | |
146 | %% \MakeFramed{\vspace{-0.5em}}} |
|
153 | %% \MakeFramed{\vspace{-0.5em}}} | |
147 | %% {\unskip\endMakeFramed} |
|
154 | %% {\unskip\endMakeFramed} | |
148 |
|
155 | |||
149 | % For now, make this a no-op... |
|
156 | % For now, make this a no-op... | |
150 | \newenvironment{codecell}{} |
|
157 | \newenvironment{codecell}{} | |
151 |
|
158 | |||
152 | \newenvironment{codeinput}{% |
|
159 | \newenvironment{codeinput}{% | |
153 | \def\FrameCommand{\colorbox{inputbackground}}% |
|
160 | \def\FrameCommand{\colorbox{inputbackground}}% | |
154 | \MakeFramed{\advance\hsize-\width \FrameRestore}} |
|
161 | \MakeFramed{\advance\hsize-\width \FrameRestore}} | |
155 | {\unskip\endMakeFramed} |
|
162 | {\unskip\endMakeFramed} | |
156 |
|
163 | |||
157 | \newenvironment{codeoutput}{% |
|
164 | \newenvironment{codeoutput}{% | |
158 | \def\FrameCommand{\colorbox{outputbackground}}% |
|
165 | \def\FrameCommand{\colorbox{outputbackground}}% | |
159 | \vspace{-1.4em} |
|
166 | \vspace{-1.4em} | |
160 | \MakeFramed{\advance\hsize-\width \FrameRestore}} |
|
167 | \MakeFramed{\advance\hsize-\width \FrameRestore}} | |
161 | {\unskip\medskip\endMakeFramed} |
|
168 | {\unskip\medskip\endMakeFramed} | |
162 |
|
169 | |||
163 | \newenvironment{traceback}{% |
|
170 | \newenvironment{traceback}{% | |
164 | \def\FrameCommand{\colorbox{traceback}}% |
|
171 | \def\FrameCommand{\colorbox{traceback}}% | |
165 | \MakeFramed{\advance\hsize-\width \FrameRestore}} |
|
172 | \MakeFramed{\advance\hsize-\width \FrameRestore}} | |
166 | {\endMakeFramed} |
|
173 | {\endMakeFramed} | |
167 |
|
174 | |||
168 | % Use and configure listings package for nicely formatted code |
|
175 | % Use and configure listings package for nicely formatted code | |
169 | \usepackage{listingsutf8} |
|
176 | \usepackage{listingsutf8} | |
170 | \lstset{ |
|
177 | \lstset{ | |
171 | language=python, |
|
178 | language=python, | |
172 | inputencoding=utf8x, |
|
179 | inputencoding=utf8x, | |
173 | extendedchars=\true, |
|
180 | extendedchars=\true, | |
174 | aboveskip=\smallskipamount, |
|
181 | aboveskip=\smallskipamount, | |
175 | belowskip=\smallskipamount, |
|
182 | belowskip=\smallskipamount, | |
176 | xleftmargin=2mm, |
|
183 | xleftmargin=2mm, | |
177 | breaklines=true, |
|
184 | breaklines=true, | |
178 | basicstyle=\small \ttfamily, |
|
185 | basicstyle=\small \ttfamily, | |
179 | showstringspaces=false, |
|
186 | showstringspaces=false, | |
180 | keywordstyle=\color{blue}\bfseries, |
|
187 | keywordstyle=\color{blue}\bfseries, | |
181 | commentstyle=\color{myteal}, |
|
188 | commentstyle=\color{myteal}, | |
182 | stringstyle=\color{darkgreen}, |
|
189 | stringstyle=\color{darkgreen}, | |
183 | identifierstyle=\color{darkorange}, |
|
190 | identifierstyle=\color{darkorange}, | |
184 | columns=fullflexible, % tighter character kerning, like verb |
|
191 | columns=fullflexible, % tighter character kerning, like verb | |
185 | } |
|
192 | } | |
186 |
|
193 | |||
187 | % The hyperref package gives us a pdf with properly built |
|
194 | % The hyperref package gives us a pdf with properly built | |
188 | % internal navigation ('pdf bookmarks' for the table of contents, |
|
195 | % internal navigation ('pdf bookmarks' for the table of contents, | |
189 | % internal cross-reference links, web links for URLs, etc.) |
|
196 | % internal cross-reference links, web links for URLs, etc.) | |
190 | \usepackage{hyperref} |
|
197 | \usepackage{hyperref} | |
191 | \hypersetup{ |
|
198 | \hypersetup{ | |
192 | breaklinks=true, % so long urls are correctly broken across lines |
|
199 | breaklinks=true, % so long urls are correctly broken across lines | |
193 | colorlinks=true, |
|
200 | colorlinks=true, | |
194 | urlcolor=blue, |
|
201 | urlcolor=blue, | |
195 | linkcolor=darkorange, |
|
202 | linkcolor=darkorange, | |
196 | citecolor=darkgreen, |
|
203 | citecolor=darkgreen, | |
197 | } |
|
204 | } | |
198 |
|
205 | |||
199 | % hardcode size of all verbatim environments to be a bit smaller |
|
206 | % hardcode size of all verbatim environments to be a bit smaller | |
200 | \makeatletter |
|
207 | \makeatletter | |
201 | \g@addto@macro\@verbatim\small\topsep=0.5em\partopsep=0pt |
|
208 | \g@addto@macro\@verbatim\small\topsep=0.5em\partopsep=0pt | |
202 | \makeatother |
|
209 | \makeatother | |
203 |
|
210 | |||
204 | % Prevent overflowing lines due to urls and other hard-to-break entities. |
|
211 | % Prevent overflowing lines due to urls and other hard-to-break entities. | |
205 | \sloppy |
|
212 | \sloppy | |
206 |
|
213 | |||
207 | ((* endblock *)) |
|
214 | ((* endblock *)) |
General Comments 0
You need to be logged in to leave comments.
Login now