From 974187a32c4b5d5cc83ad21139d638c4e2438c38 Mon Sep 17 00:00:00 2001 From: Sina Atalay Date: Mon, 20 Nov 2023 20:11:08 +0100 Subject: [PATCH] add text alignment options --- rendercv/data_model.py | 6 ++++++ rendercv/rendering.py | 15 +++++++++------ rendercv/templates/classic/classic.tex.j2 | 15 ++++++++++++--- .../templates/classic/components/entry.tex.j2 | 2 +- 4 files changed, 28 insertions(+), 10 deletions(-) diff --git a/rendercv/data_model.py b/rendercv/data_model.py index ae3a110..3836d60 100644 --- a/rendercv/data_model.py +++ b/rendercv/data_model.py @@ -468,6 +468,12 @@ class ClassicThemeOptions(BaseModel): description="The width of the date and location column.", ) + text_alignment: Literal["left-aligned", "justified"] = Field( + default="left-aligned", + title="Text Alignment", + description="The alignment of the text.", + ) + show_timespan_in: list[str] = Field( default=[], title="Show Time Span in These Sections", diff --git a/rendercv/rendering.py b/rendercv/rendering.py index 454c339..1bd0cea 100644 --- a/rendercv/rendering.py +++ b/rendercv/rendering.py @@ -11,7 +11,7 @@ from typing import Optional import sys from importlib.resources import files -from .data_model import RenderCVDataModel +from .data_model import RenderCVDataModel, CurriculumVitae, Design, ClassicThemeOptions from jinja2 import Environment, PackageLoader @@ -341,10 +341,13 @@ def render_template(data: RenderCVDataModel, output_path: Optional[str] = None) # load the template: template = environment.get_template(f"{theme}.tex.j2") + cv: CurriculumVitae = data.cv + design: Design = data.design + theme_options: ClassicThemeOptions = data.design.options output_latex_file = template.render( - cv=data.cv, - design=data.design, - theme_options=data.design.options, + cv=cv, + design=design, + theme_options=theme_options, today=get_today(), ) @@ -473,8 +476,8 @@ def run_latex(latex_file_path: str) -> str: ) run() - run() # run twice for cross-references - + run() # run twice for cross-references + # check if the PDF file is generated: if not os.path.exists(output_file_path): raise FileNotFoundError( diff --git a/rendercv/templates/classic/classic.tex.j2 b/rendercv/templates/classic/classic.tex.j2 index d092986..25fddda 100644 --- a/rendercv/templates/classic/classic.tex.j2 +++ b/rendercv/templates/classic/classic.tex.j2 @@ -84,11 +84,16 @@ \newcolumntype{R}[1]{ >{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}p{#1} } % right-aligned fixed width column type +((* if theme_options.text_alignment == "justified" *)) \newcolumntype{K}[1]{ >{\let\newline\\\arraybackslash\hspace{0pt}}X -} % left-aligned (but justified) flexible width column type +} % justified flexible width column type +((* elif theme_options.text_alignment == "left-aligned" *)) +\newcolumntype{K}[1]{ + >{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}X +} % left-aligned flexible width column type +((* endif *)) \setlength\tabcolsep{-1.5pt} % no space between columns - \newenvironment{highlights}{ \begin{itemize}[ topsep=0pt, @@ -132,7 +137,10 @@ <> ((* if cv.summary is not none *)) \section{Summary} - + { + ((* if theme_options.text_alignment == "left-aligned" *)) + \raggedright + ((* endif *)) \setlength{\leftskip}{<>} \setlength{\rightskip}{<>} @@ -140,6 +148,7 @@ \setlength{\leftskip}{0cm} \setlength{\rightskip}{0cm} + } ((* endif *)) \centering diff --git a/rendercv/templates/classic/components/entry.tex.j2 b/rendercv/templates/classic/components/entry.tex.j2 index defea7d..1b5743c 100644 --- a/rendercv/templates/classic/components/entry.tex.j2 +++ b/rendercv/templates/classic/components/entry.tex.j2 @@ -94,7 +94,7 @@ ((* endmacro *)) ((* macro one_line(name, details, markdown_url=none, link_text=none) *)) - \begingroup\raggedright + \begingroup((* if theme_options.text_alignment == "left-aligned" *))\raggedright((* endif *)) \leftskip=<> \advance\csname @rightskip\endcsname <> \advance\rightskip <>