5 # Crea un numero per la rivista Le Matematiche, usando le informazioni contenute in una specifica cartella
7 # Author: Giuseppe Bilotta <bilotta@dmi.unict.it>
11 # Last Modified: 20070317
13 # Copyright: (C) 2007 Giuseppe Bilotta
17 require 'roman_numerals'
20 puts "#{$0} <nome cartella>"
21 puts "\tcrea un numero per la rivista Le Matematiche, usando le informazioni contenute nella cartella"
25 $stderr.puts "ERRORE: %s" % msg
30 $stderr.puts "AVVISO: %s" % msg
34 SIMPLE_GROUP = /#{NOT_BRACE}+?|\{#{NOT_BRACE}*?\}/
35 NESTED_GROUP = /#{SIMPLE_GROUP}+?|\{#{SIMPLE_GROUP}*?\}/
36 TITLE_RX = /\\title\{(#{NESTED_GROUP})\}/m
37 AUTHOR_RX = /\\author\{(#{NESTED_GROUP})\}/m
39 def titolo_e_autore(name, file)
41 content = File.open(file).read
43 titoli = content.scan(TITLE_RX)
46 errore "Impossibile determinare il titolo di %s" % name
48 res[:titolo] = titoli.first.first.gsub("\\\\", "\n").gsub(/\n|\r/, " ").gsub(/\s+/, " ")
50 avviso "%s sembra avere più d'un titolo." % name
51 res[:titolo] = titoli.first.first.gsub("\\\\", "\n").gsub(/\n|\r/, " ").gsub(/\s+/, " ")
54 autori = content.scan(AUTHOR_RX)
57 errore "Impossibile determinare il titolo di %s" % name
59 res[:autori] = autori.map { |ar|
66 # TODO check if this is indeed the initial page
70 puts "Prossimo articolo: %s a pagina %d" % [name, $pg]
73 if File.exists?(tex_file)
74 art_info = titolo_e_autore(name, tex_file)
75 puts "\tTitolo:\n\t\t"+art_info[:titolo]
76 puts "\tAutori:\n\t\t"+art_info[:autori].join("\n\t\t")
77 # TODO update index file
79 errore "Impossibile trovare l'articolo \"%s\" (\"%s\")" % [name, tex_file]
86 pub = File.new(pub_file, 'w')
88 pub.puts "\\gdef\\LM@FirstPg{#{$pg}}%"
91 errore "Impossibile impostare le informazioni sull'articolo \"%s\" (\"%s\")" % [name, pub_file]
95 compile = system 'pdflatex', "-interaction=batchmode", tex_file
97 errore "Impossibile compilare l'articolo \"%s\" (\"%s\")" % [name, tex_file]
103 log = File.new(log_file).read
104 if log.match(/Output written on .+ \((\d+) pages, (\d+) bytes\).\s*\r?\n?/)
106 puts "Ok! %d pagine" % pagine
108 errore "Impossibile determinare il numero di pagine per l'articolo \"%s\" (\"%s\")" % [name, tex_file]
112 errore "Impossibile compilare l'articolo \"%s\" (\"%s\")" % [name, tex_file]
119 if !cartella or cartella.empty?
127 errore "Impossibile accedere alla cartella \"#{cartella}\""
132 if not File.exists?(indice)
133 errore "La cartella \"%s\" non contiene il file di indice!" % cartella
137 info = YAML.load(File.read(indice))
139 errore "Impossibile leggere il file di indice in \"%s\"" % cartella
142 if info.has_key?(:anno)
143 anno = info[:anno].to_i
145 errore "Il file di indice in \"%s\" non specifica l'anno!" % cartella
147 if info.has_key?(:volume)
148 vol = info[:volume].to_i
149 vol_rm = vol.to_s_roman
151 errore "Il file di indice in \"%s\" non specifica il volume!" % cartella
153 if info.has_key?(:numero)
154 num = info[:numero].to_i
155 num_rm = num.to_s_roman
157 errore "Il file di indice in \"%s\" non specifica il numero!" % cartella
159 if info.has_key?(:articoli)
160 articoli = info[:articoli]
162 errore "Il file di indice in \"%s\" non specifica alcun articolo!" % cartella
165 puts "Preparazione: Le Matematiche, volume #{vol_rm}, numero #{num_rm}, anno #{anno}"
168 \\gdef\\LM@Year{#{anno}}%
169 \\gdef\\LM@Vol{#{vol_rm}}%
170 \\gdef\\LM@Num{#{num_rm}}%
173 articoli.each { |art|