rake4latex 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. data/{lib/call_rake4latex.rb → call_rake4latex.rb} +21 -9
  2. data/lib/rake4latex.rb +113 -180
  3. data/lib/rake4latex/base.rb +205 -0
  4. data/lib/rake4latex/clean.rb +53 -0
  5. data/lib/rake4latex/latexdependencies.rb +2 -0
  6. data/lib/rake4latex/latexrunner.rb +31 -15
  7. data/lib/rake4latex/rake4latex.yaml +76 -0
  8. data/lib/rake4latex/rules.rb +90 -18
  9. data/lib/rake4latex/splitindex.rb +5 -2
  10. data/lib/rake4latex/template.rb +60 -0
  11. data/lib/rake4latex/tex_statistic.rb +8 -3
  12. data/lib/rake4latex_dvipdfm.rb +40 -0
  13. data/lib/rake4latex_lualatex.rb +22 -0
  14. data/lib/rake4latex_pdflatex.rb +22 -0
  15. data/lib/rake4latex_ps2pdf.rb +27 -0
  16. data/lib/rake4latex_xelatex.rb +22 -0
  17. data/license.txt +15 -0
  18. data/readme.html +70 -23
  19. data/readme.txt +58 -18
  20. data/readme_call_rake4latex.txt +25 -0
  21. data/test/_expected/bibtex_test.txt +10 -0
  22. data/test/_expected/bibtex_test_bib.txt +5 -0
  23. data/test/_expected/dvipdfm_test.txt +7 -0
  24. data/test/_expected/gloss_test.txt +16 -0
  25. data/test/_expected/gloss_test_bib.txt +8 -0
  26. data/test/_expected/includes_test.txt +8 -0
  27. data/test/_expected/index_test.txt +7 -0
  28. data/test/_expected/longtable_test.txt +6 -0
  29. data/test/_expected/minitoc_test.txt +8 -0
  30. data/test/_expected/ps2pdf_test.txt +8 -0
  31. data/test/_expected/rail_test.txt +7 -0
  32. data/test/_expected/rail_test_error.txt +10 -0
  33. data/test/_expected/splitindex_test.txt +8 -0
  34. data/test/_expected/supertabular_test.txt +6 -0
  35. data/test/_expected/supertabular_test_statistic.txt +30 -0
  36. data/test/_expected/z_complex_test.txt +12 -0
  37. data/test/_test_call/test_call.rb +14 -0
  38. data/test/_test_call/testdocument.tex +18 -0
  39. data/test/bibtex/rakefile.rb +11 -5
  40. data/test/bibtex/testdocument.bib +1 -0
  41. data/test/dvipdfm/rakefile.rb +43 -0
  42. data/test/dvipdfm/testdocument.tex +10 -0
  43. data/test/gloss/rakefile.rb +65 -0
  44. data/test/gloss/test_gloss.bib +4 -0
  45. data/test/gloss/testdocument.tex +31 -0
  46. data/test/includes/rakefile.rb +4 -4
  47. data/test/index/rakefile.rb +1 -1
  48. data/test/longtable/rakefile.rb +1 -1
  49. data/test/ps2pdf/rakefile.rb +43 -0
  50. data/test/ps2pdf/testdocument.tex +10 -0
  51. data/test/rail/rakefile.rb +10 -19
  52. data/test/rail/testrail.tex +2 -6
  53. data/test/rail/testrail_error.tex +58 -0
  54. data/test/supertabular/rakefile.rb +1 -1
  55. data/test/unittest_rake4latex.rb +66 -0
  56. data/test/z_complex/rakefile.rb +2 -2
  57. metadata +64 -6
@@ -0,0 +1,53 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # The 'rake/clean' file defines two file lists (CLEAN and CLOBBER) and
4
+ # two rake tasks (:clean and :clobber).
5
+ #
6
+ # [:clean] Clean up the project by deleting scratch files and backup
7
+ # files. Add files to the CLEAN file list to have the :clean
8
+ # target handle them.
9
+ #
10
+ # [:clobber] Clobber all generated and non-source files in a project.
11
+ # The task depends on :clean, so all the clean files will
12
+ # be deleted as well as files in the CLOBBER file list.
13
+ # The intent of this task is to return a project to its
14
+ # pristine, just unpacked state.
15
+ #
16
+ # This replaces the original clean.
17
+ #
18
+ # Changes:
19
+ # * Use File.delete (avoid stderr-messages of rm_r)
20
+ # * Use LaTeXRunner.logger if available.
21
+ # * Add task :basefile as prerequisite.
22
+
23
+ require 'rake'
24
+
25
+ CLEAN = Rake::FileList["**/*~", "**/*.bak", "**/core"]
26
+ CLEAN.clear_exclude.exclude { |fn|
27
+ fn.pathmap("%f") == 'core' && File.directory?(fn)
28
+ }
29
+
30
+ desc "Remove any temporary products."
31
+ #~ task :clean do
32
+ task :clean => :basefile do
33
+ logger = Rake4LaTeX::Logger
34
+ logger.info("Clean: delete helpfiles #{CLEAN.inspect}") if logger.info?
35
+ CLEAN.each { |fn|
36
+ #~ rm_r fn rescue nil
37
+ #~ logger.debug("Clean: delete #{fn}") if logger
38
+ File.delete(fn) rescue ( logger.warn("Clean: #{fn} not deleted") if logger )
39
+ }
40
+ end
41
+
42
+ CLOBBER = Rake::FileList.new
43
+
44
+ desc "Remove any generated file."
45
+ task :clobber => :clean do
46
+ logger = Rake4LaTeX::Logger
47
+ logger.info("Clobber: delete helpfiles #{(CLEAN + CLOBBER).inspect}") if logger.info?
48
+ CLOBBER.each { |fn|
49
+ #~ rm_r fn rescue nil
50
+ #~ logger.debug("Clobber: delete #{fn}") if logger
51
+ File.delete(fn) rescue ( logger.warn("Clobber: #{fn} not deleted") if logger )
52
+ }
53
+ end
@@ -1,3 +1,4 @@
1
+ module Rake4LaTeX
1
2
  #
2
3
  #Class to determine dependecies of a LaTeX project.
3
4
  #
@@ -101,3 +102,4 @@ There is no check on the file found by kpsewhich ##fixme##
101
102
  deps
102
103
  end #self.find_included_files
103
104
  end #LaTeXDependencies
105
+ end #Rake4LaTeX
@@ -1,3 +1,6 @@
1
+
2
+
3
+ module Rake4LaTeX
1
4
  =begin rdoc
2
5
  Class which encapsulates all the information needed to call latex
3
6
  as often as needed.
@@ -17,7 +20,6 @@ class LaTeXRunner
17
20
  :maxruns => 5,
18
21
  :program => :pdflatex, #Valid entries see PROGRAMS
19
22
  :loglevel => Log4r::INFO,
20
- :options => ['-interaction=batchmode'],
21
23
  :texerrors_allowed => false,
22
24
  }
23
25
  =begin rdoc
@@ -63,9 +65,10 @@ The settings contain the following values:
63
65
  def initialize( settings )
64
66
 
65
67
  #~ raise ArgumentError, "Task is no RakeTask but #{t.class}" unless task.is_a?(Rake::Task)
66
-
67
- @logger = Log4r::Logger.new("LaTeXRunner #{settings[:main_file]}")
68
- @logger.outputters = Log4r::StdoutOutputter.new('log_stdout')
68
+
69
+ @logger = Rake4LaTeX::Logger
70
+ #~ @logger = Log4r::Logger.new("LaTeXRunner #{settings[:main_file]}")
71
+ #~ @logger.outputters = Log4r::StdoutOutputter.new('log_stdout')
69
72
 
70
73
  DEFAULT_SETTINGS.merge(settings).each{|key, value|
71
74
  #~ puts "#{key}: #{value}"
@@ -81,17 +84,16 @@ The settings contain the following values:
81
84
  raise ArgumentError, "Undefined key #{key} for LaTeXRunner"
82
85
  end
83
86
  }
84
-
85
87
  raise MainfileError, "main_file missing" unless @main_file
86
88
  raise MainfileError, "main_file #{@main_file} not found" unless File.exist?(@main_file)
87
89
  raise ArgumentError, "Maxrun is no number" unless @maxruns.is_a?( Fixnum ) or @maxruns == Infinity
88
90
 
89
- Rake.application.latexrunner = self
90
91
  @basename = File.basename(@main_file)
91
92
  @input_dir = File.dirname(@main_file)
92
93
  @full_input_dir = File.expand_path(@input_dir)
93
94
 
94
- @logger.name.replace("LaTeXRunner #{@basename}")
95
+ #This replacement is global in Rake4LaTeX::Logger -> May be a problem with multiple documents, parallel tasks...
96
+ @logger.name.replace("LaTeXRunner #{@basename}") #no, only one global Logger.
95
97
  @logger.info( "StartLaTeXRunner for #{@main_file}")
96
98
 
97
99
  @rerun_necessary = true #initialize
@@ -146,10 +148,8 @@ The settings contain the following values:
146
148
  It determines the latex command line and calls <tt>run_latex_as_needed</tt>.
147
149
  =end
148
150
  def execute()
149
-
150
- cmd = "#{@program} #{@options.join ' '} " +
151
- #~ "-output-directory=#@full_output_dir
152
- " #{@basename}"
151
+
152
+ cmd = Rake4LaTeX.build_cmd( @program, :filename => @basename )
153
153
  Dir.chdir(@input_dir) do
154
154
  @texruns = 0
155
155
  while rerun_necessary?
@@ -159,7 +159,7 @@ The settings contain the following values:
159
159
  end
160
160
  end
161
161
  #Guarentee that help files are deleted fin clean.
162
- set4clean( @basename )
162
+ Rake4LaTeX.set4clean( @basename )
163
163
 
164
164
  plural_s = "#{@texruns} run#{@texruns>1 ? 's': ''}"
165
165
  if @rerun_necessary
@@ -191,7 +191,8 @@ The settings contain the following values:
191
191
  raise RuntimeError, "There where #@program errors. "\
192
192
  "See #{@main_file.ext('.log')} for details" unless @texerrors_allowed
193
193
  end
194
-
194
+
195
+ helpfiles = %w{aux toc lof lot}
195
196
  #Build the checksums.
196
197
  FileList["#{@basename.ext('*')}"].each do |file|
197
198
  # Compare old and new MD5 digest for the given file.
@@ -201,16 +202,30 @@ The settings contain the following values:
201
202
  @logger.debug("new file #{file}")
202
203
  checksums[file] = :changed
203
204
  when File.open(file){|f| MD5.new(f.read).hexdigest}
204
- @logger.debug("Unchanged file #{file}")
205
+ #no message needed
206
+ #~ @logger.debug("Unchanged file #{file}")
205
207
  else
206
208
  @logger.debug(" Changed file #{file}" )
207
209
  checksums[file] = :changed
208
210
  end
209
211
  }
212
+ #Special rules for additional files
213
+ case file
214
+ #Build by gloss.sty
215
+ when /#{@basename.ext()}\.(.+)\.aux/
216
+ gloss_name = $1
217
+ helpfiles << "#{$1}.aux"
218
+ @logger.debug("Detected additional aux-file <#{file}>" )
219
+ if ! Post_Prerequisites_check["#{gloss_name}.bbl"]
220
+ @logger.info("Define additional rule <#{gloss_name}.bbl> (gloss.sty)" )
221
+ Post_Prerequisites_check[".#{gloss_name}.bbl"] = Post_Prerequisites_check[".bbl"]
222
+ tex_postrule ".#{gloss_name}.bbl" => ".#{gloss_name}.aux"
223
+ end
224
+ end
210
225
  end
211
226
 
212
227
  #check changes in some files.
213
- %w{aux toc lof lot}.each{|ext|
228
+ helpfiles.each{|ext|
214
229
  next unless checksums[@basename.ext(ext)] == :changed
215
230
  @rerun_necessary = true
216
231
  @logger.info("Rerun necessary (#{ext}-file changed)" ) if @rerun_necessary
@@ -266,3 +281,4 @@ The settings contain the following values:
266
281
  end
267
282
 
268
283
  end #LaTeXRunner
284
+ end #Rake4LaTeX
@@ -0,0 +1,76 @@
1
+ bibtex:
2
+ cmd: bibtex
3
+ parameters:
4
+ - value_key: :source
5
+ dvipdfm:
6
+ cmd: dvipdfm
7
+ parameters:
8
+ - value_key: :filename
9
+ dvips:
10
+ cmd: dvips
11
+ parameters:
12
+ - value_key: :filename
13
+ latex:
14
+ cmd: latex
15
+ parameters:
16
+ - value: -interaction=batchmode
17
+ - name: -output-directory=
18
+ value_key: :output_dir
19
+ optional: true
20
+ - value_key: :filename
21
+ makeindex:
22
+ cmd: makeindex
23
+ parameters:
24
+ - name: -s
25
+ value_key: :format
26
+ optional: true
27
+ - name: -o
28
+ value_key: :file_out
29
+ optional: true
30
+ - name: -t
31
+ value_key: :file_log
32
+ optional: true
33
+ - value_key: :file_in
34
+ pdflatex:
35
+ cmd: pdflatex
36
+ parameters:
37
+ parameters:
38
+ - value: -interaction=batchmode
39
+ - name: -output-directory=
40
+ value_key: :output_dir
41
+ optional: true
42
+ - value_key: :filename
43
+ lualatex:
44
+ cmd: lualatex
45
+ parameters:
46
+ parameters:
47
+ - value: -interaction=batchmode
48
+ - name: -output-directory=
49
+ value_key: :output_dir
50
+ optional: true
51
+ - value_key: :filename
52
+ ps2pdf:
53
+ cmd: ps2pdf
54
+ parameters:
55
+ - value_key: :filename
56
+ rail:
57
+ cmd: C:/usr/texmf/tex/Latex/rail/rail.exe
58
+ comment:
59
+ - name: -t
60
+ value_key: :railfile
61
+ space_separated: true
62
+ comment: This command works only with 8 character filenames.
63
+ parameters:
64
+ - name: <
65
+ value_key: :railfile
66
+ space_separated: true
67
+ comment: With stdin we can use longer filenames. The processor must save the result as rao-file.
68
+ xelatex:
69
+ cmd: xelatex
70
+ parameters:
71
+ parameters:
72
+ - value: -interaction=batchmode
73
+ - name: -output-directory=
74
+ value_key: :output_dir
75
+ optional: true
76
+ - value_key: :filename
@@ -1,9 +1,36 @@
1
+ =begin rdoc
2
+ Collection of rules to build a LaTeX-project.
3
+
4
+ This file defines how to build:
5
+ * dvi (latex)
6
+ * ind (makeindex)
7
+ * bbl (BibTeX)
8
+ * ps (ps2pdf)
9
+
10
+ There is no definition how to create a pdf.
11
+ This may be done via different ways. You can select your version on your own:
12
+ * ../rake4latex_dvipdfm.rb
13
+ * ../rake4latex_lualatex.rb
14
+ * ../rake4latex_pdflatex.rb (Default)
15
+ * ../rake4latex_ps2pdf.rb
16
+ * ../rake4latex_xelatex.rb
17
+
18
+ =end
19
+
20
+ #
21
+ #Generate pdf-rules/files
22
+ #
23
+ #~ %w{xe lua}.each{|x|
24
+ #~ File.open("../rake4latex_#{x}latex.rb", 'w'){|f| f << File.read('../rake4latex_pdflatex.rb').gsub(/pdf(latex)/i, "#{x}\\1")}
25
+ #~ }
26
+ #~ Dir['../rake4latex_*'].each{|x| puts "* #{x}" }
27
+
28
+
1
29
  #Some Tools have screen output.
2
- #runtex should run silent in background, so we have to redirect the output.
30
+ #Rake4LaTeX should run silent in background, so we have to redirect the output.
3
31
  require 'catch_output'
4
32
  include Catch_output
5
33
 
6
-
7
34
  desc "Show compiled source in Adobe Acrobat Reader."
8
35
  task :acroread do |t|
9
36
  t.prerequisites.each{|pre|
@@ -17,7 +44,7 @@ desc "Set the basefile - needed for clean and statistic"
17
44
  task :basefile do |task|
18
45
  task.prerequisites.each{|pre|
19
46
  #~ puts "Set basefile #{pre.inspect}"
20
- set4clean( pre )
47
+ Rake4LaTeX.set4clean( pre )
21
48
  file :statistic => pre
22
49
  }
23
50
  task.reenable() #If not the second call for clean will not work.
@@ -37,7 +64,7 @@ end
37
64
 
38
65
  desc "Build a dvi-file with LaTeX"
39
66
  rule '.dvi' => '.tex' do |t|
40
- runner = LaTeXRunner.new(
67
+ runner = Rake4LaTeX::LaTeXRunner.new(
41
68
  :main_file => t.source,
42
69
  :program => :latex,
43
70
  :dummy => nil
@@ -45,24 +72,32 @@ rule '.dvi' => '.tex' do |t|
45
72
  runner.execute #Does all the work and calls the "post-prerequisites"
46
73
  end
47
74
 
48
- desc "Build a pdf-file with pdfLaTeX"
49
- rule '.pdf' => '.tex' do |t|
50
- runner = LaTeXRunner.new(
51
- :main_file => t.source,
52
- :program => :pdflatex,
53
- :dummy => nil
54
- )
55
- runner.execute #Does all the work and calls the "post-prerequisites"
75
+ desc "Build a ps-file from dvi"
76
+ rule '.ps' => '.dvi' do |t|
77
+ Rake4LaTeX::Logger.info("Call dvips for <#{t.source}>")
78
+ cmd = Rake4LaTeX.build_cmd( 'dvips', :filename => t.source )
79
+
80
+ stdout, stderr = catch_screen_output{
81
+ sh cmd
82
+ #stdout -> empty
83
+ #stderr -> log.
84
+ }
85
+ if $? != 0
86
+ Rake4LaTeX::Logger.fatal("There where dvips errors. \n#{stdout}")
87
+ end
56
88
  end
57
89
 
90
+
91
+
58
92
  desc "Call Makeindex"
59
93
  tex_postrule '.ind' => '.idx' do |t, args |
60
94
  #check for splitidx
61
- splitidx = Splitindex.new(t.source, Rake.application.latexrunner.logger)
95
+ splitidx = Rake4LaTeX::Splitindex.new(t.source, Rake4LaTeX::Logger)
62
96
  if splitidx.makeindex? #standard index, no splitidx
63
97
  #makeindex writes to stderr -> catch it
98
+ cmd = Rake4LaTeX.build_cmd( 'makeindex', :file_in => t.source )
64
99
  stdout, stderr = catch_screen_output{
65
- sh "makeindex #{t.source}"
100
+ sh cmd
66
101
  }
67
102
  else #splitidx used
68
103
  #call splitindex
@@ -85,6 +120,8 @@ tex_postrule_check '.bbl' do |args|
85
120
  if ( args[:checksums][auxfile] == :changed and File.read(auxfile) =~ /bibdata/ )
86
121
  necessary = "#{auxfile} changed"
87
122
  end
123
+ else
124
+ args[:logger].warn("\t#{auxfile} not found in bbl-precheck")
88
125
  end
89
126
  #Check all prerequisites.
90
127
  #This should be the aux-file and (optional) bib-files.
@@ -111,23 +148,58 @@ tex_postrule_check '.bbl' do |args|
111
148
  } unless necessary
112
149
  necessary #return parameter
113
150
  end
151
+
114
152
  #Define the rule
115
153
  tex_postrule '.bbl' => '.aux' do |t|
154
+ cmd = Rake4LaTeX.build_cmd( 'bibtex', :source => t.source )
116
155
  stdout, stderr = catch_screen_output{
117
- puts `bibtex #{t.source}`
156
+ puts `#{cmd}`
118
157
  }
119
158
  if $? != 0
120
- Rake.application.latexrunner.logger.fatal("There where BibTeX errors. \n#{stdout}")
159
+ Rake4LaTeX::Logger.fatal("There where BibTeX errors. \n#{stdout}")
121
160
  end
122
161
  end
123
162
 
124
- desc "Build a statistic for TeX project"
163
+ #Support for rail
164
+ #http://www.ctan.org/tex-archive/support/rail/
165
+ desc "Call Rail"
166
+ tex_postrule '.rao' => '.rai' do |t|
167
+ #Rail works only with filenames with 8 characters.
168
+ #So we use stdin.
169
+ cmd = Rake4LaTeX.build_cmd( 'rail', :railfile => t.source )
170
+ Rake4LaTeX::Logger.debug("Call rail: #{cmd}")
171
+ stdout, stderr = catch_screen_output{
172
+ puts `#{cmd}`
173
+ }
174
+ error = false
175
+ if $? != 0
176
+ Rake4LaTeX::Logger.fatal("There where Rail errors.")
177
+ error = true
178
+ end
179
+ stderr.each{|errline|
180
+ Rake4LaTeX::Logger.error("Rail error: #{errline.strip}")
181
+ error = true
182
+ }
183
+ if error
184
+ Rake4LaTeX::Logger.warn("No rail diagramms generated")
185
+ else
186
+ #Now we have to save the result and delete some stuff.
187
+ stdout.sub!(/^(This is Rail.*)/, '%\1') #%This is Rail, Version 1.1 #0
188
+ stdout.sub!(/^(\(stdin.*)/, '%\1')
189
+ stdout.sub!(/^\)/, '%\1)') #last line
190
+ File.open(t.source.ext('rao'), 'w'){|f| f << stdout }
191
+ end
192
+ end
125
193
 
194
+
195
+
196
+
197
+ desc "Build a statistic for TeX project"
126
198
  task :statistic => :basefile do |t|
127
199
  puts "Statistics:"
128
200
  t.prerequisites.each{|pre|
129
201
  next if pre == 'basefile' #exclude task :basefile
130
- stat = TeX_Statistic.new(pre)
202
+ stat = Rake4LaTeX::TeX_Statistic.new(pre)
131
203
  puts stat
132
204
  }
133
205
  end
@@ -1,3 +1,5 @@
1
+
2
+ module Rake4LaTeX
1
3
  #
2
4
  #Checks for a given idx-file if splitindx is used.
3
5
  #
@@ -55,8 +57,9 @@ class Splitindex
55
57
  #
56
58
  #Call makeindex for the given idx-file
57
59
  def call_makeindex( idxname )
60
+ cmd = Rake4LaTeX.build_cmd( 'makeindex', :file_in => idxname )
58
61
  stdout, stderr = catch_screen_output{
59
- puts `makeindex #{idxname}`
62
+ puts `#{cmd}`
60
63
  }
61
64
  if $? != 0
62
65
  @logger.fatal("There where Makeindex errors. for #{idxname}\n#{stderr}")
@@ -72,7 +75,7 @@ class Splitindex
72
75
  #~ idxnames
73
76
  #~ end
74
77
  end #Splitindex
75
-
78
+ end #Rake4LaTeX
76
79
  __END__
77
80
  #Get existing index-data first
78
81