user2326871 user2326871 - 1 month ago 7x
LaTeX Question

How to execute a Golang template when "{" or "}" are in the static part of the template?

My Problem is that, I want to build a letter generator, which first builds a latex-file from user input, and then compiles this via latex to PDF.

The template contains multiple lines like this:


part is
, and the
part from go is

When I try to load the template, it throws this error:

panic: template: letter.tmpl:72: unexpected "}" in command

Is there a trick to help the parser handling such a situation?

Thanks in advance,



Use Template.Delims to set the delimiters to some non conflicting text. {{ and }} are just the default values, this method allows to select other delimiters.

Alternative method: In you template, where you want latex's { and }, you can insert some safe text instead, like say #( and )# and then make a "global" replacement on the output from the template. Yet setting delimiters is far easier IMO and quite probably more performant, if that matters.