Templating lib with changeable delimiters?

I've looked around on crates.io as well as lib.rs to no avail, so before I start handrolling something, I figured I'd ask around :slight_smile:

I want to produce latex documents from templates. As far as I can tell, the usual choice of delimiters ({{ for expressions) does not work due to latex's excessive usage of { characters. I found this guide on how to do it with jinja2, but I'd rather not stay with python for this and use rust. This poses a challenge, since all templating engines seem to 1) have fixed delimiters or 2) require templates at compile time or 3) both of them.

Did I miss any good ones? The logic I need is rather simple, so I might just handroll something along the lines of "read the full file and do regexp substitution".... but I'd still be grateful for any hints. Maybe I missed something obvious to do here instead? Thanks for any non-null pointers :slight_smile:

I'm curious what you need runtime templates for? I've always thought of compile time templates as inherently better for any just case I've encountered.

I might rethink the process, but what I'm doing is writing a program for my wife to generate testimonies for schoolchildren (she's a teacher... not sure if "testimonies" is the right word, that printout pupils get with their grades when the year is done). The idea is that the user chooses a template, and a data file (which the user has to edit properly before), and the program processes the template and runs the result through pdflatex to generate the final document. Compile time templates mean that every time something changes I have to recompile and redistribute, which seems like a huge hassle if someone other than my wife wants to use it.

Nice project! We call those "report cards" in the U.S., I suspect they've got other names in other countries.

It seems like a decent reason for a runtime template, but I'd be concerned with the difficulty of debugging templates for your user base. Latex doesn't give great error messages, and if your template system gives poor error messages it could be a real pain for your users, assuming they're not fluent in latex. So if you'll be creating the templates for your wife, is consider using static templates, which does simplify the distribution story, even though it would be less flexible.

That said, you might want a very simple template engine, which could have simple errors and might be easy to code yourself, as you say.

an alternative can be to use markdown (with templates) and convert it with pandoc to latex or pdf


That's the road I'm going for right now indeed. I thought a bit about it, and the templates shouldn't be edited by users anyways, so it might jus work out. Askama works nicely for now. Thanks!

The layout is quite involved an needs a lot of direct control, so I think markdown isn't a good fit here. Thanks anyways!