groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From paul <pl.grue...@gmail.com>
Subject How to handle LaTeX templates without \\-escaping?
Date Thu, 17 Jan 2019 12:36:57 GMT
Hi all,

I need to generate custom invoice pdfs from user data. Parsing the xml 
with Groovy is no problem; next step would be to generate a .tex file 
for every invoice (which will then be compiled to pdfs by `latexmk` and 
sent by email). Because the invoice generation logic is not trivial, a 
simple variable search-&-replace won't do, I need loops and ifs.
Groovy's (Simple)TemplateEngine is great – except I'd have to \\-Escape 
every backslash in the LaTeX template. Any idea how to avoid this? Some 
possible solutions I've come up with:

1) \\-escape in template-parts ( <%...%> or ${...} ) only would be ok, 
but not in everywhere in .tex file! Any way to do this?

2) possibility to change escape-character from \ to something else?

3) do a template.replace('\\','\\\\') beforehand. Anything that can go 
wrong there? I couldn't use a '\n' in the templates, but I guess that's 
not neccessary anyway.

4) (ab)use the MarkupTemplateEngine. At least the documentation states 
it's possible to "generate all sorts of text, not only XML/HTML". Is it 
possible to change the generated tags from <x>...</x> to 
\begin{x}...\end{x} ?

5) If there is another templating engine better suited for the task, I'd 
like to know! A quick search yielded eg. Apache Velocity, Apache 
Freemarker or StringTemplate, but I don't have the time to test each of 
them.
Lastly, I'm not required to use Groovy (but I'd very much like to)... if 
I'm better off using eg. Python I'm ok with it (a internet search for 
"groovy+latex" has nearly no matches).

Thanks in advance
Paul
-- 
typed with Neo 2 -- an ergonomically optimized keyboard layout
for German, English, programming, and science

http://neo-layout.org/

Mime
View raw message