From 1dab52d229955b25085cc8631196ad07c3c06f0b Mon Sep 17 00:00:00 2001 From: Sina Atalay Date: Sun, 10 Sep 2023 21:56:54 +0200 Subject: [PATCH] create rendering module --- rendercv/rendering.py | 48 +++++++++++++++++++++++++++++++++++++++++++ rendercv/tinytex.py | 44 --------------------------------------- 2 files changed, 48 insertions(+), 44 deletions(-) create mode 100644 rendercv/rendering.py diff --git a/rendercv/rendering.py b/rendercv/rendering.py new file mode 100644 index 0000000..283d364 --- /dev/null +++ b/rendercv/rendering.py @@ -0,0 +1,48 @@ +"""This module implements rendering utilities. +""" +import os +import subprocess + +def render_template(template, data): + pass + +def run_latex(latexFilePath): + """ + Run LuaLateX on the given LaTeX file and generate a PDF. + + :param latexFilePath: The path to the LaTeX file to compile. + :type latexFilePath: str + :return: None + :rtype: None + """ + latexFilePath = os.path.normpath(latexFilePath) + latexFile = os.path.basename(latexFilePath) + + if os.name == "nt": + # remove all files except the .tex file + for file in os.listdir(os.path.dirname(latexFilePath)): + if file.endswith(".tex"): + continue + os.remove(os.path.join(os.path.dirname(latexFilePath), file)) + + tinytexPath = os.path.join( + os.path.dirname(__file__), + "vendor", + "TinyTeX", + "bin", + "windows", + ) + subprocess.run( + [ + f"{tinytexPath}\\latexmk.exe", + "-lualatex", + # "-c", + f"{latexFile}", + "-synctex=1", + "-interaction=nonstopmode", + "-file-line-error", + ], + cwd=os.path.dirname(latexFilePath), + ) + else: + print("Only Windows is supported for now.") diff --git a/rendercv/tinytex.py b/rendercv/tinytex.py index 7afbdb9..198836b 100644 --- a/rendercv/tinytex.py +++ b/rendercv/tinytex.py @@ -1,47 +1,3 @@ """ This module implements a handler for TinyTeX. """ - -import os -import subprocess - -def run_latex(latexFilePath): - """ - Run LuaLateX on the given LaTeX file and generate a PDF. - - :param latexFilePath: The path to the LaTeX file to compile. - :type latexFilePath: str - :return: None - :rtype: None - """ - latexFilePath = os.path.normpath(latexFilePath) - latexFile = os.path.basename(latexFilePath) - - if os.name == "nt": - # remove all files except the .tex file - for file in os.listdir(os.path.dirname(latexFilePath)): - if file.endswith(".tex"): - continue - os.remove(os.path.join(os.path.dirname(latexFilePath), file)) - - tinytexPath = os.path.join( - os.path.dirname(__file__), - "vendor", - "TinyTeX", - "bin", - "windows", - ) - subprocess.run( - [ - f"{tinytexPath}\\latexmk.exe", - "-lualatex", - # "-c", - f"{latexFile}", - "-synctex=1", - "-interaction=nonstopmode", - "-file-line-error", - ], - cwd=os.path.dirname(latexFilePath), - ) - else: - print("Only Windows is supported for now.")