Consider using a template engine, such as Jinja2 with Python.
You can change the default syntax {%, {{etc.) to make it more compatible with LaTeX. For example:
env = jinja2.Environment( loader=jinja2.FileSystemLoader( JINJA_DIRS ), comment_start_string='["', # don't conflict with eg {#1 comment_end_string = '"]', block_start_string = '[%', block_end_string = '%]', variable_start_string = '[=', variable_end_string = ']', autoescape=True, finalize=_jinja2_finalize_callback, # make a function that escapes TeX ) template = env.get_template( self.template ) tex = template.render( content )
In addition to the functions that are passed to the template environment, Jinja2 supports macros . For example, your above code should work as expected, like:
[% macro blah(egg, spam) -%] foo [=egg] \to [=spam] bar [%- endmacro %] [= blah("chicken","pork") ] % substitutes with "foo chicken \to pork"
I'm not sure what your goals are, and it does take a little work, but it is not an insurmountable problem if you are familiar with Python.
I hope this helps.
Brian M. hunt
source share