diff --git a/converters/template.py b/converters/template.py index 2fa9b08..14d8ec4 100755 --- a/converters/template.py +++ b/converters/template.py @@ -207,6 +207,14 @@ class ConverterTemplate(Configurable): dictionnary """ ) + + tex_environement = Bool(False, + config=True, + help=""" is this a tex environment or not """) + + template_file = Unicode('', + config=True, + help=""" whetever """ ) #------------------------------------------------------------------------- # Instance-level attributes that are set in the constructor for this # class. @@ -221,7 +229,7 @@ class ConverterTemplate(Configurable): if fmt in output: return [fmt] - def __init__(self, tplfile='fullhtml', preprocessors=[], config=None,tex_environement=False, **kw): + def __init__(self, preprocessors=[], config=None, **kw): """ tplfile : jinja template file to process. @@ -232,8 +240,8 @@ class ConverterTemplate(Configurable): """ super(ConverterTemplate, self).__init__(config=config, **kw) - self.env = texenv if tex_environement else env - self.ext = '.tplx' if tex_environement else '.tpl' + self.env = texenv if self.tex_environement else env + self.ext = '.tplx' if self.tex_environement else '.tpl' self.nb = None self.preprocessors = preprocessors self.preprocessors.append(haspyout_transformer) @@ -250,7 +258,7 @@ class ConverterTemplate(Configurable): self.env.filters['ansi2html'] = ansi2html self.env.filters['markdown2latex'] = markdown2latex - self.template = self.env.get_template(tplfile+self.ext) + self.template = self.env.get_template(self.template_file+self.ext) diff --git a/profile/full_html.nbcv b/profile/full_html.nbcv new file mode 100644 index 0000000..fce99c9 --- /dev/null +++ b/profile/full_html.nbcv @@ -0,0 +1,5 @@ +c = get_config() + +c.ConverterTemplate.extract_figures=False +c.ConverterTemplate.template_file='fullhtml' +c.ConverterTemplate.tex_environement=False diff --git a/profile/latex_base.nbcv b/profile/latex_base.nbcv new file mode 100644 index 0000000..8a16e9c --- /dev/null +++ b/profile/latex_base.nbcv @@ -0,0 +1,5 @@ +c = get_config() + +c.ConverterTemplate.extract_figures=False +c.ConverterTemplate.template_file='latex_base' +c.ConverterTemplate.tex_environement=True diff --git a/runme.py b/runme.py index b10908a..e7e1d32 100755 --- a/runme.py +++ b/runme.py @@ -5,6 +5,7 @@ from __future__ import print_function import sys import io +import os from converters.template import * from converters.template import ConverterTemplate @@ -13,6 +14,7 @@ from converters.html import ConverterHTML # All the stuff needed for the configurable things from IPython.config.application import Application +from IPython.config.loader import ConfigFileNotFound from IPython.utils.traitlets import List, Unicode, Type, Bool, Dict, CaselessStrEnum @@ -24,10 +26,23 @@ class NbconvertApp(Application): self.classes.insert(0,ConverterTemplate) # ensure those are registerd + def load_config_file(self, profile_name): + try: + Application.load_config_file( + self, + profile_name+'.nbcv', + path=[os.path.join(os.getcwdu(),'profile')] + ) + except ConfigFileNotFound: + self.log.warn("Config file for profile '%s' not found, giving up ",profile_name) + exit(1) + def initialize(self, argv=None): self.parse_command_line(argv) cl_config = self.config + profile_file = sys.argv[1] + self.load_config_file(profile_file) self.update_config(cl_config) @@ -45,7 +60,6 @@ class NbconvertApp(Application): tex_environement=False C = ConverterTemplate(tplfile=sys.argv[1], - tex_environement=tex_environement, config=self.config) C.read(ipynb_file)