-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathformat.py
More file actions
executable file
·60 lines (54 loc) · 1.58 KB
/
Copy pathformat.py
File metadata and controls
executable file
·60 lines (54 loc) · 1.58 KB
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
from pathlib import Path
import re
p = Path('/tmp')
math = p /'math.txt'
temp = p / 'ans.txt'
break_sentence = p / 'break.txt'
"""
create /temp/math.txt
then run this program,
In order to fill anki card format
$$ will replace to [$][/$]
\[ \]will replace to [$$][/$$]
"""
if math.exists():
# with math.open() as f:
# text = f.read()
# s = '1\n'
# f.write(s)
math.touch()
s = math.read_text()
# s = re.sub(r'\$\n*(.+?)\n\$', r'[$]\1[/$]', s)
# s = re.sub(r'\$\n*(.+?)\n*\$', r'[$]\1[/$]', s)
# s = re.sub(r'\$(.+?)\$', r'[$]\1[/$]', s)
s = re.sub(r'\$(.*)\$', r'[$]\1[/$]', s)
s = re.sub(r'\\\[', r'[$$]', s)
s = re.sub(r'\\\]', r'[/$$]', s)
s = re.sub(r'\\dif',r'\\mathrm{d}',s)
s = re.sub(r'\\bm',r'\\boldsymbol',s)
s = re.sub(r'\\gets',r'\\leftarrow',s)
s = re.sub(r'\\var',r'\\operatorname{var}',s)
s = re.sub(r'\\cov',r'\\operatorname{cov}',s)
# s = s.replace("\n\n","************")
# s = s.replace("\n"," ")
# s = s.replace("************","\n\n")
math.write_text(s)
"""
create /tmp/break.txt
run this program,
,.; will be break to fit the latex sentence
"""
if break_sentence.exists():
break_sentence.touch()
s = break_sentence.read_text()
s = re.sub('([^A|B|C|D]),',r'\1,\n',s)
s = re.sub('([A|B|C|D]?)[,|,]', r'\1. ', s)
s = s.replace(';', ';\n')
s = s.replace('?', '?\n')
s = s.replace('。', '.\n')
# s = s.replace(" ","")
s = s.replace(".",".\n")
s = s.replace(",",",\n")
# s = s.replace(': ', ':\n')
# temp.write_text(s)
break_sentence.write_text(s)