-
Notifications
You must be signed in to change notification settings - Fork 0
/
listsymbols
executable file
·109 lines (93 loc) · 3.49 KB
/
listsymbols
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/bin/env python
import re
class TableWrite:
"""Write tables with correct header and footer"""
def __init__(self,file):
self.f = file
self.columncount = 0
self.tableopen= False
self.tablebegin = r'\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}}l@{\extracolsep{0.5cm}}l@{\extracolsep{\fill}}l@{\extracolsep{0.5cm}}l@{\extracolsep{\fill}}l@{\extracolsep{0.5cm}}l}'+'\n'
self.tableend=r'\end{tabular*}'+'\n'
def item(self,text):
if not self.tableopen:
self.f.write(self.tablebegin)
self.tableopen=True
self.columncount = 0
self.f.write(text)
if self.columncount<2:
self.f.write(' & ')
self.columncount+=1
else:
self.f.write(r' \\'+'\n')
self.columncount=0
def finish(self):
if self.tableopen:
if self.columncount>0:
self.f.write(r' \\'+'\n')
self.f.write(self.tableend+'\n')
self.tableopen=False
def header(self,text):
self.finish()
self.f.write(text+'\n')
fin = open('lhcb-symbols-def.tex')
outname = 'lhcb-symbols-list.tex'
fout = open(outname,'w')
print "All symbols are now available in the file %s." % outname
fout.write("""% This is an automatically generated appendix to template.tex.
% When included it will show all the symbols defined in lhcb-symbols-def.tex.
%
% To regenerate with the latest definitions run the script ./listsymbols
\\section{List of all symbols}
\\label{sec:listofsymbols}
""")
psection = re.compile(r'(%+)\s*(.*)')
pdef = re.compile(r'^\\def(\\.+?)[\s{]+[^%]*(%\s.+)*')
pnew = re.compile(r'^\\newcommand\{(\\\w+?)\}(\[\d\])*[\s\{]+[^%]*(%\s.+)*')
parg = re.compile(r'.+(#\d)+.*')
writer=TableWrite(fout)
for l in fin.readlines():
# Match on section headers
m = psection.match(l)
if m:
length = len(m.group(1))
if length<=2:
if length==1:
writer.header('\\subsection{%s}' % m.group(2))
else:
writer.header('\\subsubsection{%s}' % m.group(2))
# Match on the \def lines
m = pdef.match(l)
if m:
marg = parg.match(m.group(1))
if not marg:
writer.item('\\texttt{\\textbackslash %s} & %s'
% (m.group(1)[1:],m.group(1)))
else:
if m.group(2):
pat1 = re.compile(r'#')
pat2 = re.compile(r'(#\d)+')
generic = re.sub(pat1,r'\#',m.group(1))
example = re.sub(pat2,m.group(2)[2:],m.group(1))
writer.item('\\texttt{\\textbackslash %s ' % generic[1:] +
'\\textbackslash %s} & %s'
% (example[1:],example))
else:
print 'Ignoring line: %s' % l[:-1]
# Match on the \newcommand lines
m = pnew.match(l)
if m:
if not m.group(2):
writer.item('\\texttt{\\textbackslash %s} & %s'
% (m.group(1)[1:],m.group(1)))
elif m.group(3):
generic = str(m.group(3)[2:]).replace('{',r'\{').replace('}',r'\}')
writer.item('\\texttt{\\textbackslash %s%s ' %
(m.group(1)[1:],m.group(2)) +
'\\textbackslash %s%s} & %s%s'
% (m.group(1)[1:],generic,
m.group(1),m.group(3)[2:]))
else:
print 'Ignoring line: %s' % l[:-1]
writer.finish()
fin.close()
fout.close()