Jinja2 templates overwriting comment markup

Hey folks,

I am using PyCharm Prof with the TeXiFy plugin to write my LaTeX documents.

I started to use Jinja2 Templates to generate some tables automatically from data sources. If I specify LaTeX-source file type in Languages & Frameworks > Template Languages, the templates are successfully recognized. However, not only in documents containing template markups, but also in all plain TeX documents, PyCharm is now starting to use Jinja style comments when I press the line and block comment shortcuts instead of TeX style comments.

Is there any way to make PyCharm to recognize only the files I want to be templates and leave the others as is, eg by using a template directory? The TeX documents should further be recognized as LaTeX-source file type to enable syntax highlighting and checks provided by TeXiFy.

4 comments
Comment actions Permalink

Hi, 

The TeX documents should further be recognized as LaTeX-source file type to enable syntax highlighting and checks provided by TeXiFy.

PyCharm should do this already, does it not happen for you? Do you loose the ability to autocomplete LaTex-specific syntax when this file type is template-enabled?
If so, could you please check if you get the same issue in, say, HTML? As mentioned, PyCharm should add the Jinja2-specific features to the file, but also retain it's original completion features. Also, please provide some example of the completion that stops working in a LaTeX file.
0
Comment actions Permalink

Maybe my text was a bit confused...
Syntax highlight and completion is working for TeX and Jinja if I add TeX-Files to template list.
But when I press the shortcuts for commenting, PyCharm uses {# #} (Jinja style comments) instead of % (TeX style).
In template files this is correct, but not in plain TeX files. However, I have a mixture of template TeX files and plain ones in my project (so templates for some tables, which are generated by a Python script at compile time, and regular files for the text itself).

So I need a way to tell PyCharm which are plain files and template ones.

My tries were:
- If I remove TeX files from the template list and rename my files as *.tex.jinja2, then PyCharm only activates Jinja support. If I add additionally "*.tex.*" pattern to LaTeX-Source file type, it activates TeX support but not Jinja2. So this was no solution.
- Marking my templates folder as templates folder (purple icon). No effect at all.

If there is no way yet, maybe it is possible to include extra patterns in the template list, not only relying on file types.
Or maybe the could be some file type inheritance, so that one can define a derived file type, which inherits all syntax recognition but can have its own name patterns. So one could derive a "LaTeX-source template" file type with pattern "*.tex.jinja" or something out of "LaTeX-source" with "*.tex" to make them distinguishable in the template list.

0
Comment actions Permalink

Unfortunately there's no way to tell PyCharm it should treat some files of the same extension as templates. If I understood correctly, your only issue is with the comments? If so, I would suggest to submit a usability issue to https://youtrack.jetbrains.com with detailed description of your use case. I can't think of a workaround at the moment, sorry.

 

0
Comment actions Permalink

Thanks however. I will do that.

0

Please sign in to leave a comment.