rake4latex 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/{lib/call_rake4latex.rb → call_rake4latex.rb} +21 -9
- data/lib/rake4latex.rb +113 -180
- data/lib/rake4latex/base.rb +205 -0
- data/lib/rake4latex/clean.rb +53 -0
- data/lib/rake4latex/latexdependencies.rb +2 -0
- data/lib/rake4latex/latexrunner.rb +31 -15
- data/lib/rake4latex/rake4latex.yaml +76 -0
- data/lib/rake4latex/rules.rb +90 -18
- data/lib/rake4latex/splitindex.rb +5 -2
- data/lib/rake4latex/template.rb +60 -0
- data/lib/rake4latex/tex_statistic.rb +8 -3
- data/lib/rake4latex_dvipdfm.rb +40 -0
- data/lib/rake4latex_lualatex.rb +22 -0
- data/lib/rake4latex_pdflatex.rb +22 -0
- data/lib/rake4latex_ps2pdf.rb +27 -0
- data/lib/rake4latex_xelatex.rb +22 -0
- data/license.txt +15 -0
- data/readme.html +70 -23
- data/readme.txt +58 -18
- data/readme_call_rake4latex.txt +25 -0
- data/test/_expected/bibtex_test.txt +10 -0
- data/test/_expected/bibtex_test_bib.txt +5 -0
- data/test/_expected/dvipdfm_test.txt +7 -0
- data/test/_expected/gloss_test.txt +16 -0
- data/test/_expected/gloss_test_bib.txt +8 -0
- data/test/_expected/includes_test.txt +8 -0
- data/test/_expected/index_test.txt +7 -0
- data/test/_expected/longtable_test.txt +6 -0
- data/test/_expected/minitoc_test.txt +8 -0
- data/test/_expected/ps2pdf_test.txt +8 -0
- data/test/_expected/rail_test.txt +7 -0
- data/test/_expected/rail_test_error.txt +10 -0
- data/test/_expected/splitindex_test.txt +8 -0
- data/test/_expected/supertabular_test.txt +6 -0
- data/test/_expected/supertabular_test_statistic.txt +30 -0
- data/test/_expected/z_complex_test.txt +12 -0
- data/test/_test_call/test_call.rb +14 -0
- data/test/_test_call/testdocument.tex +18 -0
- data/test/bibtex/rakefile.rb +11 -5
- data/test/bibtex/testdocument.bib +1 -0
- data/test/dvipdfm/rakefile.rb +43 -0
- data/test/dvipdfm/testdocument.tex +10 -0
- data/test/gloss/rakefile.rb +65 -0
- data/test/gloss/test_gloss.bib +4 -0
- data/test/gloss/testdocument.tex +31 -0
- data/test/includes/rakefile.rb +4 -4
- data/test/index/rakefile.rb +1 -1
- data/test/longtable/rakefile.rb +1 -1
- data/test/ps2pdf/rakefile.rb +43 -0
- data/test/ps2pdf/testdocument.tex +10 -0
- data/test/rail/rakefile.rb +10 -19
- data/test/rail/testrail.tex +2 -6
- data/test/rail/testrail_error.tex +58 -0
- data/test/supertabular/rakefile.rb +1 -1
- data/test/unittest_rake4latex.rb +66 -0
- data/test/z_complex/rakefile.rb +2 -2
- metadata +64 -6
@@ -18,6 +18,7 @@ search path for executable files.
|
|
18
18
|
=end
|
19
19
|
|
20
20
|
require 'rake4latex'
|
21
|
+
#~ Dir.chdir('lib'){ require 'rake4latex' }
|
21
22
|
require 'optparse'
|
22
23
|
|
23
24
|
#Anlegen des Parsers
|
@@ -30,7 +31,7 @@ opts.separator "call_rake4latex testdocument.pdf"
|
|
30
31
|
opts.separator " Create testdocument.pdf via pdflatex"
|
31
32
|
opts.separator " Starts only if testdocument.tex is newer then testdocument.pdf."
|
32
33
|
opts.separator ""
|
33
|
-
opts.separator "call_rake4latex -
|
34
|
+
opts.separator "call_rake4latex -e testdocument"
|
34
35
|
opts.separator " Touch 'testdocument.tex' (set the modification date)"
|
35
36
|
opts.separator " Create testdocument.pdf via pdflatex"
|
36
37
|
opts.separator ""
|
@@ -44,23 +45,29 @@ TASK_AFTER_TeX = []
|
|
44
45
|
PARSE_MESSAGES = true
|
45
46
|
|
46
47
|
|
48
|
+
#
|
49
|
+
#fixme: format
|
47
50
|
=begin
|
48
51
|
Shortcuts
|
49
52
|
=end
|
50
|
-
opts.on('-
|
51
|
-
TASK_BEFORE_TeX << :
|
53
|
+
opts.on('-e', "--enforce", "Enforce an initial TeX-run") { |v|
|
54
|
+
TASK_BEFORE_TeX << :enforce
|
55
|
+
}
|
56
|
+
|
57
|
+
opts.on('-f', "--format FORMAT", "Set the format for TeX-run (pdflatex, xelatex, lualatex)") { |v|
|
58
|
+
Rake4LaTeX.set_latexrunner_default(:program, v.to_sym)
|
52
59
|
}
|
53
60
|
|
54
61
|
#
|
55
62
|
#fixme:
|
56
63
|
#Warum gibt es immer einen TeX-Lauf mit dieser Option?
|
57
64
|
#
|
58
|
-
opts.on('
|
65
|
+
opts.on('--dep', "--dependecies", "Build dependecies (rakefile recommended)") { |v|
|
59
66
|
TASK_BEFORE_TeX << :dependecies
|
60
67
|
}
|
61
68
|
opts.on("-i", "--ignore", "--ignore-error", "Allow LaTeX errors") { |v|
|
62
69
|
puts "Allow LaTeX errors" if PARSE_MESSAGES
|
63
|
-
|
70
|
+
Rake4LaTeX.set_latexrunner_default(:texerrors_allowed, true)
|
64
71
|
}
|
65
72
|
|
66
73
|
opts.on("-s", "--statistic", "Show the statistic after TeX-run") { |v|
|
@@ -102,13 +109,17 @@ LaTeXRunner-options
|
|
102
109
|
#
|
103
110
|
opts.on("--maxrun MAXRUN", "Maximum MAXRUN TeX calls") { |v|
|
104
111
|
puts "Set maximum TeX-Runs #{v.inspect}" if PARSE_MESSAGES
|
105
|
-
|
112
|
+
Rake4LaTeX.set_latexrunner_default(:maxruns, v.to_i)
|
106
113
|
#~ LaTeXRunner::DEFAULT_SETTINGS[:maxruns] =
|
107
114
|
}
|
108
115
|
|
109
116
|
opts.on("-l", "--loglevel LEVEL", "Log Level for the logger (1=debug, 2=info(default), 3=warn 4=error)") { |v|
|
110
117
|
puts "Set loglevel to #{v.inspect}" if PARSE_MESSAGES
|
111
|
-
|
118
|
+
Rake4LaTeX.set_latexrunner_default(:loglevel, v.to_i)
|
119
|
+
}
|
120
|
+
|
121
|
+
opts.on("-v", "--version", "Version") { |v|
|
122
|
+
puts "Rake4LaTeX-Caller Version #{Rake4LaTeX::VERSION}"
|
112
123
|
}
|
113
124
|
|
114
125
|
|
@@ -119,10 +130,10 @@ begin
|
|
119
130
|
ARGV.each{|arg|
|
120
131
|
target = arg.ext('pdf')
|
121
132
|
puts "Define target #{target}"
|
122
|
-
set4clean(arg)
|
133
|
+
Rake4LaTeX.set4clean(arg)
|
123
134
|
TASK_BEFORE_TeX.each{|task|
|
124
135
|
case task
|
125
|
-
when :
|
136
|
+
when :enforce
|
126
137
|
puts "Force an initial TeX-run (touch #{target.ext('tex')})" if PARSE_MESSAGES
|
127
138
|
task (:touch => target.ext('tex'))
|
128
139
|
task (:default => :touch)
|
@@ -139,6 +150,7 @@ begin
|
|
139
150
|
end
|
140
151
|
}
|
141
152
|
task( :default => target )
|
153
|
+
puts "call_rake4latex tries to generate #{target}"
|
142
154
|
}
|
143
155
|
rescue OptionParser::MissingArgument, OptionParser::InvalidOption => err
|
144
156
|
puts "Error:\t#{err}"
|
data/lib/rake4latex.rb
CHANGED
@@ -24,11 +24,47 @@ A not-so minimal rakefile looks like this:
|
|
24
24
|
app[:default].invoke
|
25
25
|
end
|
26
26
|
|
27
|
-
You can generate
|
27
|
+
You can generate a rakefile template with:
|
28
28
|
require 'rake4latex'
|
29
29
|
puts Rake4LaTeX.template( [basename] )
|
30
30
|
|
31
|
-
|
31
|
+
===call_rake4latex.rb
|
32
|
+
When you think, your project is too small to create a rakefile,
|
33
|
+
then try call_rake4latex.rb.
|
34
|
+
|
35
|
+
call_rake4latex.rb is a small programm where you can control
|
36
|
+
rake4latex from your shell.
|
37
|
+
|
38
|
+
Example:
|
39
|
+
call_rake4latex.rb my_file
|
40
|
+
call_rake4latex.rb -e my_file
|
41
|
+
|
42
|
+
===rake4latex as lib in your application
|
43
|
+
|
44
|
+
You can use rake4latex as a lib inside your application.
|
45
|
+
|
46
|
+
Example:
|
47
|
+
require 'rake4latex'
|
48
|
+
task :touch => 'testdocument.tex'
|
49
|
+
task :runtex => [:touch, 'testdocument.pdf', :clean]
|
50
|
+
Rake.application[:runtex].invoke
|
51
|
+
#~ task :basefile => 'testdocument.pdf'
|
52
|
+
#~ Rake.application[:clean].invoke
|
53
|
+
|
54
|
+
==Document creation
|
55
|
+
rake4latex defines the tasks and rules to build documents with LaTeX.
|
56
|
+
|
57
|
+
pdf can be created in different ways.
|
58
|
+
rake4latex uses pdflatex, but there are other rake-profile to
|
59
|
+
create your pdf in different ways:
|
60
|
+
* rake4latex_dvipdfm.rb
|
61
|
+
* rake4latex_lualatex.rb
|
62
|
+
* rake4latex_pdflatex.rb
|
63
|
+
* rake4latex_ps2pdf.rb
|
64
|
+
* rake4latex_xelatex.rb
|
65
|
+
|
66
|
+
|
67
|
+
===Multiple runs
|
32
68
|
One of the problems with writing a Makefile for LaTeX is that often latex needs
|
33
69
|
to be run more than once on the same file, before obtaining the final output.
|
34
70
|
Moreover, every LaTeX package may require other runs basing on different conditions
|
@@ -89,7 +125,7 @@ BibTeX depends on two files:
|
|
89
125
|
You can define the dependecies of bib-file in your rakefile:
|
90
126
|
file 'testdocument.pdf' => 'testdocument.bib'
|
91
127
|
file 'testdocument.bbl' => 'testdocument.bib'
|
92
|
-
You need both
|
128
|
+
You need both definitions.
|
93
129
|
The pdf-dependecy is needed to start a new TeX-run,
|
94
130
|
The bbl-dependecy is needed to start a new BibTeX-run.
|
95
131
|
|
@@ -104,15 +140,19 @@ The following tools are supported by rake4latex:
|
|
104
140
|
The rake process to generate the document is independent of any
|
105
141
|
package.
|
106
142
|
But some packages requires additional TeX-runs.
|
143
|
+
|
107
144
|
The following packages are tested and work fine:
|
108
145
|
* minitoc
|
109
146
|
* longtable
|
110
147
|
* supertabular
|
111
|
-
* splitindex (splitindex is replaced by internal routines)
|
112
148
|
|
113
|
-
|
114
|
-
*
|
115
|
-
|
149
|
+
For the following packages exists special solutions:
|
150
|
+
* splitindex (splitindex is replaced by internal routines)
|
151
|
+
http://www.ctan.org/tex-archive/macros/latex/contrib/splitindex/
|
152
|
+
* gloss (glossary based on bibTeX)
|
153
|
+
http://www.ctan.org/tex-archive/macros/latex/contrib/gloss/
|
154
|
+
* rail (creating rail-diagramms)
|
155
|
+
http://www.ctan.org/tex-archive/support/rail/
|
116
156
|
|
117
157
|
==Adding new tasks
|
118
158
|
===Normal tasks
|
@@ -165,196 +205,89 @@ We need a modified pre-check, if the BibTeX-call is necessary:
|
|
165
205
|
See also section 'Multiple runs'
|
166
206
|
|
167
207
|
==Known Bugs and Problems
|
168
|
-
*
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
208
|
+
* Two runs for new documents, when only one is needed.
|
209
|
+
|
210
|
+
After the first run, the aux-file is created,
|
211
|
+
so rake4latex detect a reason to rerun.
|
212
|
+
Solution would be to make a log-file analyse.
|
213
|
+
* No plan to solve it.
|
214
|
+
Not a big problem, and why you need a rakefile for such simple tex-files?
|
215
|
+
|
216
|
+
* No usage of kpsewhich.
|
217
|
+
|
178
218
|
LaTeXDependencies#get_dependecies checks dependecies only relative to
|
179
219
|
the file location.
|
180
220
|
kpsewhich is not used.
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
=end
|
185
|
-
|
186
|
-
<<weiter
|
187
|
-
fixmes
|
188
|
-
== weiterer Aufbau rake abh�ngigkeiten
|
189
|
-
- glossary
|
190
|
-
rule '.glo' => '.aux' '.glo' do |t|
|
191
|
-
(glossaries?)
|
192
|
-
|
193
|
-
==task statistic/log-analyse
|
221
|
+
* Would be nice escpecially for BibTeX and scan for \bibliography{xxx}
|
222
|
+
* Low priority
|
194
223
|
|
195
|
-
|
224
|
+
===Packages with problems
|
225
|
+
There are additional packages requiring additonal runs.
|
196
226
|
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
#~ app.set_latexrunner_default(:texerrors_allowed, true)
|
202
|
-
app[:default].invoke
|
227
|
+
* glossaries (glossary based on makeindex) - support not planned.
|
228
|
+
* multiind/index (multiple index) - support not planned.
|
229
|
+
Please use splitindex or inform me about your need.
|
230
|
+
* rail (rail syntax diagramms) - see tests, the rakefile includes the solution.
|
203
231
|
|
204
|
-
rail �berarbeiten
|
205
232
|
|
206
|
-
Compilierungswege dvi -> ps -> pdf
|
207
233
|
|
208
|
-
prob:
|
209
|
-
wie erkennen ob
|
210
|
-
- dvi2ps + ps2pdf
|
211
|
-
- dvipdfm
|
212
|
-
|
213
|
-
weiter
|
214
|
-
|
215
|
-
|
216
|
-
#~ ==Problems
|
217
|
-
#~ * the action which checks for changed references causes a second latex invocation
|
218
|
-
#~ every time the .aux file changes.
|
219
|
-
#~ I don't know enough of the contents of the
|
220
|
-
#~ .aux file to parse it, but I need to base the decision on it, because messages
|
221
|
-
#~ such as "rerun to get cross-references right" in the latex log file aren't
|
222
|
-
#~ reliable (for example, the when the hyperref package is used, they aren't
|
223
|
-
#~ produced)
|
224
|
-
|
225
|
-
require 'log4r'
|
226
|
-
#Create a dummy-Logger to define the constants Log4r::DEBUG...
|
227
|
-
|
228
|
-
Log4r::Logger.new("test")
|
229
|
-
#~ gem 'rake', '=0.8.7'
|
230
|
-
require 'rake'
|
231
|
-
require 'md5'
|
232
|
-
|
233
|
-
class Rake::Application
|
234
|
-
=begin rdoc
|
235
|
-
Sets a default option for the LaTeXRunner.
|
236
|
-
|
237
|
-
The options are stored and used for new LaTeXRunners.
|
238
|
-
|
239
|
-
Example:
|
240
|
-
app.set_latexrunner_default(:loglevel, Log4r::DEBUG)
|
241
|
-
|
242
|
-
You could also access LaTeXRunner::DEFAULT_SETTINGS directly.
|
243
|
-
But with this method you get also a check if the option exists.
|
244
234
|
=end
|
245
|
-
def set_latexrunner_default( key, option )
|
246
|
-
if ! LaTeXRunner::DEFAULT_SETTINGS.keys.include?(key)
|
247
|
-
raise ArgumentError, "Undefined key #{key.inspect} for LaTeXRunner" unless @latexrunner
|
248
|
-
@latexrunner.logger.warn("Undefined key #{key.inspect} for LaTeXRunner")
|
249
|
-
end
|
250
|
-
LaTeXRunner::DEFAULT_SETTINGS[key] = option
|
251
|
-
end
|
252
|
-
=begin rdoc
|
253
|
-
Get the related actual LaTeXRunner.
|
254
|
-
=end
|
255
|
-
attr_reader :latexrunner
|
256
|
-
=begin rdoc
|
257
|
-
Define a LaTeXRunner.
|
258
235
|
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
raise ArgumentError, "LaTeXRunner is no LaTeXRunner but #{t.class}" unless latexrunner.is_a?(LaTeXRunner)
|
263
|
-
if @latexrunner
|
264
|
-
@latexrunner.logger.warn( "LaTeXRunner replaced by other runner")
|
265
|
-
end
|
266
|
-
@latexrunner = latexrunner
|
267
|
-
@latexrunner.logger.debug( "Set LaTeXRunner #{@latexrunner.main_file} as default runner in Rake::Application")
|
268
|
-
end
|
269
|
-
end #Rake::Application
|
270
|
-
|
271
|
-
=begin rdoc
|
272
|
-
Define the files to be deleted with clean and clobber.
|
273
|
-
|
274
|
-
There is no global definition to delete all files,
|
275
|
-
only the help file for the selected basename is taken.
|
276
|
-
|
277
|
-
Helpfiles for splitindex are not added. You can do it manual:
|
278
|
-
CLEAN.add("testdocument-*") #splitidx-helpfiles
|
279
|
-
|
280
|
-
This method is called by task 'basename'
|
281
|
-
=end
|
282
|
-
def set4clean( basename )
|
283
|
-
#fixme splitindex-dateien
|
284
|
-
FileList["#{basename.ext('*')}"].each do |file|
|
285
|
-
#Set the cleaning actions
|
286
|
-
case file
|
287
|
-
when /\.(tex)\Z/
|
288
|
-
when /\.(aux|log|out|toc|lot|lof|nav|snm)\Z/
|
289
|
-
CLEAN.include(file)
|
290
|
-
when /\.(maf|ptc\d*|mtc\d*|stc\d*)\Z/ #minitoc
|
291
|
-
CLEAN.include(file)
|
292
|
-
when /\.(ilg|idx|ind)\Z/ #Index-Files
|
293
|
-
CLEAN.include(file)
|
294
|
-
when /\.(blg|bbl)\Z/ #BibTeX-Files
|
295
|
-
CLEAN.include(file)
|
296
|
-
when /\.(rai|rao|RAO)\Z/ #Rail-Files
|
297
|
-
CLEAN.include(file)
|
298
|
-
when /\.(dvi|pdf|ps)\Z/
|
299
|
-
CLOBBER.include(file)
|
300
|
-
else
|
301
|
-
#~ @logger.warn("Unknown help file #{file}")
|
302
|
-
end
|
303
|
-
end
|
304
|
-
CLEAN.uniq!
|
305
|
-
CLOBBER.uniq!
|
306
|
-
end
|
307
|
-
|
308
|
-
=begin rdoc
|
309
|
-
Define a task to be executed after each TeX run.
|
310
|
-
|
311
|
-
The task name is added to LaTeXRunner::Post_Prerequisites.
|
312
|
-
LaTeXRunner#run_latex_once will loop on all tasks in LaTeXRunner::Post_Prerequisites.
|
313
|
-
=end
|
314
|
-
def tex_postrule(*args, &block)
|
315
|
-
#~ rules = rule(*args, &block)
|
316
|
-
Rake::Task.create_rule(*args, &block) #@rules << [pattern, deps, block]
|
317
|
-
#
|
318
|
-
if args.size == 1 #normal rule without arguments
|
319
|
-
LaTeXRunner::Post_Prerequisites << args.first.keys.first
|
320
|
-
else #rule with arguments (args.last is a hash with :needs)
|
321
|
-
LaTeXRunner::Post_Prerequisites << args.first
|
322
|
-
end
|
323
|
-
end
|
324
|
-
=begin rdoc
|
325
|
-
Define a procedure to decide, if the post process should be
|
326
|
-
called.
|
327
|
-
|
328
|
-
The task name is added to LaTeXRunner::Post_Prerequisites_check.
|
329
|
-
LaTeXRunner#run_latex_once will loop on all tasks in LaTeXRunner::Post_Prerequisites_check.
|
330
|
-
|
331
|
-
The block will be called with a hash, the block must accept this one parameter.
|
236
|
+
<<weiter
|
237
|
+
fixmes
|
238
|
+
- glossaries
|
332
239
|
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
* :logger: the logger of the related task
|
240
|
+
task statistic/log-analyse ausbauen.
|
241
|
+
task pack unpack logarchive
|
242
|
+
weiter
|
337
243
|
|
338
|
-
|
244
|
+
#
|
245
|
+
#Load the base functions and load subfiles.
|
246
|
+
#
|
247
|
+
require 'rake4latex/base'
|
339
248
|
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
249
|
+
#
|
250
|
+
#Define the pdf-creation via pdflatex
|
251
|
+
#
|
252
|
+
#This definition maust be first.
|
253
|
+
#If not, the way via ps2pdf would be the default.
|
254
|
+
desc "Build a pdf-file with pdfLaTeX"
|
255
|
+
rule '.pdf' => '.tex' do |t|
|
256
|
+
runner = Rake4LaTeX::LaTeXRunner.new(
|
257
|
+
:main_file => t.source,
|
258
|
+
#~ :program => :pdflatex, #Take the default
|
259
|
+
:dummy => nil
|
260
|
+
)
|
261
|
+
runner.execute #Does all the work and calls the "post-prerequisites"
|
346
262
|
end
|
347
263
|
|
348
264
|
#
|
349
|
-
#
|
265
|
+
#Define the pdf-creation via dvips ps2dvi
|
266
|
+
#
|
267
|
+
#To get the pdf via dvips and ps2dvi you must build the dependecies
|
268
|
+
# file testfile.ps => testfile.tex
|
269
|
+
# file testfile.pdf => testfile.ps
|
350
270
|
#
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
271
|
+
#If you define
|
272
|
+
# file testfile.pdf => testfile.tex
|
273
|
+
#you get the way via pdflatex.
|
274
|
+
#
|
275
|
+
#Or you take rake4latex_ps2pdf
|
276
|
+
#
|
277
|
+
desc "Build a pdf-file via ps2dvi"
|
278
|
+
rule '.pdf' => '.ps' do |t|
|
279
|
+
t.application.latexrunner.logger.info("Call ps2pdf for <#{t.source}>") if t.application.latexrunner
|
280
|
+
cmd = Rake4LaTeX.build_cmd( 'ps2pdf', :filename => t.source )
|
281
|
+
|
282
|
+
stdout, stderr = catch_screen_output{
|
283
|
+
sh "ps2pdf #{t.source}"
|
284
|
+
#stdout -> empty
|
285
|
+
#stderr -> "ps2pdf testdocument.ps"
|
286
|
+
}
|
287
|
+
if $? != 0
|
288
|
+
t.application.latexrunner.logger.fatal("There where ps2pdf errors. \n#{stdout}")
|
289
|
+
end
|
290
|
+
end
|
358
291
|
|
359
292
|
|
360
293
|
#Do some development tests
|
@@ -0,0 +1,205 @@
|
|
1
|
+
=begin rdoc
|
2
|
+
Base definitions of rake4latex.
|
3
|
+
This file must be loaded by all specific rake4file-variants.
|
4
|
+
=end
|
5
|
+
|
6
|
+
|
7
|
+
#~ gem 'rake', '=0.8.7'
|
8
|
+
require 'rake'
|
9
|
+
require 'md5'
|
10
|
+
require 'log4r' #1.0.5
|
11
|
+
|
12
|
+
module Rake4LaTeX
|
13
|
+
VERSION = '0.1.0'
|
14
|
+
|
15
|
+
#With this creation we define the constants Log4r::DEBUG...
|
16
|
+
Logger = Log4r::Logger.new("LaTeXRunner")
|
17
|
+
Logger.outputters = Log4r::StdoutOutputter.new('log_stdout')
|
18
|
+
|
19
|
+
=begin rdoc
|
20
|
+
Sets a default option for the LaTeXRunner.
|
21
|
+
|
22
|
+
The options are stored and used for new LaTeXRunners.
|
23
|
+
|
24
|
+
Examples:
|
25
|
+
Rake4LaTeX.set_latexrunner_default(:maxruns, 1)
|
26
|
+
Rake4LaTeX.set_latexrunner_default(:loglevel, Log4r::DEBUG)
|
27
|
+
Rake4LaTeX.set_latexrunner_default(:program, xelatex)
|
28
|
+
Rake4LaTeX.set_latexrunner_default(:texerrors_allowed, true)
|
29
|
+
|
30
|
+
You could also access LaTeXRunner::DEFAULT_SETTINGS directly.
|
31
|
+
But with this method you get also a check if the option exists.
|
32
|
+
=end
|
33
|
+
def self.set_latexrunner_default( key, option )
|
34
|
+
if ! LaTeXRunner::DEFAULT_SETTINGS.keys.include?(key)
|
35
|
+
raise ArgumentError, "Undefined key #{key.inspect} for LaTeXRunner" unless @latexrunner
|
36
|
+
Rake4LaTeX::Logger.warn("Undefined key #{key.inspect} for LaTeXRunner") if Rake4LaTeX::Logger.warn?
|
37
|
+
end
|
38
|
+
LaTeXRunner::DEFAULT_SETTINGS[key] = option
|
39
|
+
case key
|
40
|
+
when :program
|
41
|
+
if LaTeXRunner::PROGRAMS.keys.include?( option.to_sym )
|
42
|
+
LaTeXRunner::DEFAULT_SETTINGS[key] = option.to_sym
|
43
|
+
else
|
44
|
+
Rake4LaTeX::Logger.warn("Undefined programm #{option.inspect} for LaTeXRunner") if Rake4LaTeX::Logger.warn?
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
=begin rdoc
|
50
|
+
Load the Programs with parameters for Rake4LaTeX.build_cmd.
|
51
|
+
|
52
|
+
Each program is a Hash:
|
53
|
+
program:
|
54
|
+
cmd: shell-cmd
|
55
|
+
parameters:
|
56
|
+
value: value as textstring
|
57
|
+
name: name of the parameter
|
58
|
+
value_key: key of the value, must be given to Rake4LaTeX.build_cmd
|
59
|
+
optional: flag, if the parameter is optional.
|
60
|
+
space_separated: between name and value is a space.
|
61
|
+
=end
|
62
|
+
|
63
|
+
#fixme: incremental reading: global + local overwrites
|
64
|
+
[
|
65
|
+
"#{File.dirname(__FILE__)}/rake4latex.yaml",
|
66
|
+
#ocra-settings:
|
67
|
+
#a src\lib\rake4latex\rake4latex.yaml
|
68
|
+
#a lib\ruby\gems\1.8\gems\rake4latex-0.1.0\lib\rake4latex\base.rb
|
69
|
+
"#{File.dirname(__FILE__)}/../../../../../../../../src/lib/rake4latex/rake4latex.yaml", #for ocra-version (exe)
|
70
|
+
].each{| setting_file |
|
71
|
+
if File.exist?(setting_file)
|
72
|
+
Programms = YAML.load(File.read(setting_file))
|
73
|
+
break
|
74
|
+
end
|
75
|
+
}
|
76
|
+
if ! defined? Programms
|
77
|
+
raise "No program settings found"
|
78
|
+
end
|
79
|
+
|
80
|
+
|
81
|
+
=begin rdoc
|
82
|
+
Build the command line to call a tool.
|
83
|
+
|
84
|
+
Bases is the configuration in Programms.
|
85
|
+
|
86
|
+
'parameters' contains the parameters for the call.
|
87
|
+
The keys must fit to the settings in Rake4LaTeX::Programms .
|
88
|
+
=end
|
89
|
+
def self.build_cmd( programm, parameters = {} )
|
90
|
+
|
91
|
+
configuration = Programms[programm]
|
92
|
+
if ! configuration
|
93
|
+
Rake4LaTeX::Logger.fatal( "No configuration for #{programm.inspect}") if Rake4LaTeX::Logger.fatal?
|
94
|
+
return false
|
95
|
+
end
|
96
|
+
|
97
|
+
cmd = configuration['cmd'].dup
|
98
|
+
configuration['parameters'].each{ | parameter |
|
99
|
+
cmd << " #{parameter['value']}" if parameter['value']
|
100
|
+
if parameter['value_key']
|
101
|
+
if parameters[parameter['value_key']]
|
102
|
+
cmd << " "
|
103
|
+
cmd << "#{parameter['name']}" if parameter['name']
|
104
|
+
cmd << " " if parameter['space_separated']
|
105
|
+
cmd << "#{parameters[parameter['value_key']]}"
|
106
|
+
else
|
107
|
+
if ! parameter['optional'] and Rake4LaTeX::Logger.error?
|
108
|
+
Rake4LaTeX::Logger.error( "Parameter #{parameter['value_key'].inspect} missing to execute #{programm}")
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
}#configuration['parameters']
|
113
|
+
|
114
|
+
cmd
|
115
|
+
end
|
116
|
+
=begin rdoc
|
117
|
+
Define the files to be deleted with clean and clobber.
|
118
|
+
|
119
|
+
There is no global definition to delete all files,
|
120
|
+
only the help file for the selected basename is taken.
|
121
|
+
|
122
|
+
Helpfiles for splitindex are not added. You can do it manual:
|
123
|
+
CLEAN.add("testdocument-*") #splitidx-helpfiles
|
124
|
+
|
125
|
+
This method is called by task 'basename'
|
126
|
+
=end
|
127
|
+
def self.set4clean( basename )
|
128
|
+
#fixme splitindex-dateien
|
129
|
+
FileList["#{basename.ext('*')}"].each do |file|
|
130
|
+
#Set the cleaning actions
|
131
|
+
case file
|
132
|
+
when /\.(tex)\Z/
|
133
|
+
when /\.(aux|log|out|toc|lot|lof|nav|snm)\Z/
|
134
|
+
CLEAN.include(file)
|
135
|
+
when /\.(maf|ptc\d*|mtc\d*|stc\d*)\Z/ #minitoc
|
136
|
+
CLEAN.include(file)
|
137
|
+
when /\.(ilg|idx|ind)\Z/ #Index-Files
|
138
|
+
CLEAN.include(file)
|
139
|
+
when /\.(blg|bbl)\Z/ #BibTeX-Files
|
140
|
+
CLEAN.include(file)
|
141
|
+
when /\.(rai|rao|RAO)\Z/ #Rail-Files
|
142
|
+
CLEAN.include(file)
|
143
|
+
when /\.(dvi|pdf|ps)\Z/
|
144
|
+
CLOBBER.include(file)
|
145
|
+
else
|
146
|
+
#~ @logger.warn("Unknown help file #{file}")
|
147
|
+
end
|
148
|
+
end
|
149
|
+
CLEAN.uniq!
|
150
|
+
CLOBBER.uniq!
|
151
|
+
end #set4clean
|
152
|
+
|
153
|
+
end #Rake4LaTeX
|
154
|
+
|
155
|
+
|
156
|
+
=begin rdoc
|
157
|
+
Define a task to be executed after each TeX run.
|
158
|
+
|
159
|
+
The task name is added to LaTeXRunner::Post_Prerequisites.
|
160
|
+
LaTeXRunner#run_latex_once will loop on all tasks in LaTeXRunner::Post_Prerequisites.
|
161
|
+
=end
|
162
|
+
def tex_postrule(*args, &block)
|
163
|
+
#~ rules = rule(*args, &block)
|
164
|
+
Rake::Task.create_rule(*args, &block) #@rules << [pattern, deps, block]
|
165
|
+
#
|
166
|
+
if args.size == 1 #normal rule without arguments
|
167
|
+
Rake4LaTeX::LaTeXRunner::Post_Prerequisites << args.first.keys.first
|
168
|
+
else #rule with arguments (args.last is a hash with :needs)
|
169
|
+
Rake4LaTeX::LaTeXRunner::Post_Prerequisites << args.first
|
170
|
+
end
|
171
|
+
end
|
172
|
+
=begin rdoc
|
173
|
+
Define a procedure to decide, if the post process should be
|
174
|
+
called.
|
175
|
+
|
176
|
+
The task name is added to LaTeXRunner::Post_Prerequisites_check.
|
177
|
+
LaTeXRunner#run_latex_once will loop on all tasks in LaTeXRunner::Post_Prerequisites_check.
|
178
|
+
|
179
|
+
The block will be called with a hash, the block must accept this one parameter.
|
180
|
+
|
181
|
+
Inside the block you have access to:
|
182
|
+
* :task: The task for which you test.
|
183
|
+
* :checksums: the checksums of the files before the TeX-run.
|
184
|
+
* :logger: the logger of the related task
|
185
|
+
|
186
|
+
The block must return false or the reason for a call (e.g. "testdocument.aux changed")
|
187
|
+
|
188
|
+
Example: See BibTeX-definition.
|
189
|
+
=end
|
190
|
+
def tex_postrule_check(rulename, &block)
|
191
|
+
raise "No block for postrule_check #{rulename}" unless block_given?
|
192
|
+
raise "Wrong number of arguments for postrule_check #{rulename}" unless block.arity == 1
|
193
|
+
Rake4LaTeX::LaTeXRunner::Post_Prerequisites_check[rulename] ||= [] << block
|
194
|
+
end
|
195
|
+
|
196
|
+
#
|
197
|
+
#Load the sub-files
|
198
|
+
#
|
199
|
+
require 'rake4latex/clean' #modified rake/clean
|
200
|
+
require 'rake4latex/latexrunner'
|
201
|
+
require 'rake4latex/latexdependencies'
|
202
|
+
require 'rake4latex/splitindex'
|
203
|
+
require 'rake4latex/rules'
|
204
|
+
require 'rake4latex/tex_statistic'
|
205
|
+
require 'rake4latex/template'
|