add text alignment options

This commit is contained in:
Sina Atalay 2023-11-20 20:11:08 +01:00
parent 4fb871fb8d
commit 9afec3ba3b
4 changed files with 28 additions and 10 deletions

View File

@ -468,6 +468,12 @@ class ClassicThemeOptions(BaseModel):
description="The width of the date and location column.", 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( show_timespan_in: list[str] = Field(
default=[], default=[],
title="Show Time Span in These Sections", title="Show Time Span in These Sections",

View File

@ -11,7 +11,7 @@ from typing import Optional
import sys import sys
from importlib.resources import files from importlib.resources import files
from .data_model import RenderCVDataModel from .data_model import RenderCVDataModel, CurriculumVitae, Design, ClassicThemeOptions
from jinja2 import Environment, PackageLoader from jinja2 import Environment, PackageLoader
@ -341,10 +341,13 @@ def render_template(data: RenderCVDataModel, output_path: Optional[str] = None)
# load the template: # load the template:
template = environment.get_template(f"{theme}.tex.j2") 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( output_latex_file = template.render(
cv=data.cv, cv=cv,
design=data.design, design=design,
theme_options=data.design.options, theme_options=theme_options,
today=get_today(), today=get_today(),
) )
@ -473,8 +476,8 @@ def run_latex(latex_file_path: str) -> str:
) )
run() run()
run() # run twice for cross-references run() # run twice for cross-references
# check if the PDF file is generated: # check if the PDF file is generated:
if not os.path.exists(output_file_path): if not os.path.exists(output_file_path):
raise FileNotFoundError( raise FileNotFoundError(

View File

@ -84,11 +84,16 @@
\newcolumntype{R}[1]{ \newcolumntype{R}[1]{
>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}p{#1} >{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}p{#1}
} % right-aligned fixed width column type } % right-aligned fixed width column type
((* if theme_options.text_alignment == "justified" *))
\newcolumntype{K}[1]{ \newcolumntype{K}[1]{
>{\let\newline\\\arraybackslash\hspace{0pt}}X >{\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 \setlength\tabcolsep{-1.5pt} % no space between columns
\newenvironment{highlights}{ \newenvironment{highlights}{
\begin{itemize}[ \begin{itemize}[
topsep=0pt, topsep=0pt,
@ -132,7 +137,10 @@
<<header(name=cv.name, connections=cv.connections)|indent(4)>> <<header(name=cv.name, connections=cv.connections)|indent(4)>>
((* if cv.summary is not none *)) ((* if cv.summary is not none *))
\section{Summary} \section{Summary}
{
((* if theme_options.text_alignment == "left-aligned" *))
\raggedright
((* endif *))
\setlength{\leftskip}{<<theme_options.margins.entry_area.left_and_right>>} \setlength{\leftskip}{<<theme_options.margins.entry_area.left_and_right>>}
\setlength{\rightskip}{<<theme_options.margins.entry_area.left_and_right>>} \setlength{\rightskip}{<<theme_options.margins.entry_area.left_and_right>>}
@ -140,6 +148,7 @@
\setlength{\leftskip}{0cm} \setlength{\leftskip}{0cm}
\setlength{\rightskip}{0cm} \setlength{\rightskip}{0cm}
}
((* endif *)) ((* endif *))
\centering \centering

View File

@ -94,7 +94,7 @@
((* endmacro *)) ((* endmacro *))
((* macro one_line(name, details, markdown_url=none, link_text=none) *)) ((* macro one_line(name, details, markdown_url=none, link_text=none) *))
\begingroup\raggedright \begingroup((* if theme_options.text_alignment == "left-aligned" *))\raggedright((* endif *))
\leftskip=<<theme_options.margins.entry_area.left_and_right>> \leftskip=<<theme_options.margins.entry_area.left_and_right>>
\advance\csname @rightskip\endcsname <<theme_options.margins.entry_area.left_and_right>> \advance\csname @rightskip\endcsname <<theme_options.margins.entry_area.left_and_right>>
\advance\rightskip <<theme_options.margins.entry_area.left_and_right>> \advance\rightskip <<theme_options.margins.entry_area.left_and_right>>