reposition last updated text

This commit is contained in:
Sina Atalay 2023-10-08 16:13:47 +02:00
parent 468dafa19d
commit 4ddd8581d9
2 changed files with 29 additions and 8 deletions

View File

@ -190,7 +190,19 @@ def make_it_italic(value: str, match_str: str) -> str:
return value return value
def print_today() -> str: def divide_length_by(length: str, divider: float) -> str:
# r"""Divide a length by a number.
# Length is a string with the following regex pattern: `\d+\.?\d* *(cm|in|pt|mm|ex|em)`
# """
# Get the value as a float and the unit as a string:
value = re.search(r"\d+\.?\d*", length).group()
unit = re.findall(r"[^\d\.\s]+", length)[0]
return str(float(value) / divider) + " " + unit
def get_today() -> str:
"""Return today's date. """Return today's date.
Returns: Returns:
@ -240,22 +252,23 @@ def render_template(data):
environment.comment_start_string = "((#" environment.comment_start_string = "((#"
environment.comment_end_string = "#))" environment.comment_end_string = "#))"
# load the template:
theme = data.design.theme
template = environment.get_template(f"{theme}.tex.j2")
# add custom filters: # add custom filters:
environment.filters["markdown_to_latex"] = markdown_to_latex environment.filters["markdown_to_latex"] = markdown_to_latex
environment.filters["markdown_url_to_url"] = markdown_url_to_url environment.filters["markdown_url_to_url"] = markdown_url_to_url
environment.filters["make_it_bold"] = make_it_bold environment.filters["make_it_bold"] = make_it_bold
environment.filters["make_it_underlined"] = make_it_underlined environment.filters["make_it_underlined"] = make_it_underlined
environment.filters["make_it_italic"] = make_it_italic environment.filters["make_it_italic"] = make_it_italic
environment.filters["divide_length_by"] = divide_length_by
# load the template:
theme = data.design.theme
template = environment.get_template(f"{theme}.tex.j2")
output_latex_file = template.render( output_latex_file = template.render(
cv=data.cv, cv=data.cv,
design=data.design, design=data.design,
theme_options=data.design.options, theme_options=data.design.options,
today=print_today(), today=get_today(),
) )
# Create an output file and write the rendered LaTeX code to it: # Create an output file and write the rendered LaTeX code to it:
@ -265,6 +278,10 @@ def render_template(data):
file.write(output_latex_file) file.write(output_latex_file)
# Copy the fonts directory to the output directory: # Copy the fonts directory to the output directory:
# Remove the old fonts directory if it exists:
if os.path.exists(os.path.join(os.path.dirname(output_file_path), "fonts")):
shutil.rmtree(os.path.join(os.path.dirname(output_file_path), "fonts"))
font_directory = get_path_to_font_directory(data.design.font) font_directory = get_path_to_font_directory(data.design.font)
output_fonts_directory = os.path.join(os.path.dirname(output_file_path), "fonts") output_fonts_directory = os.path.join(os.path.dirname(output_file_path), "fonts")
shutil.copytree( shutil.copytree(

View File

@ -100,8 +100,12 @@
\newcommand{\placelastupdatedtext}{% \placetextbox{<horizontal pos>}{<vertical pos>}{<stuff>} \newcommand{\placelastupdatedtext}{% \placetextbox{<horizontal pos>}{<vertical pos>}{<stuff>}
\AddToShipoutPictureFG*{% Add <stuff> to current page foreground \AddToShipoutPictureFG*{% Add <stuff> to current page foreground
\put(\LenToUnit{\paperwidth-0.5cm},\LenToUnit{\paperheight-0.5cm}){\vtop{{\null}\makebox[0pt][c]{ \put(
\small\color{gray}\emph{Last updated on <<today>>} \hspace{\widthof{Last updated on <<today>>}}}}}% \LenToUnit{\paperwidth-<<theme_options.margins.page.right>>},
\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>>}}
}}}%
}% }%
}% }%