-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvert_latex.py
40 lines (30 loc) · 941 Bytes
/
convert_latex.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
38
39
40
## Author : Daesung Park
## Date : 2015.08.10
## This script sorts the acronym list by the short name.
## acro{<acronym>}[<short name>]{<full name>}
import re
from operator import itemgetter
import sys
## define the file_path
file_path = "./my_acronym_acronym_package.tex"
a = []
with open(file_path, 'r') as fp:
for line in fp:
#print line
#if line.startswith("%"): continue
#if line.startswith("\begin"): continue
#if line.startswith("\end"): continue
match = re.match(r'\\acro\{(.*?)\}\[(.*?)\]\{(.*?)\}', line)
if not match: continue
a.append(match.groups())
a_sort = sorted(a, key=itemgetter(1))
template = r'{0}, {1}, {2}'
## define the output file name
f = open('acronym_sorted_.txt', 'w')
sys.stdout = f
#print r"\begin{acronym}"
print r"## short name, acronym, long name"
for (x,y,z) in a_sort:
print template.format(x,y,z)
#print r"\end{acronym}"
f.close()