INNER CODE UNIT · Python
remove_non_english_characters
RQLuo/MixTeX-Latex-OCR · mixtex_data_gen/gen.py:14
def remove_non_english_characters(input_file_path, output_file_path):
english_regex = re.compile(r'[^a-zA-Z0-9\s.,?!\'"()]+')
with open(input_file_path, 'r', encoding='utf-8') as file:
content = file.read()
cleaned_content = english_regex.sub('', content)
with open(output_file_path, 'w', encoding='utf-8') as file:
file.write(cleaned_content)
# Function to extract LaTeX formulas from a .tex file
# Input:
# tex_file_path (str): Path to the LaTeX (.tex) file
# Output:
# formula_list (list): List of extracted LaTeX formulas
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)