diff --git a/rendercv/data_model.py b/rendercv/data_model.py index fa88ed82..d74fb13b 100644 --- a/rendercv/data_model.py +++ b/rendercv/data_model.py @@ -592,6 +592,23 @@ def markdown_url(self) -> Optional[str]: return markdown_url + @computed_field + @cached_property + def month_and_year(self) -> Optional[str]: + if self.date is not None: + # Then it means start_date and end_date are not provided. + try: + # If this runs, it means the date is an ISO format string, and it can be + # parsed + month_and_year = format_date(Date.fromisoformat(self.date)) + except: + month_and_year = self.date + else: + # Then it means start_date and end_date are provided and month_and_year + # doesn't make sense. + month_and_year = None + + return month_and_year class OneLineEntry(Event): """This class stores [OneLineEntry](../index.md#onelineentry) information.""" diff --git a/rendercv/rendering.py b/rendercv/rendering.py index e6c12a94..471e2a7d 100644 --- a/rendercv/rendering.py +++ b/rendercv/rendering.py @@ -126,6 +126,65 @@ def make_it_bold(value: str, match_str: str) -> str: else: return value +def make_it_underlined(value: str, match_str: str) -> str: + """Make the matched parts of the string underlined. + + This function is used as a Jinja2 filter. + + Example: + ```python + make_it_underlined_if("Hello World!", "Hello") + ``` + + will return: + + `#!python "\\underline{Hello} World!"` + + Args: + value (str): The string to make underlined. + match_str (str): The string to match. + """ + if not isinstance(value, str): + raise ValueError("make_it_underlined_if should only be used on strings!") + + if not isinstance(match_str, str): + raise ValueError("The string to match should be a string!") + + if match_str in value: + value = value.replace(match_str, "\\underline{" + match_str + "}") + return value + else: + return value + +def make_it_italic(value: str, match_str: str) -> str: + """Make the matched parts of the string italic. + + This function is used as a Jinja2 filter. + + Example: + ```python + make_it_italic_if("Hello World!", "Hello") + ``` + + will return: + + `#!python "\\textit{Hello} World!"` + + Args: + value (str): The string to make italic. + match_str (str): The string to match. + """ + if not isinstance(value, str): + raise ValueError("make_it_italic_if should only be used on strings!") + + if not isinstance(match_str, str): + raise ValueError("The string to match should be a string!") + + if match_str in value: + value = value.replace(match_str, "\\textit{" + match_str + "}") + return value + else: + return value def render_template(data): """Render the template using the given data. @@ -164,6 +223,8 @@ def render_template(data): environment.filters["markdown_to_latex"] = markdown_to_latex environment.filters["markdown_url_to_url"] = markdown_url_to_url environment.filters["make_it_bold"] = make_it_bold + environment.filters["make_it_underlined"] = make_it_underlined + environment.filters["make_it_italic"] = make_it_italic output_latex_file = template.render(design=data.design.options, cv=data.cv) diff --git a/rendercv/templates/classic.tex.j2 b/rendercv/templates/classic.tex.j2 index 2b8adaf0..3657bcc4 100644 --- a/rendercv/templates/classic.tex.j2 +++ b/rendercv/templates/classic.tex.j2 @@ -11,7 +11,7 @@ bottom=<>, % seperation between body and page edge from the bottom left=<>, % seperation between body and page edge from the left right=<>, % seperation between body and page edge from the right - showframe % for debugging + % showframe % for debugging ]{geometry} % for adjusting page geometry \usepackage{fontspec} % for loading fonts \usepackage[explicit]{titlesec} % for customizing section titles diff --git a/rendercv/templates/components/classic/entry.tex.j2 b/rendercv/templates/components/classic/entry.tex.j2 index 84b6c3e0..4e55cef5 100644 --- a/rendercv/templates/components/classic/entry.tex.j2 +++ b/rendercv/templates/components/classic/entry.tex.j2 @@ -55,7 +55,7 @@ \end{tabularx} ((* endmacro *)) -((* macro publication(title, authors, journal, year, doi, doi_url)*)) +((* macro publication(title, authors, journal, date, doi, doi_url)*)) ((# \begin{tabularx}{⟨width⟩}[⟨pos⟩]{⟨preamble⟩} #)) ((# width: \textwidth #)) ((# preamble: first column, second column #)) @@ -64,13 +64,11 @@ \begin{tabularx}{\textwidth}{K{<>} R{2 cm}} \textbf{<>} - <<authors|join(", ")|make_it_bold("Cetin Yilmaz")>> + <<authors|join(", ")|make_it_italic(cv.name)>> DOI: \hrefExternal{<<doi_url>>}{<<doi>>} - - <<journal>> & - <<year>> + <<date>> \end{tabularx} ((* endmacro *)) diff --git a/rendercv/templates/components/classic/section_contents.tex.j2 b/rendercv/templates/components/classic/section_contents.tex.j2 index c1c5cfaf..4dff1025 100644 --- a/rendercv/templates/components/classic/section_contents.tex.j2 +++ b/rendercv/templates/components/classic/section_contents.tex.j2 @@ -41,7 +41,7 @@ title=value.title, authors=value.authors, journal=value.journal, - year=value.date, + date=value.month_and_year, doi=value.doi, doi_url=value.doi_url, )|indent(4)>>