3 # The purpose of this script is to save the information in the aux files so we don't have
4 # to run pdftex three times every time we want to make html output. It collects all the
5 # aux files, parses them, and saves them in save.ref .
6 # I also use this in eruby_util.rb for a workaround for a bug in latex that sometimes
7 # makes it impossible to use a pageref ("Missing \endcsname inserted").
10 files = files.concat(Dir["*.aux"])
13 $stderr.print "Error, no aux files found\n"
19 File.open('save.ref','w') do |g|
20 $stderr.print "Harvesting " if verbose
22 if aux =~ /ch(\d+)/ then
25 if ch.to_i>0 && ch.to_i<99 && !FileTest.exist?(pos) then
26 $stderr.print "Error in harvest_aux_files.rb, file #{aux} has no corresponding file #{pos}; probably this is because ch#{ch} needs an <% end_chapter %> at the end\n"
30 File.open(aux,'r') do |f|
31 t = f.gets(nil) # nil means read whole file
32 $stderr.print "#{aux} " if verbose
34 # lines look like this: \newlabel{fig:comet-goofy-orbit}{{a}{14}}
36 t.scan(/\\newlabel{([^}]+)}{{([^}]*)}{([^}]+)}}/) { |label,number,page|
37 #$stderr.print "label=#{label}, #{number}, p. #{page}\n"
38 g.print "#{label},#{number},#{page}\n"
42 $stderr.print "\n" if verbose