INNER CODE UNIT · Python
extract_latex_formulas
RQLuo/MixTeX-Latex-OCR · mixtex_data_gen/gen.py:27
def extract_latex_formulas(tex_file_path):
with open(tex_file_path, 'r', encoding='utf-8') as f:
tex_content = f.read()
pattern = r'\\\[(.+?)\\\]|\\begin{align\*}(.+?)\\end{align\*}'
formulas = re.findall(pattern, tex_content)
formula_list = [re.sub(r'\\eqref\{(.*?)\}', r'', group) for tuples in formulas for group in tuples if group]
return formula_list
# Function to process text by inserting LaTeX formulas randomly
# Input:
# input_file (str): Path to the input text file
# output_file (str): Path to save the processed text file
# formulas (list): List of LaTeX formulas to insert
# Output:
# None (writes the processed content to output_file)
def process_text(input_file, output_file, formulas):
with open(input_file, 'r', encoding='utf-8') as f:
text = f.read()