File size: 1,353 Bytes
a67ae61
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
'''

the issue is about $ here comes somezhting eq1 termsi whitespace $
the whitespace must be removed for proper displaying

go through all qdms files and find the white spaces at the beginning and 
at the end
'''

import pathlib
import re

# get current working directory
cwd = pathlib.Path().cwd()

# define output path
inp_Fold = cwd / "Data/1_Writing/"


# pat = r"\\$[^\\$]+\\$"
pat = r"\$[^\$]+\$"
pat_Start = r"(\s)\$"
pat_End = r"\$(\s)"

found_And_Replace= {}

# recursively looking into all folders --> subfolders are looked into as well
for iF,ct_File in enumerate(inp_Fold.rglob('*.qmd')):
    # print(ct_File.name)

    file_Content = []
    with open(str(ct_File),"r") as file:
        file_Content = file.readlines()
        
    for il, line in enumerate(file_Content):
        results = re.findall(pat, line)

        # found all simmilar to ['$\\beta_i$'] --> make sure that start and end with empty space are both covered
        for je, elem in enumerate(results):
            
            # start with empty space
            res_Start = re.findall(pat_Start, elem)
            res_End = re.findall(pat_End, elem)
            
            if len(res_Start) > 0 or len(res_End):
                # print(f"found results in file: {ct_File}")
                print(f"elem: {elem}")
                
         
            
print("done")