-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10_LimpiezaConExpReg.py
37 lines (30 loc) · 1.02 KB
/
10_LimpiezaConExpReg.py
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
import sys
import re
def process_tex_file(filename):
# Expresiones regulares equivalentes a las utilizadas en sed
regex_patterns = [
(r'\\colorbox{[^}]*}{([^}]*)}', r'\1'),
(r'\\Calibri{([^}]*)}', ''),
(r'\\textup{([^}]*)}', r'\1'),
(r'\\textnormal{([^}]*)}', r'\1'),
(r'\\textcolor{[^}]*}{([^}]*)}', r'\1'),
(r'\\foreignlanguage{[^}]*}{([^}]*)}', r'\1'),
(r'\\href{[^}]*}{([^}]*)}', r'\1')
]
# Leer el contenido del archivo
with open(filename, 'r') as file:
content = file.read()
# Aplicar las sustituciones
for pattern, replacement in regex_patterns:
content = re.sub(pattern, replacement, content)
# Escribir el contenido modificado de vuelta al archivo
with open(filename, 'w') as file:
file.write(content)
def main():
if len(sys.argv) != 2:
print("Uso: python script.py archivo.tex")
sys.exit(1)
filename = sys.argv[1]
process_tex_file(filename)
if __name__ == "__main__":
main()