At first I had the same idea, so I digged into Genshi and tried a lot but without luck.
Unfortunately it’s harder because of the translation system. When you want to update the translations Tryton will also read all the reports and tries to get the strings which can be translated.
After spending some hours to get LaTeX working with Genshi and failed, I decided to move to Jinja.
Why is Jinja more suitable:
- Loading the LaTeX template into memory Python or Genshi is automatically escaping the different special characters. Jinja has the possibility to disable escaping (no idea how they do it, but it works flawlessly).
- Writing the generated document to a LaTeX file Python or Genshi is again escaping and removing special characters. From characters like
//
or//*
the first/
is removed which causes an error when the file is processed. Because of the disabled escaping Jinja outputs a perfect LaTeX file - With Jinja you can change the default strings for variables, blocks etc. This makes it possible to have kind of the same syntax for LaTeX. I know not much of a ‘more suitable’ but I want to mention it.
- Because LaTeX templates are plain text, Genshi doesn’t know which text is translatable. Jinja has an i18n extension which makes it possible to enclose your strings which should be translated. This makes is easier for the user, but also keeps the translation a bit more clean because characters like
#
,:
or&
can be left outside the enclosing and out of the translation. - very simple
escape
filter for the dynamic data which can be called by the user.
For me, loading the template and outputting it into a faultless LaTeX file was the biggest issue. By moving to Jinja this was working right out of the box. Also the possibility to change the start and endstrings of the different blocks and variables made the template more readable. In the end translation setup was very easy.
I’ve looked into that as well, but walked into the same problem with escaping.
My code including comments and empty lines is now around 200 lines. This includes:
- adding MIME type
- adding LaTeX to the selection in the UI
- own translate factory (unfortunately needed because Jinja wants
gettext
andngettext
functions) - extend the
TranslationSet
wizard to get the translatable strings - report mixin to escape data, render and convert the template into a document
I have to clean up things and make parts more configurable before I release it so it can be tested.