The Django-Tex Syntax Highlighting extension (vscode-django-tex
) is a simple VSCode extension for syntax highlighting in django-tex
(.tex
) templates. The extension is based on another extension called Django, which does the same for .txt
and .html
templates, so credits to @batisteo for that.
You can install this extension directly from the Extension Marketplace in VSCode. You can also launch VS Code Quick Open (Ctrl+P
), paste the following command, and press enter:
ext install bfrangi.vscode-django-tex
-
Syntax Highlighting in
django-tex
(.tex
) templates:Rest of the example code
Template code:
\documentclass{article} \begin{document} \begin{center} \section*{Table for {{date|date}} } \begin{tabular}{ {% for _ in table.body.rows.0 %}|c{% endfor %}| } {# This is a comment #} \hline % This is another comment \multicolumn{ {{table.headers.first.span}} }{|c|}{ {{table.headers.first.value}} } & \multicolumn{ {{table.headers.second.span}} }{c|}{ {{table.headers.second.value}} } \\ \hline \iffalse This is a comment spanning several lines \hline \fi {% for row in table.body.rows %} {% for cell in row %}{% if not cell == row.0 %} & {% endif %} cell{{cell}} {% endfor %} \\ {% endfor %} {% comment %} This is another comment spanning several lines \hline {% endcomment %} \hline \end{tabular} \end{center} \end{document}
We could combine the code from the
django-tex
template with the following function based view to render the LaTeX document:from django_tex.shortcuts import render_to_pdf from datetime import date def render_pdf(request): table = { 'headers': { 'first': { 'span': 3, 'value': 'First Multicol', }, 'second': { 'span': 3, 'value': 'Second Multicol', }, }, 'body': { 'rows': [ [i for i in range(6)], [i for i in range(6)], [i for i in range(6)], [i for i in range(6)], [i for i in range(6)], ] }, } filename = 'filename.pdf' template_name = 'path/to/template_name.pdf' context = { 'date': date.today(), 'table': table, } return render_to_pdf( request, template_name, context, filename, )
This would produce:
Visit the CHANGELOG.md
here.
Enjoy!