From 0af0fcffeca5323cd8ddf5478e25055753f0f0b8 Mon Sep 17 00:00:00 2001 From: Sina Atalay Date: Fri, 17 Nov 2023 01:04:43 +0100 Subject: [PATCH] improve classic theme --- rendercv/rendering.py | 61 +++++++++++++++++-- rendercv/templates/classic/classic.tex.j2 | 16 ++--- .../date_and_location_strings.tex.j2 | 4 +- .../templates/classic/components/entry.tex.j2 | 52 +++++++++++----- 4 files changed, 105 insertions(+), 28 deletions(-) diff --git a/rendercv/rendering.py b/rendercv/rendering.py index 80cbb0f..7bd8928 100644 --- a/rendercv/rendering.py +++ b/rendercv/rendering.py @@ -212,6 +212,59 @@ def make_it_italic(value: str, match_str: Optional[str] = None) -> str: return make_it_something(value, "make_it_italic", match_str) +def abbreviate_name(name: list[str]) -> str: + """Abbreviate a name by keeping the first letters of the first names. + + This function is used as a Jinja2 filter. + + Example: + ```python + abbreviate_name("John Doe") + ``` + + will return: + + `#!python "J. Doe"` + + Args: + name (str): The name to abbreviate. + Returns: + str: The abbreviated name. + """ + first_names = name.split(" ")[:-1] + first_names_initials = [first_name[0] + "." for first_name in first_names] + last_name = name.split(" ")[-1] + abbreviated_name = " ".join(first_names_initials) + " " + last_name + + return abbreviated_name + + +def abbreviate_names(names: list[str]) -> str: + """Abbreviate a list of names by keeping the first letters of the first names. + + This function is used as a Jinja2 filter. + + Example: + ```python + abbreviate_names(["John Doe", "Jane Atalay"]) + ``` + + will return: + + `#!python ["J. Doe", "J. Atalay"]` + + Args: + names (list[str]): The names to abbreviate. + Returns: + str: The list of abbreviated names. + """ + abbreviated_names = [] + for name in names: + abbreviated_names.append(abbreviate_name(name)) + + return abbreviated_names + + def divide_length_by(length: str, divider: float) -> str: r"""Divide a length by a number. @@ -282,6 +335,8 @@ def render_template(data: RenderCVDataModel, output_path: Optional[str] = None) environment.filters["make_it_underlined"] = make_it_underlined environment.filters["make_it_italic"] = make_it_italic environment.filters["divide_length_by"] = divide_length_by + environment.filters["abbreviate_name"] = abbreviate_name + environment.filters["abbreviate_names"] = abbreviate_names # load the template: template = environment.get_template(f"{theme}.tex.j2") @@ -411,10 +466,8 @@ def run_latex(latex_file_path: str) -> str: raise RuntimeError( "Running TinyTeX has failed with the following error:", f"{error_line}", - ( - "If you can't solve the problem, please try to re-install RenderCV," - " or open an issue on GitHub." - ), + "If you can't solve the problem, please try to re-install RenderCV," + " or open an issue on GitHub.", ) # check if the PDF file is generated: diff --git a/rendercv/templates/classic/classic.tex.j2 b/rendercv/templates/classic/classic.tex.j2 index 7eaea83..9ad5c21 100644 --- a/rendercv/templates/classic/classic.tex.j2 +++ b/rendercv/templates/classic/classic.tex.j2 @@ -55,7 +55,7 @@ }{ % print bold title, give 0.15 cm space and draw a line of 0.8 pt thickness % from the end of the title to the end of the body - \textbf{#1}\hspace{0.15cm}\titlerule[0.8pt] + \textbf{#1}\hspace{0.15cm}\titlerule[0.8pt]\hspace{-0.1cm} }[] % section title formatting \titlespacing{\section}{ @@ -76,8 +76,9 @@ >{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}p{#1} } % right-aligned fixed width column type \newcolumntype{K}[1]{ - >{\raggedright\let\newline\\\arraybackslash\hspace{-0.2cm}\hspace{#1}}X -} % left-aligned flexible width column type + >{\let\newline\\\arraybackslash\hspace{0pt}}X +} % left-aligned (but justified) flexible width column type +\setlength\tabcolsep{-1.5pt} % no space between columns \newenvironment{highlights}{ \begin{itemize}[ @@ -101,10 +102,10 @@ \newcommand{\placelastupdatedtext}{% \placetextbox{}{}{} \AddToShipoutPictureFG*{% Add to current page foreground \put( - \LenToUnit{\paperwidth-<>}, + \LenToUnit{\paperwidth-<>-<>+0.05cm}, \LenToUnit{\paperheight-<>} ){\vtop{{\null}\makebox[0pt][c]{ - \small\color{gray}\emph{Last updated on <>} \hspace{\widthof{Last updated on <>}} + \small\color{gray}\emph{Last updated on <>}\hspace{\widthof{Last updated on <>}} }}}% }% }% @@ -123,8 +124,8 @@ ((* if cv.summary is not none *)) \section{Summary} - \setlength{\leftskip}{<>} - \setlength{\rightskip}{<>} + \setlength{\leftskip}{<>} + \setlength{\rightskip}{<>} <> @@ -132,6 +133,7 @@ \setlength{\rightskip}{0cm} ((* endif *)) + \centering ((* for section in cv.sections *)) \section{<>} diff --git a/rendercv/templates/classic/components/date_and_location_strings.tex.j2 b/rendercv/templates/classic/components/date_and_location_strings.tex.j2 index f563ee9..62fecf3 100644 --- a/rendercv/templates/classic/components/date_and_location_strings.tex.j2 +++ b/rendercv/templates/classic/components/date_and_location_strings.tex.j2 @@ -1,9 +1,9 @@ ((* macro date_and_location_strings(date_and_location_strings) *)) ((* for item in date_and_location_strings *)) ((* if loop.last *)) -<> \hspace*{-0.2cm + <>} +<> ((* else *)) -<> \hspace*{-0.2cm + <>} \newline +<> \newline ((* endif *)) ((* endfor *)) ((* endmacro *)) \ No newline at end of file diff --git a/rendercv/templates/classic/components/entry.tex.j2 b/rendercv/templates/classic/components/entry.tex.j2 index 43a1415..c1324f0 100644 --- a/rendercv/templates/classic/components/entry.tex.j2 +++ b/rendercv/templates/classic/components/entry.tex.j2 @@ -6,9 +6,9 @@ ((# width: \textwidth #)) ((# preamble: first column, second column, third column #)) ((# first column: p{0.55cm}; constant width, ragged left column #)) - ((# second column: K{<>}; variable width, ragged left column #)) + ((# second column: K{<>}; variable width, justified column #)) ((# third column: R{<>}; constant widthm ragged right column #)) -\begin{tabularx}{\textwidth}{p{0.55cm} K{<>} R{<>}} +\begin{tabularx}{\textwidth-<>-0.13cm}{L{0.85cm} K{<>} R{<>}} \textbf{<>} & \textbf{<>}, <> @@ -22,9 +22,9 @@ ((# \begin{tabularx}{⟨width⟩}[⟨pos⟩]{⟨preamble⟩} #)) ((# width: \textwidth #)) ((# preamble: first column, second column #)) - ((# first column:: K{<>}; variable width, ragged left column #)) + ((# first column:: K{<>}; variable width, justified column #)) ((# second column: R{<>}; constant width ragged right column #)) -\begin{tabularx}{\textwidth}{K{<>} R{<>}} +\begin{tabularx}{\textwidth-<>-0.13cm}{K{<>} R{<>}} \textbf{<>}, <> <> & @@ -36,9 +36,24 @@ ((# \begin{tabularx}{⟨width⟩}[⟨pos⟩]{⟨preamble⟩} #)) ((# width: \textwidth #)) ((# preamble: first column, second column #)) - ((# first column:: K{<>}; variable width, ragged left column #)) + ((# first column:: K{<>}; variable width, justified column #)) ((# second column: R{<>}; constant width ragged right column #)) -\begin{tabularx}{\textwidth}{K{<>} R{<>}} + ((* if date_and_location_strings == [] *)) +\begin{tabularx}{\textwidth-<>-0.13cm}{K{<>}} + ((* if markdown_url is not none *)) + ((* if link_text is not none *)) + ((* set markdown_url = "["+link_text+"]("+ markdown_url|markdown_link_to_url +")" *)) + \textbf{<>}, <> + ((* else *)) + \textbf{<>}, <> + ((* endif *)) + ((* else *)) + \textbf{<>} + ((* endif *)) + <> +\end{tabularx} + ((* else *)) +\begin{tabularx}{\textwidth-<>-0.13cm}{K{<>} R{<>}} ((* if markdown_url is not none *)) ((* if link_text is not none *)) ((* set markdown_url = "["+link_text+"]("+ markdown_url|markdown_link_to_url +")" *)) @@ -53,28 +68,36 @@ & <> \end{tabularx} + ((* endif *)) ((* endmacro *)) ((* macro publication(title, authors, journal, date, doi, doi_url)*)) ((# \begin{tabularx}{⟨width⟩}[⟨pos⟩]{⟨preamble⟩} #)) ((# width: \textwidth #)) ((# preamble: first column, second column #)) - ((# first column:: K{<>}; variable width, ragged left column #)) + ((# first column:: K{<>}; variable width, justified column #)) ((# second column: R{<>}; constant width ragged right column #)) -\begin{tabularx}{\textwidth}{K{<>} R{<>}} +\begin{tabularx}{\textwidth-<>-0.13cm}{K{<>} R{<>}} \textbf{<>} - - <<authors|join(", ")|make_it_italic(cv.name)>> + + \vspace{<<theme_options.margins.entry_area.vertical_between|divide_length_by(2)>>} + + <<authors|abbreviate_names|join(", ")|make_it_italic(cv.name|abbreviate_name)>> + + \vspace{<<theme_options.margins.entry_area.vertical_between|divide_length_by(2)>>} DOI: \href{<<doi_url>>}{<<doi>>} & <<date>> + \end{tabularx} ((* endmacro *)) -((* macro one_line(name, details, markdown_url=none, link_text=none)*)) - \setlength{\leftskip}{<<theme_options.margins.entry_area.left>>} - \setlength{\rightskip}{<<theme_options.margins.entry_area.right>>} +((* macro one_line(name, details, markdown_url=none, link_text=none) *)) + \begingroup\raggedright + \leftskip=<<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>> ((* if markdown_url is not none *)) ((* if link_text is not none *)) @@ -87,6 +110,5 @@ \textbf{<<name>>:} <<details>> ((* endif *)) - \setlength{\leftskip}{0cm} - \setlength{\rightskip}{0cm} + \par\endgroup ((* endmacro *)) \ No newline at end of file