Spaces:
Running
Running
File size: 1,931 Bytes
a0d1776 3b4e6ce a0d1776 fb8c051 a0d1776 fb8c051 b4c6c2b a0d1776 3a7ead9 b4c6c2b c304855 3b4e6ce 018eb6d 3b4e6ce 018eb6d 3b4e6ce b4c6c2b 8e698eb |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
import os
import re
import shutil
def replace_title(save_to_path, title):
# Define input and output file names
input_file_name = os.path.join(save_to_path, "template.tex")
output_file_name = os.path.join(save_to_path , "main.tex")
# Open the input file and read its content
with open(input_file_name, 'r') as infile:
content = infile.read()
content = content.replace(r"\title{TITLE} ", f"\\title{{{title}}} ")
# Open the output file and write the modified content
with open(output_file_name, 'w') as outfile:
outfile.write(content)
# return all string in \cite{...} \citet{...} or \citep{...}.
# check if citations are in bibtex.
# replace citations
# sometimes the output may include thebibliography and bibitem . remove all of it.
# return all .png and replace it using placeholder.
def find_tex_files(directory_path):
tex_files = []
for filename in os.listdir(directory_path):
if filename.endswith(".tex"):
tex_files.append(filename)
return tex_files
def find_figure_names(tex_file_path):
# Regular expression pattern to find \includegraphics commands
pattern = r'\\includegraphics.*?{(.*?)}'
with open(tex_file_path, 'r') as file:
content = file.read()
# Find all matches in the file content
matches = re.findall(pattern, content)
# Matches will be a list of figure names
return matches
def create_copies(output_dir):
tex_files = find_tex_files(output_dir)
for tex_file in tex_files:
path = os.path.join(output_dir, tex_file)
all_figs = find_figure_names(path)
for fig in all_figs:
original_fig = os.path.join(output_dir, "fig.png")
target_fig = os.path.join(output_dir, fig)
shutil.copy2(original_fig, target_fig)
# todo: post-processing the generated algorithm for correct compile.
if __name__ == "__main__":
pass
|