You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@groovy.apache.org by paul <pl...@gmail.com> on 2019/01/17 12:36:57 UTC

How to handle LaTeX templates without \\-escaping?

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/

Re: How to handle LaTeX templates without \\-escaping?

Posted by "Daniel.Sun" <su...@apache.org>.
FYI, you can enable escaping backlash by the following code

def ste = new SimpleTemplateEngine()
ste.setEscapeBackslash(true)

I encountered the same issue and fixed the issue in groovy 2.5+ some months
ago.

Cheers,
Daniel.Sun





-----
Apache Groovy committer 
Blog: http://blog.sunlan.me 
Twitter: @daniel_sun 

--
Sent from: http://groovy.329449.n5.nabble.com/Groovy-Users-f329450.html

Re: How to handle LaTeX templates without \\-escaping?

Posted by "Daniel.Sun" <su...@apache.org>.
> this was exactly what I wanted!
Glad to know it works.
BTW, in order to keep back compatibility, we did not change the default
behavior of the SimpleTemplateEngine.

> Out of curiosity, I suppose it's not easily possible to change the
> MarkupTemplateEngine's tags from xml-style's <x>...</x> to something else?
I have not looked into its implementation, so I have no idea...

Cheers,
Daniel.Sun




-----
Apache Groovy committer 
Blog: http://blog.sunlan.me 
Twitter: @daniel_sun 

--
Sent from: http://groovy.329449.n5.nabble.com/Groovy-Users-f329450.html

Re: How to handle LaTeX templates without \\-escaping?

Posted by paul <pl...@gmail.com>.
Thanks Daniel,

Am 17.01.19 um 16:10 schrieb Daniel.Sun:
> FYI, you can enable escaping backslash by the following code
> 
> def ste = new SimpleTemplateEngine()
> ste.setEscapeBackslash(true)
this was exactly what I wanted!

Out of curiosity, I suppose it's not easily possible to change the 
MarkupTemplateEngine's tags from xml-style's <x>...</x> to something else?

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

http://neo-layout.org/

Re: How to handle LaTeX templates without \\-escaping?

Posted by "Daniel.Sun" <su...@apache.org>.
FYI, you can enable escaping backlash by the following code

def ste = new SimpleTemplateEngine()
ste.setEscapeBackslash(true)

I encountered the same issue and fixed the issue in groovy 2.5+ some months
ago.

Cheers,
Daniel.Sun



-----
Apache Groovy committer 
Blog: http://blog.sunlan.me 
Twitter: @daniel_sun 

--
Sent from: http://groovy.329449.n5.nabble.com/Groovy-Users-f329450.html