Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Thanks for your work #39

Closed
pcav opened this issue Jan 11, 2019 · 6 comments
Closed

Thanks for your work #39

pcav opened this issue Jan 11, 2019 · 6 comments

Comments

@pcav
Copy link

pcav commented Jan 11, 2019

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
Copy link
Owner

@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
Copy link
Author

pcav commented Jan 11, 2019

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
Copy link

ghtmtt commented Jan 14, 2019

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
Copy link
Owner

gmazzamuto commented Jan 15, 2019

@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
Copy link

ghtmtt commented Jan 16, 2019

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
Copy link
Author

pcav commented Jan 16, 2019

Thanks @gmazzamuto !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants