gmazzamuto / europasscv

Unofficial LaTeX class for the new version of the Europass curriculum vitae
116 stars 37 forks source link

Thanks for your work #39

Closed pcav closed 5 years ago

pcav commented 5 years ago

I know I'm abusing this bugtracker, but we just want to thank you for your template, that we are using with success for our website https://www.faunalia.eu/ through our scripts https://gitlab.com/faunalia/cv_pg_generator Thanks!

gmazzamuto commented 5 years ago

@pcav excellent, very interesting company! I am glad that you find the template useful. A new release will be out in a few days, featuring support for bibliography... you might find that useful too. I have taken a look at your code, and I think it can be improved. You should consider using Jinja2 which is a template engine for Python, rather than generating the .tex file one line at a time using write().

Best!

pcav commented 5 years ago

Thanks a lot. Yes, we're sure it can be improved in several respects. We'll try to grneralize it. Thanks for the suggestion.

ghtmtt commented 5 years ago

Hi @gmazzamuto we are working on other improvements (e.g. DB template). What would be your suggestions to use Jinja to improve the code? Do you have some examples?

gmazzamuto commented 5 years ago

@ghtmtt Here is a minimal example. With Jinja2 you can do something like this:

Template file template_cv.tex:

\documentclass[english,a4paper]{europasscv}
\usepackage[english]{babel}

\ecvname{\PYVAR{pi.name}}
\ecvaddress{\PYVAR{pi.address}}

\begin{document}
  Hello, my name is \PYVAR{pi.name} and this is my CV:

  \begin{europasscv}

  \ecvpersonalinfo

  \end{europasscv}

\end{document}

Python script to render the template:

from jinja2.nativetypes import NativeEnvironment, Environment
from jinja2.loaders import FileSystemLoader

env = Environment(
    loader=FileSystemLoader('.'),
    variable_start_string='\PYVAR{',
    variable_end_string='}',
)

template = env.get_template('template_cv.tex')

# Python variable to hold personal information
pi = {
    'name': 'Katie Smith',
    'address': '12 Strawberry Hill, Dublin 8 Éire/Ireland',
}

template.stream(pi=pi).dump('output.tex')  # render template to file

# or, equivalently, if on needs the rendered template in a Python variable
rendered = template.render(pi=pi)

with open('output2.tex', 'w') as f:
    f.write(rendered)

Note that with Jinja2 the default variable syntax in the template is {{ pi.name }}, but I have changed it to be \PYVAR{pi.name} to avoid parsing errors due to the many braces { and } that are used in LaTeX.

ghtmtt commented 5 years ago

Many thanks @gmazzamuto for the code snippet. From what I see you are defining a template but I'll still looping some dictionary values (as it is for now in my script). So the main difference is in using f.write once in your example and many times in my example..

pcav commented 5 years ago

Thanks @gmazzamuto !