-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathmake-links.rb
More file actions
34 lines (31 loc) · 866 Bytes
/
make-links.rb
File metadata and controls
34 lines (31 loc) · 866 Bytes
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
mapping = {}
for line in File.open("./linearAlgebra.aux").readlines
if line.match( /\\@writefile{toc}{\\contentsline {subsection}{([0-9]*.[0-9])*[^}]*}{[0-9]+}{section\*.([0-9]+)}}/ )
mapping[$2] = $1
end
end
sections = {}
for line in File.open("./linearAlgebra.aux").readlines
if line.match( /\\newlabel{([^}]*)}{{([^}]*)}.*{section\*.([0-9]+)}{}}/ )
section = mapping[$3]
number = $2
label = $1
if section
sections[label] = section
end
end
end
files = {}
for f in Dir.glob("./**/*.tex") do
File.open(f).read.scan(/\\label{([^}]*)}/) { |r|
r = r[0]
if sections[r]
files[sections[r]] = f
end
}
end
Dir.mkdir('by-number') unless File.exist?('by-number')
for k in files.keys
File.symlink "../" + files[k], "./by-number/#{k}.tex"
File.symlink "../" + files[k].gsub(/.tex/,''), "./by-number/#{k}"
end