improve classic theme

This commit is contained in:
Sina Atalay 2023-11-17 01:04:43 +01:00
parent 631e9d594c
commit 0af0fcffec
4 changed files with 105 additions and 28 deletions

View File

@ -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."
),
" or open an issue on GitHub.",
)
# check if the PDF file is generated:

View File

@ -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{<horizontal pos>}{<vertical pos>}{<stuff>}
\AddToShipoutPictureFG*{% Add <stuff> to current page foreground
\put(
\LenToUnit{\paperwidth-<<theme_options.margins.page.right>>},
\LenToUnit{\paperwidth-<<theme_options.margins.page.right>>-<<theme_options.margins.entry_area.left_and_right>>+0.05cm},
\LenToUnit{\paperheight-<<theme_options.margins.page.top|divide_length_by(2)>>}
){\vtop{{\null}\makebox[0pt][c]{
\small\color{gray}\emph{Last updated on <<today>>} \hspace{\widthof{Last updated on <<today>>}}
\small\color{gray}\emph{Last updated on <<today>>}\hspace{\widthof{Last updated on <<today>>}}
}}}%
}%
}%
@ -123,8 +124,8 @@
((* if cv.summary is not none *))
\section{Summary}
\setlength{\leftskip}{<<theme_options.margins.entry_area.left>>}
\setlength{\rightskip}{<<theme_options.margins.entry_area.right>>}
\setlength{\leftskip}{<<theme_options.margins.entry_area.left_and_right>>}
\setlength{\rightskip}{<<theme_options.margins.entry_area.left_and_right>>}
<<cv.summary>>
@ -132,6 +133,7 @@
\setlength{\rightskip}{0cm}
((* endif *))
\centering
((* for section in cv.sections *))
\section{<<section.title>>}

View File

@ -1,9 +1,9 @@
((* macro date_and_location_strings(date_and_location_strings) *))
((* for item in date_and_location_strings *))
((* if loop.last *))
<<item>> \hspace*{-0.2cm + <<theme_options.margins.entry_area.right>>}
<<item>>
((* else *))
<<item>> \hspace*{-0.2cm + <<theme_options.margins.entry_area.right>>} \newline
<<item>> \newline
((* endif *))
((* endfor *))
((* endmacro *))

View File

@ -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{<<theme_options.margins.entry_area.left>>}; variable width, ragged left column #))
((# second column: K{<<theme_options.margins.entry_area.left_and_right>>}; variable width, justified column #))
((# third column: R{<<theme_options.date_and_location_width>>}; constant widthm ragged right column #))
\begin{tabularx}{\textwidth}{p{0.55cm} K{<<theme_options.margins.entry_area.left>>} R{<<theme_options.date_and_location_width>>}}
\begin{tabularx}{\textwidth-<<theme_options.margins.entry_area.left_and_right|divide_length_by(0.5)>>-0.13cm}{L{0.85cm} K{<<theme_options.margins.entry_area.left_and_right>>} R{<<theme_options.date_and_location_width>>}}
\textbf{<<study_type if study_type is not none>>}
&
\textbf{<<institution>>}, <<area>>
@ -22,9 +22,9 @@
((# \begin{tabularx}{⟨width⟩}[⟨pos⟩]{⟨preamble⟩} #))
((# width: \textwidth #))
((# preamble: first column, second column #))
((# first column:: K{<<theme_options.margins.entry_area.left>>}; variable width, ragged left column #))
((# first column:: K{<<theme_options.margins.entry_area.left_and_right>>}; variable width, justified column #))
((# second column: R{<<theme_options.date_and_location_width>>}; constant width ragged right column #))
\begin{tabularx}{\textwidth}{K{<<theme_options.margins.entry_area.left>>} R{<<theme_options.date_and_location_width>>}}
\begin{tabularx}{\textwidth-<<theme_options.margins.entry_area.left_and_right|divide_length_by(0.5)>>-0.13cm}{K{<<theme_options.margins.entry_area.left_and_right>>} R{<<theme_options.date_and_location_width>>}}
\textbf{<<company>>}, <<position>>
<<print_higlights(highlights)|indent(4)->>
&
@ -36,9 +36,24 @@
((# \begin{tabularx}{⟨width⟩}[⟨pos⟩]{⟨preamble⟩} #))
((# width: \textwidth #))
((# preamble: first column, second column #))
((# first column:: K{<<theme_options.margins.entry_area.left>>}; variable width, ragged left column #))
((# first column:: K{<<theme_options.margins.entry_area.left_and_right>>}; variable width, justified column #))
((# second column: R{<<theme_options.date_and_location_width>>}; constant width ragged right column #))
\begin{tabularx}{\textwidth}{K{<<theme_options.margins.entry_area.left>>} R{<<theme_options.date_and_location_width>>}}
((* if date_and_location_strings == [] *))
\begin{tabularx}{\textwidth-<<theme_options.margins.entry_area.left_and_right|divide_length_by(0.5)>>-0.13cm}{K{<<theme_options.margins.entry_area.left_and_right>>}}
((* if markdown_url is not none *))
((* if link_text is not none *))
((* set markdown_url = "["+link_text+"]("+ markdown_url|markdown_link_to_url +")" *))
\textbf{<<name>>}, <<markdown_url|markdown_to_latex>>
((* else *))
\textbf{<<name>>}, <<markdown_url|markdown_to_latex>>
((* endif *))
((* else *))
\textbf{<<name>>}
((* endif *))
<<print_higlights(highlights)|indent(4)->>
\end{tabularx}
((* else *))
\begin{tabularx}{\textwidth-<<theme_options.margins.entry_area.left_and_right|divide_length_by(0.5)>>-0.13cm}{K{<<theme_options.margins.entry_area.left_and_right>>} R{<<theme_options.date_and_location_width>>}}
((* 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 @@
&
<<print_date_and_locations(date_and_location_strings)|indent(4)->>
\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{<<theme_options.margins.entry_area.left>>}; variable width, ragged left column #))
((# first column:: K{<<theme_options.margins.entry_area.left_and_right>>}; variable width, justified column #))
((# second column: R{<<theme_options.date_and_location_width>>}; constant width ragged right column #))
\begin{tabularx}{\textwidth}{K{<<theme_options.margins.entry_area.left>>} R{<<theme_options.date_and_location_width>>}}
\begin{tabularx}{\textwidth-<<theme_options.margins.entry_area.left_and_right|divide_length_by(0.5)>>-0.13cm}{K{<<theme_options.margins.entry_area.left_and_right>>} R{<<theme_options.date_and_location_width>>}}
\textbf{<<title>>}
<<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 *))