I am starting to use Jinja for creating templates in latex. From what I saw, it is necessary to change the default jinja delimiters ({% and %}, for example) to avoid conflicts with delimiters used by latex. I have been given the following setup to use as starting point:
env = Environment(
loader=PackageLoader(pages_module, 'templates'),
autoescape=False,
block_start_string='<#',
block_end_string='#>',
variable_start_string='<<',
variable_end_string='>>',
comment_start_string='<%',
comment_end_string='%>',
)
The problem is that now my IDE complains that I can't "use macro parameter character # in horizontal mode" in the latex template files. Maybe it is a bit of a silly request, but I would like to get rid of these false errors that may obfuscate other problems my IDE could detect on the file. Looking at this alternative set of delimiters and considering the possibility to define new commands with comment-like behavior such as this, would there be any problems with defining the following environment for Jinja:
env = Environment(
loader=PackageLoader(pages_module, 'templates'),
autoescape=False,
block_start_string='\JBLOCK{',
block_end_string='}',
variable_start_string='\JVAR{',
variable_end_string='}',
comment_start_string='<%', # or whatever, I don't plan to use jinja comments
comment_end_string='%>',
)
And then using this in the latex template:
\newcommand{\JBLOCK}[1]{}
\newcommand{\JVAR}[1]{}
(...)
\JBLOCK{ block body }
\JBLOCK{ endblock body }
(...)
Do I risk getting some unexpected behavior or hard to pinpoint conflicts down the line by using something like that?
}as block closing character seems tricky because you also might need to use that character inside of the blocks (because it is a very common character in LaTeX) which would require some kind of escaping. Maybe using#>and trying to get your editor to stop producing that specific warning would be easier. – Marijn Feb 08 '22 at 20:06\JBLOCK{ <here> }? Or between\JBLOCK{block body}and\JBLOCK{endblock body}? Because in the second case it should be allright, no? Jinja is not going to try "close" a block indication that is not open (afaiu}does not signal the end of the block, but the end of a block marker). And I can't now imagine a case in which I would need to use a}inside of the block marker. Am I understanding this correctly? – Nordico Feb 09 '22 at 14:27for element in datatype of statements (which presumably is the case, also withifetc) then there should be no problem. – Marijn Feb 09 '22 at 15:38