erbtex 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.bundle/config +2 -0
- data/.gitignore +4 -1
- data/Gemfile.lock +40 -4
- data/README.org +137 -0
- data/Rakefile +10 -13
- data/bin/erbtex +3 -44
- data/erbtex.gemspec +11 -7
- data/examples/TrigTable.tex +3 -3
- data/examples/TrigTable2.tex +10 -6
- data/examples/{roots.tex → roots.tex.erb} +0 -0
- data/examples/{testbind.tex → testbind.tex.erb} +0 -0
- data/lib/erbtex/command_line.rb +79 -109
- data/lib/erbtex/runner.rb +163 -56
- data/lib/erbtex/version.rb +1 -1
- data/lib/erbtex.rb +8 -3
- data/spec/lib/command_line_spec.rb +146 -0
- data/spec/lib/find_executable_spec.rb +43 -0
- data/spec/spec_helper.rb +26 -0
- metadata +66 -31
- data/README.md +0 -127
- data/bin/etex +0 -49
- data/bin/latex +0 -49
- data/bin/lualatex +0 -49
- data/bin/luatex +0 -49
- data/bin/pdfetex +0 -49
- data/bin/pdflatex +0 -49
- data/bin/pdftex +0 -49
- data/bin/pslatex +0 -49
- data/bin/tex +0 -49
- data/bin/xelatex +0 -49
- data/bin/xetex +0 -49
- data/test/test_command_line.rb +0 -181
- data/test/test_find_executable.rb +0 -44
- data/test/test_helper.rb +0 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ba2d024e5db40939058098d4ee6cc9c3efa58c19
|
4
|
+
data.tar.gz: da8fc247a17a3e51ae2e8fa75a2f75eded1ace51
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2bd38f093f3703bf0c1c55b3a649044d776aa68b7ef6243ebcea344e4eaa4cdab0b2b872ac62bf94f910028c92019ede620467084d54c43fedfe43d824c45c7f
|
7
|
+
data.tar.gz: e44d3414536cb37057be45e48d28f7c7a599f8732ed8a5ee1db803e5e7e35ae08805b1b6f73e675c650edc5d2c962b485826e163111aed8d774dc695f27da4c7
|
data/.bundle/config
ADDED
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,25 +1,61 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
erbtex (0.
|
4
|
+
erbtex (0.3.0)
|
5
5
|
erubis
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
byebug (3.1
|
10
|
+
byebug (3.5.1)
|
11
11
|
columnize (~> 0.8)
|
12
12
|
debugger-linecache (~> 1.2)
|
13
|
-
|
13
|
+
slop (~> 3.6)
|
14
|
+
coderay (1.1.2)
|
15
|
+
columnize (0.9.0)
|
14
16
|
debugger-linecache (1.2.0)
|
17
|
+
diff-lcs (1.2.5)
|
15
18
|
erubis (2.7.0)
|
19
|
+
method_source (0.9.0)
|
20
|
+
minitest (5.5.0)
|
21
|
+
pry (0.11.3)
|
22
|
+
coderay (~> 1.1.0)
|
23
|
+
method_source (~> 0.9.0)
|
24
|
+
pry-byebug (3.0.1)
|
25
|
+
byebug (~> 3.4)
|
26
|
+
pry (~> 0.10)
|
27
|
+
pry-doc (0.11.1)
|
28
|
+
pry (~> 0.9)
|
29
|
+
yard (~> 0.9)
|
16
30
|
rake (10.3.2)
|
31
|
+
rspec (3.3.0)
|
32
|
+
rspec-core (~> 3.3.0)
|
33
|
+
rspec-expectations (~> 3.3.0)
|
34
|
+
rspec-mocks (~> 3.3.0)
|
35
|
+
rspec-core (3.3.1)
|
36
|
+
rspec-support (~> 3.3.0)
|
37
|
+
rspec-expectations (3.3.0)
|
38
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
39
|
+
rspec-support (~> 3.3.0)
|
40
|
+
rspec-mocks (3.3.1)
|
41
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
42
|
+
rspec-support (~> 3.3.0)
|
43
|
+
rspec-support (3.3.0)
|
44
|
+
slop (3.6.0)
|
45
|
+
yard (0.9.12)
|
17
46
|
|
18
47
|
PLATFORMS
|
19
48
|
ruby
|
20
49
|
|
21
50
|
DEPENDENCIES
|
22
51
|
bundler
|
23
|
-
byebug
|
24
52
|
erbtex!
|
53
|
+
minitest
|
54
|
+
pry
|
55
|
+
pry-byebug
|
56
|
+
pry-doc
|
25
57
|
rake
|
58
|
+
rspec
|
59
|
+
|
60
|
+
BUNDLED WITH
|
61
|
+
1.16.0
|
data/README.org
ADDED
@@ -0,0 +1,137 @@
|
|
1
|
+
* ErbTeX: Ruby pre-processing for TeX and LaTeX Documents
|
2
|
+
|
3
|
+
** Description
|
4
|
+
|
5
|
+
~erbtex~ is a ruby gem that provides a command line program that pre-processes
|
6
|
+
TeX and LaTeX source files with ruby's erubis and then passes the resulting file
|
7
|
+
along to a real TeX program.
|
8
|
+
|
9
|
+
** Installation
|
10
|
+
|
11
|
+
Install ~erbtex~ with:
|
12
|
+
|
13
|
+
#+BEGIN_SRC sh
|
14
|
+
gem install erbtex
|
15
|
+
#+END_SRC
|
16
|
+
|
17
|
+
** Usage
|
18
|
+
|
19
|
+
After the gem is installed, ~erbtex~ is placed in your PATH. ~erbtex~ recognizes
|
20
|
+
only one command-line option, --invoke=<tex_program>, which specifies what TeX
|
21
|
+
variant will process the TeX file after erubis has pre-proceesed the input file.
|
22
|
+
By default, ~erubis~ uses ~pdflatex~ if no --invoke option is given.
|
23
|
+
|
24
|
+
~Erbtex~ will then read the input file and execute any ruby code between the
|
25
|
+
special delimiters `{:` and `:}` instead of the erubis default of `<% %>`. The
|
26
|
+
brace-colon form of delimiters is less disruptive of syntax highlighting than
|
27
|
+
the default delimiters, which get confused with TeX and LaTeX comments. Any text
|
28
|
+
not between the delimiters is passed through untouched to the TeX program.
|
29
|
+
|
30
|
+
If the opening delimiter has an ~=~ appended to it, the delimited ruby
|
31
|
+
expression is converted into a string (with ruby's ~.to_s~ method) and inserted
|
32
|
+
in-place into the TeX manuscript at that point. For example, the text ~{:=
|
33
|
+
"Hello, world".reverse :}~ places the string ~'dlrow ,olleH'~ at that point in
|
34
|
+
the TeX file.
|
35
|
+
|
36
|
+
Without the `=` the ruby code is simply executed. You can use these, for
|
37
|
+
example, to ~require~ ruby libraries or to embed loops into the file.
|
38
|
+
|
39
|
+
Loops started in one ruby fragment can be continued or terminated in a later
|
40
|
+
fragment, and variables defined in one fragment in one fragment are visible in
|
41
|
+
later fragments according to Ruby's usual scoping rules. The result is that you
|
42
|
+
can use the ruby programming language to greatly increase the computational
|
43
|
+
capabilities of a normal TeX or LaTeX.
|
44
|
+
|
45
|
+
The resulting output is then processed as a normal TeX file.
|
46
|
+
|
47
|
+
** Example
|
48
|
+
|
49
|
+
For example, the following LaTeX file will produce a table of square
|
50
|
+
roots when run through erbtex. It uses a ruby iterator to supply the
|
51
|
+
rows of the table, a feat that would tedious at best with bare TeX or
|
52
|
+
LaTeX.
|
53
|
+
|
54
|
+
#+BEGIN_SRC latex
|
55
|
+
\documentclass{article}
|
56
|
+
\usepackage[mathbf]{euler}
|
57
|
+
\usepackage{longtable}
|
58
|
+
|
59
|
+
\begin{document}
|
60
|
+
\begin{longtable}[c]{r|r}
|
61
|
+
\hline\hline
|
62
|
+
\multicolumn{1}{c|}{\mathversion{bold}$x$}&
|
63
|
+
\multicolumn{1}{c}{\mathversion{bold}\rule{0pt}{12pt}$\sqrt{x}$}\\
|
64
|
+
\hline\hline
|
65
|
+
\endhead
|
66
|
+
\hline\hline
|
67
|
+
\endfoot
|
68
|
+
% The following line starts a ruby enumerator loop but does not
|
69
|
+
% produce any output, since the delimiters are {: :}.
|
70
|
+
{: 0.upto(100).each do |x| :}
|
71
|
+
% But the following two lines produce output since the opening delimiter is
|
72
|
+
% '{:='. Both call the sprintf method in ruby via the percent operator, and the
|
73
|
+
% second line calls ruby's Math module to compute the square root. Notice that
|
74
|
+
% the '%' inside the delimiters does not have the effect of commenting out
|
75
|
+
% the following text. It is interpreted as a ruby '%' operator.
|
76
|
+
|
77
|
+
{:= "\\mathversion{bold}$%0.4f$" % x :}&
|
78
|
+
{:= "$%0.8f$" % Math.sqrt(x) :}\\
|
79
|
+
{: end :}
|
80
|
+
\end{longtable}
|
81
|
+
\end{document}
|
82
|
+
#+END_SRC
|
83
|
+
|
84
|
+
With the above in file `roots.tex`, running `$ erbtex roots.tex` at the command
|
85
|
+
line will generate a `PDF` file with a nicely typeset table of square roots.
|
86
|
+
|
87
|
+
As a by-product, the pre-processed file ~roots.etx~ is left in the same
|
88
|
+
directory, so you can see what the effect of the erbtex fragments were. This is
|
89
|
+
often very handy when you are trying to debug the document; otherwise, feel free
|
90
|
+
to delete it. Here, for example is a portion of the `roots.etx` file generated
|
91
|
+
by the foregoing:
|
92
|
+
|
93
|
+
#+BEGIN_SRC latex
|
94
|
+
\begin{document}
|
95
|
+
\begin{longtable}[c]{r|r}
|
96
|
+
\hline\hline
|
97
|
+
\multicolumn{1}{c|}{\mathversion{bold}$x$}&
|
98
|
+
\multicolumn{1}{c}{\mathversion{bold}\rule{0pt}{12pt}$\sqrt{x}$}\\
|
99
|
+
\hline\hline
|
100
|
+
\endhead
|
101
|
+
\hline\hline
|
102
|
+
\endfoot
|
103
|
+
\mathversion{bold}$0.0000$&
|
104
|
+
$0.00000000$\\
|
105
|
+
\mathversion{bold}$1.0000$&
|
106
|
+
$1.00000000$\\
|
107
|
+
\mathversion{bold}$2.0000$&
|
108
|
+
$1.41421356$\\
|
109
|
+
\mathversion{bold}$3.0000$&
|
110
|
+
$1.73205081$\\
|
111
|
+
\mathversion{bold}$4.0000$&
|
112
|
+
$2.00000000$\\
|
113
|
+
\mathversion{bold}$5.0000$&
|
114
|
+
$2.23606798$\\
|
115
|
+
\mathversion{bold}$6.0000$&
|
116
|
+
$2.44948974$\\
|
117
|
+
\mathversion{bold}$7.0000$&
|
118
|
+
$2.64575131$\\
|
119
|
+
\mathversion{bold}$8.0000$&
|
120
|
+
$2.82842712$\\
|
121
|
+
\mathversion{bold}$9.0000$&
|
122
|
+
$3.00000000$\\
|
123
|
+
\mathversion{bold}$10.0000$&
|
124
|
+
$3.16227766$\\
|
125
|
+
\mathversion{bold}$11.0000$&
|
126
|
+
$3.31662479$\\
|
127
|
+
\mathversion{bold}$12.0000$&
|
128
|
+
$3.46410162$\\
|
129
|
+
\mathversion{bold}$13.0000$&
|
130
|
+
$3.60555128$\\
|
131
|
+
\mathversion{bold}$14.0000$&
|
132
|
+
#+END_SRC
|
133
|
+
|
134
|
+
And many more lines like it.
|
135
|
+
|
136
|
+
The examples directory installed with the erbtex gem has a few more
|
137
|
+
examples.
|
data/Rakefile
CHANGED
@@ -1,15 +1,12 @@
|
|
1
|
-
require '
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
require 'rdoc/task'
|
2
4
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
task :default => :test
|
7
|
-
desc "Run all the unit tests"
|
8
|
-
task :test do
|
9
|
-
Dir.foreach('test') do |t|
|
10
|
-
next if t == 'test_helper.rb'
|
11
|
-
next if t =~ /^\.\.?/
|
12
|
-
cmd = "ruby -I 'test' -C 'test' #{t}"
|
13
|
-
system cmd
|
14
|
-
end
|
5
|
+
RDoc::Task.new do |rdoc|
|
6
|
+
rdoc.main = 'README.rdoc'
|
7
|
+
rdoc.rdoc_files.include('README.rdoc', 'lib')
|
15
8
|
end
|
9
|
+
|
10
|
+
RSpec::Core::RakeTask.new(:spec)
|
11
|
+
|
12
|
+
task default: :spec
|
data/bin/erbtex
CHANGED
@@ -1,49 +1,8 @@
|
|
1
1
|
#! /usr/bin/env ruby
|
2
2
|
|
3
|
-
verbose = true
|
4
|
-
|
5
|
-
# This adds our lib subdirectory to the ruby load path
|
6
|
-
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
|
7
|
-
|
8
|
-
# This adds our RUBYLIB env to ruby load path
|
9
|
-
if ENV['RUBYLIB']
|
10
|
-
STDERR.puts "ENV['RUBYLIB']:" if verbose
|
11
|
-
ENV['RUBYLIB'].split(':').each do |p|
|
12
|
-
$LOAD_PATH.unshift p
|
13
|
-
STDERR.puts "\t#{p}" if verbose
|
14
|
-
end
|
15
|
-
else
|
16
|
-
STDERR.puts "ENV['RUBYLIB'] is EMPTY" if verbose
|
17
|
-
end
|
18
|
-
|
19
3
|
require 'erbtex'
|
20
4
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
if a =~ /\s/
|
25
|
-
a = "'" + a + "'"
|
26
|
-
end
|
27
|
-
commandline += " #{a}"
|
5
|
+
module ErbTeX
|
6
|
+
cl = CommandLine.new(ARGV)
|
7
|
+
exit ErbTeX.run(cl).exitstatus
|
28
8
|
end
|
29
|
-
|
30
|
-
if verbose
|
31
|
-
STDERR.puts "Program name: #{progname}"
|
32
|
-
STDERR.puts "Command line: #{commandline}"
|
33
|
-
STDERR.puts "Ruby Load path:"
|
34
|
-
$:.each do |p|
|
35
|
-
STDERR.puts "\t#{p}"
|
36
|
-
end
|
37
|
-
STDERR.puts 'ARGV:'
|
38
|
-
ARGV.each do |a|
|
39
|
-
STDERR.puts "\t#{a}"
|
40
|
-
end
|
41
|
-
STDERR.puts 'PATH:'
|
42
|
-
ENV['PATH'].split(':').each do |p|
|
43
|
-
STDERR.puts "\t#{p}"
|
44
|
-
end
|
45
|
-
STDERR.puts "Executable: "
|
46
|
-
STDERR.puts ErbTeX.find_executable($0)
|
47
|
-
end
|
48
|
-
|
49
|
-
ErbTeX.run(commandline)
|
data/erbtex.gemspec
CHANGED
@@ -7,8 +7,8 @@ Gem::Specification.new do |gem|
|
|
7
7
|
gem.version = ErbTeX::VERSION
|
8
8
|
gem.platform = Gem::Platform::RUBY
|
9
9
|
gem.date = %q{2012-05-13}
|
10
|
-
gem.homepage =
|
11
|
-
gem.authors = [
|
10
|
+
gem.homepage = ''
|
11
|
+
gem.authors = ['Daniel E. Doherty']
|
12
12
|
gem.email = %q{ded-erbtex@ddoherty.net}
|
13
13
|
gem.summary = %q{Preprocesses TeX and LaTeX files with erubis for ruby.}
|
14
14
|
gem.description = %q{Create a local link called pdflatex to erbtex and it will
|
@@ -17,13 +17,17 @@ Gem::Specification.new do |gem|
|
|
17
17
|
automated TeX and LaTeX documents.}
|
18
18
|
|
19
19
|
gem.files = `git ls-files`.split("\n")
|
20
|
-
gem.files.delete_if {|f| f =~
|
20
|
+
gem.files.delete_if { |f| f =~ /\.(log|etc|aux|etx|pdf|gem|tmp)$/ }
|
21
21
|
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
22
22
|
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
23
|
-
gem.require_paths = [
|
23
|
+
gem.require_paths = ['lib']
|
24
24
|
|
25
|
-
gem.add_dependency
|
25
|
+
gem.add_dependency 'erubis'
|
26
26
|
gem.add_development_dependency 'rake'
|
27
|
-
gem.add_development_dependency
|
28
|
-
gem.add_development_dependency
|
27
|
+
gem.add_development_dependency 'bundler'
|
28
|
+
gem.add_development_dependency 'rspec'
|
29
|
+
gem.add_development_dependency 'minitest'
|
30
|
+
gem.add_development_dependency 'pry'
|
31
|
+
gem.add_development_dependency 'pry-doc'
|
32
|
+
gem.add_development_dependency 'pry-byebug'
|
29
33
|
end
|
data/examples/TrigTable.tex
CHANGED
@@ -10,9 +10,9 @@
|
|
10
10
|
\usepackage{fancyhdr}
|
11
11
|
\pagestyle{fancy}
|
12
12
|
\renewcommand{\headrulewidth}{0pt}
|
13
|
-
\
|
14
|
-
\
|
15
|
-
\
|
13
|
+
\setlength{\headheight}{14.0pt}
|
14
|
+
\lhead{\large\mathversion{bold}$\firstmark$}
|
15
|
+
\rhead{\large\mathversion{bold}$\botmark$}
|
16
16
|
|
17
17
|
\begin{document}
|
18
18
|
|
data/examples/TrigTable2.tex
CHANGED
@@ -9,10 +9,10 @@
|
|
9
9
|
%% flipping pages.
|
10
10
|
\usepackage{fancyhdr}
|
11
11
|
\pagestyle{fancy}
|
12
|
+
\setlength{\headheight}{14.0pt}
|
12
13
|
\renewcommand{\headrulewidth}{0pt}
|
13
|
-
\
|
14
|
-
\
|
15
|
-
\lhead{}
|
14
|
+
\lhead{\large\mathversion{bold}\firstmark}
|
15
|
+
\rhead{\large\mathversion{bold}\botmark}
|
16
16
|
|
17
17
|
\begin{document}
|
18
18
|
|
@@ -30,6 +30,8 @@
|
|
30
30
|
end
|
31
31
|
:}
|
32
32
|
|
33
|
+
\def\tstrut{\rule[-1pt]{0pt}{11pt}}
|
34
|
+
|
33
35
|
%% Set up the longtable environment by specifying the header for
|
34
36
|
%% each page and the footer.
|
35
37
|
\begin{longtable}[c]{c|llllll}
|
@@ -63,7 +65,7 @@
|
|
63
65
|
|
64
66
|
%% Treat the first line of the table, for an x value of 0 specially
|
65
67
|
%% by giving exact answers in symbolic form.
|
66
|
-
{:= "\\multicolumn{1}{c|}{{\\mathversion{bold}\\mark{%s}$0$}}" % d0.to_tex :}&
|
68
|
+
{:= "\\multicolumn{1}{c|}{\\tstrut{\\mathversion{bold}\\mark{%s}$0$}}" % d0.to_tex :}&
|
67
69
|
{:= "\\multicolumn{1}{c}{{$0$}}" :}&
|
68
70
|
{:= "\\multicolumn{1}{c}{{$1$}}" :}&
|
69
71
|
{:= "\\multicolumn{1}{c}{{$0$}}" :}&
|
@@ -84,7 +86,7 @@
|
|
84
86
|
{:
|
85
87
|
## Here is where each line of the main body of the table is set.
|
86
88
|
## We use the digs function defined above to make sure that every
|
87
|
-
## column
|
89
|
+
## column has the same number of significant digits for the functions
|
88
90
|
## that tend toward infinity.
|
89
91
|
##
|
90
92
|
## NB: I could write this comment as a LaTeX comment outside a code
|
@@ -94,7 +96,7 @@
|
|
94
96
|
## around 2MB.
|
95
97
|
-:}
|
96
98
|
\mark{{:= x.to_tex :}}
|
97
|
-
{:= "\\mathversion{bold}#{x.to_tex}" :}&
|
99
|
+
\tstrut{:= "\\mathversion{bold}#{x.to_tex}" :}&
|
98
100
|
{:= "$%0.8f$" % x.sin :}&
|
99
101
|
{:= "$%0.8f$" % x.cos :}&
|
100
102
|
{:= "$%0.*f$" % [ digs(tanx), tanx ] :}&
|
@@ -127,3 +129,5 @@
|
|
127
129
|
%% End the table and document---this version comes to 649 pages!
|
128
130
|
\end{longtable}
|
129
131
|
\end{document}
|
132
|
+
|
133
|
+
% Take /that/ Charles Babbage!
|
File without changes
|
File without changes
|
data/lib/erbtex/command_line.rb
CHANGED
@@ -4,136 +4,106 @@ module ErbTeX
|
|
4
4
|
class NoInputFile < StandardError; end
|
5
5
|
|
6
6
|
class CommandLine
|
7
|
-
attr_reader :
|
8
|
-
attr_reader :
|
9
|
-
|
10
|
-
def initialize(command_line)
|
11
|
-
@command_line = command_line
|
12
|
-
@input_file = @marked_command_line = nil
|
13
|
-
@run_dir = Dir.pwd
|
14
|
-
find_output_dir
|
15
|
-
find_progname
|
16
|
-
find_input_file
|
17
|
-
find_input_path
|
18
|
-
mark_command_line
|
19
|
-
end
|
7
|
+
attr_reader :erbtex_name, :tex_program, :tex_options
|
8
|
+
attr_reader :tex_commands, :input_file
|
20
9
|
|
21
|
-
def
|
22
|
-
|
23
|
-
|
10
|
+
def initialize(argv)
|
11
|
+
# Note: argv will be the command line arguments after processing by the
|
12
|
+
# shell, so if we see things such as '&', '~', '\' in the args, these were
|
13
|
+
# quoted by the user on the command-line and need no special treatment
|
14
|
+
# here. For example, '~/junk' on the commandline will show up here as
|
15
|
+
# '/home/ded/junk'. If we see '~/junk', that means the user has quoted the
|
16
|
+
# ~ on the command line with something like '\~junk', so we should assume
|
17
|
+
# that the user wants to keep it that way. Likewise, an arg with spaces in
|
18
|
+
# it will have been quoted by the user to be seen as a single argument.
|
19
|
+
# When we output these for use by the shell in the system command, we
|
20
|
+
# should apply shellquote to everything so that the receiving shell sees
|
21
|
+
# the args in the same way.
|
24
22
|
|
25
|
-
|
26
|
-
|
27
|
-
#
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
# Found -output-directory on last pass without an equals sign
|
36
|
-
out_dir = a
|
37
|
-
end
|
38
|
-
if a =~ /^--?output-d(irectory)?=(\S+)/
|
39
|
-
out_dir = $2
|
40
|
-
elsif a =~ /^--?output-d(irectory)?$/
|
41
|
-
# Next arg is the out_dir
|
42
|
-
have_out_dir = true
|
43
|
-
end
|
44
|
-
end
|
45
|
-
if out_dir.nil?
|
46
|
-
if File.writable?(Dir.pwd)
|
47
|
-
@output_dir = Dir.pwd
|
48
|
-
else
|
49
|
-
@output_dir = File.expand_path(ENV['TEXMFOUTPUT'])
|
50
|
-
end
|
51
|
-
else
|
52
|
-
@output_dir = File.expand_path(out_dir)
|
23
|
+
@erbtex_name = File.basename($0)
|
24
|
+
|
25
|
+
# Find the tex_commands
|
26
|
+
@tex_commands = []
|
27
|
+
if argv.any? { |a| a =~ /\A\\/ }
|
28
|
+
# All args after first starting with '\' should be interpreted as TeX
|
29
|
+
# commands, even if they don't start with '\'
|
30
|
+
@tex_commands = argv.drop_while { |a| a !~ /\A\\/ }
|
31
|
+
first_tex_command_k = argv.size - @tex_commands.size
|
32
|
+
argv = argv[0..first_tex_command_k - 1]
|
53
33
|
end
|
54
|
-
end
|
55
34
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
if cmd =~ infile_re
|
62
|
-
@input_file = "#{$2}"
|
63
|
-
if @input_file =~ /\.tex(\.erb)?$/
|
64
|
-
@input_file = @input_file
|
65
|
-
else
|
66
|
-
@input_file += ".tex"
|
67
|
-
end
|
68
|
-
elsif cmd =~ %r{(\\input\s+)?(["'])((?:\\?.)*?)\2} #"
|
69
|
-
# The re above captures single- or double-quoted strings with
|
70
|
-
# the insides in $3
|
71
|
-
@input_file = "#{$3}"
|
72
|
-
if @input_file !~ /\.tex$/
|
73
|
-
@input_file += ".tex#{$1}"
|
74
|
-
end
|
75
|
-
else
|
76
|
-
@input_file = nil
|
35
|
+
# Look for our --invoke=tex_command option
|
36
|
+
@tex_program = 'pdflatex'
|
37
|
+
if argv.any? { |a| a =~ /\A--invoke=(\w+)/ }
|
38
|
+
@tex_program = $1
|
39
|
+
argv.reject! { |a| a =~ /\A--invoke=(\w+)/ }
|
77
40
|
end
|
78
|
-
end
|
79
41
|
|
80
|
-
|
81
|
-
#
|
82
|
-
if
|
83
|
-
@
|
84
|
-
elsif @input_file.nil?
|
85
|
-
@input_path = nil
|
86
|
-
else
|
87
|
-
# The following cribbed from kpathsea.rb
|
88
|
-
@progname.untaint
|
89
|
-
@input_file.untaint
|
90
|
-
kpsewhich = "kpsewhich -progname=\"#{@progname}\" -format=\"tex\" \"#{@input_file}\""
|
91
|
-
lines = ""
|
92
|
-
IO.popen(kpsewhich) do |io|
|
93
|
-
lines = io.readlines
|
94
|
-
end
|
95
|
-
if $? == 0
|
96
|
-
@input_path = lines[0].chomp.untaint
|
97
|
-
else
|
98
|
-
raise NoInputFile, "Can't find #{@input_file} in TeX search path; try kpsewhich -format=tex #{@input_file}."
|
99
|
-
end
|
42
|
+
# The last argument, assuming it does not start with a '-' or '&', is
|
43
|
+
# assumed to be the name of the input_file.
|
44
|
+
if !argv.empty? && argv[-1] !~ /\A[-&]/
|
45
|
+
@input_file = CommandLine.expand_input_file(argv.pop)
|
100
46
|
end
|
47
|
+
|
48
|
+
# What remains in argv should be the tex program's '-options', which
|
49
|
+
# should be passed through untouched. So, can form the full command line
|
50
|
+
# for tex_processing
|
51
|
+
@tex_options = argv.dup
|
101
52
|
end
|
102
53
|
|
103
|
-
def
|
104
|
-
|
105
|
-
#
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
ncl
|
54
|
+
def tex_command(tex_file = input_file)
|
55
|
+
"#{tex_program} " \
|
56
|
+
"#{tex_options.shelljoin} " \
|
57
|
+
"#{tex_commands.shelljoin} " \
|
58
|
+
"#{tex_file}"
|
59
|
+
.strip.squeeze(' ')
|
110
60
|
end
|
111
61
|
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
if
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
62
|
+
# Return the name of the input file based on the name given in the command
|
63
|
+
# line. Try to find the right extension for the input file if none is given.
|
64
|
+
def self.expand_input_file(input_file)
|
65
|
+
full_ext = input_file[/\A(.*)(\.[\w.]+)\z/, 2]
|
66
|
+
if full_ext.nil? || full_ext.empty?
|
67
|
+
if File.exist?("#{input_file}.tex.erb")
|
68
|
+
"#{input_file}.tex.erb"
|
69
|
+
elsif File.exist?("#{input_file}.tex")
|
70
|
+
"#{input_file}.tex"
|
71
|
+
elsif File.exist?("#{input_file}.erb")
|
72
|
+
"#{input_file}.erb"
|
73
|
+
else
|
74
|
+
input_file
|
75
|
+
end
|
122
76
|
else
|
123
|
-
|
77
|
+
input_file
|
124
78
|
end
|
125
|
-
# Replace progname with '^p^'
|
126
|
-
@marked_command_line = @marked_command_line.lstrip
|
127
|
-
@marked_command_line = @marked_command_line.sub(/\S+/, '^p^')
|
128
79
|
end
|
129
80
|
end
|
130
81
|
end
|
131
82
|
|
132
83
|
# NOTES:
|
133
|
-
|
134
84
|
# The following text is from the Web2C documentation at
|
135
85
|
# http://tug.org/texinfohtml/web2c.html#Output-file-location
|
136
86
|
#
|
87
|
+
# 4.1 TeX invocation
|
88
|
+
#
|
89
|
+
# TeX, Metafont, and MetaPost process the command line (described here)
|
90
|
+
# and determine their memory dump (fmt) file in the same way (*note Memory
|
91
|
+
# dumps::). Synopses:
|
92
|
+
#
|
93
|
+
# tex [OPTION]... [TEXNAME[.tex]] [TEX-COMMANDS]
|
94
|
+
# tex [OPTION]... \FIRST-LINE
|
95
|
+
# tex [OPTION]... &FMT ARGS
|
96
|
+
#
|
97
|
+
# TeX searches the usual places for the main input file TEXNAME (*note
|
98
|
+
# (kpathsea)Supported file formats::), extending TEXNAME with '.tex' if
|
99
|
+
# necessary. To see all the relevant paths, set the environment variable
|
100
|
+
# 'KPATHSEA_DEBUG' to '-1' before running the program.
|
101
|
+
#
|
102
|
+
# After TEXNAME is read, TeX processes any remaining TEX-COMMANDS on
|
103
|
+
# the command line as regular TeX input. Also, if the first non-option
|
104
|
+
# argument begins with a TeX escape character (usually '\'), TeX processes
|
105
|
+
# all non-option command-line arguments as a line of regular TeX input.
|
106
|
+
|
137
107
|
# 3.4 Output file location
|
138
108
|
#
|
139
109
|
# All the programs generally follow the usual convention for output
|