From c477a3e03aa3e0b3b2a9b4bce0c313b59d50e6f5 Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Sat, 17 Mar 2007 12:40:35 +0100 Subject: [PATCH] The script now actually compiles the articles. Rename italian test to lematest-it.tex --- crea_numero.rb | 33 ++++++++++++++++++++++---- test/indice | 3 +-- test/{lematest.bib => lematest-it.bib} | 0 test/{lematest.tex => lematest-it.tex} | 0 test/lematest.pub | 4 ---- 5 files changed, 29 insertions(+), 11 deletions(-) rename test/{lematest.bib => lematest-it.bib} (100%) rename test/{lematest.tex => lematest-it.tex} (100%) delete mode 100644 test/lematest.pub diff --git a/crea_numero.rb b/crea_numero.rb index eaa10c5..55d44ec 100755 --- a/crea_numero.rb +++ b/crea_numero.rb @@ -45,10 +45,10 @@ def titolo_e_autore(name, file) when 0 errore "Impossibile determinare il titolo di %s" % name when 1 - res[:titolo] = titoli.first.first.gsub("\\\\", "\n") + res[:titolo] = titoli.first.first.gsub("\\\\", "\n").gsub(/\n|\r/, " ").gsub(/\s+/, " ") else avviso "%s sembra avere più d'un titolo." % name - res[:titolo] = titoli.first.first.gsub("\\\\", "\n") + res[:titolo] = titoli.first.first.gsub("\\\\", "\n").gsub(/\n|\r/, " ").gsub(/\s+/, " ") end autori = content.scan(AUTHOR_RX) @@ -72,8 +72,9 @@ def compila(name) tex_file << '.tex' if File.exists?(tex_file) art_info = titolo_e_autore(name, tex_file) - puts "\tTitolo:\n\t\t"+art_info[:titolo].gsub("\n","\n\t\t") + puts "\tTitolo:\n\t\t"+art_info[:titolo] puts "\tAutori:\n\t\t"+art_info[:autori].join("\n\t\t") + # TODO update index file else errore "Impossibile trovare l'articolo \"%s\" (\"%s\")" % [name, tex_file] exit 2 @@ -89,7 +90,28 @@ def compila(name) rescue errore "Impossibile impostare le informazioni sull'articolo \"%s\" (\"%s\")" % [name, pub_file] end - return 0 + + begin + compile = system 'pdflatex', "-interaction=batchmode", tex_file + rescue + errore "Impossibile compilare l'articolo \"%s\" (\"%s\")" % [name, tex_file] + end + + log_file = name.dup + log_file << '.log' + if compile + log = File.new(log_file).read + if log.match(/Output written on .+ \((\d+) pages, (\d+) bytes\).\s*\r?\n?/) + pagine = $1.to_i + puts "Ok! %d pagine" % pagine + else + errore "Impossibile determinare il numero di pagine per l'articolo \"%s\" (\"%s\")" % [name, tex_file] + end + + else + errore "Impossibile compilare l'articolo \"%s\" (\"%s\")" % [name, tex_file] + end + return pagine end cartella = ARGV[0] @@ -149,7 +171,8 @@ $yvn = <