erbtex 0.3.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: ba2d024e5db40939058098d4ee6cc9c3efa58c19
4
- data.tar.gz: da8fc247a17a3e51ae2e8fa75a2f75eded1ace51
2
+ SHA256:
3
+ metadata.gz: 73e049b2407795a0ba4acd0b5e0bb7f962c072695ba245f6a42d12b96bdfea41
4
+ data.tar.gz: e15af14509ec54c2fbc4fc4bfadb75d5ff04a0a74b5fb4e1b581cd4d1abae978
5
5
  SHA512:
6
- metadata.gz: 2bd38f093f3703bf0c1c55b3a649044d776aa68b7ef6243ebcea344e4eaa4cdab0b2b872ac62bf94f910028c92019ede620467084d54c43fedfe43d824c45c7f
7
- data.tar.gz: e44d3414536cb37057be45e48d28f7c7a599f8732ed8a5ee1db803e5e7e35ae08805b1b6f73e675c650edc5d2c962b485826e163111aed8d774dc695f27da4c7
6
+ metadata.gz: bc69c3a51c63e9514e3fba20a05df2a567328235440e07d49ac612d08c902ac994a1a9687f4916d07b59a51c77c2d98073f2839ad0473ff9594ec62a7fa7e67d
7
+ data.tar.gz: 60e4929df42ca88888703ccb57d2a424ed5120d9ed1c25bd4f0feece9ee16878eb1fdd6118ffd0ddc2a9aee49c8133bf1a311ba5934b4c03139e7c610f6f6fc4
data/Gemfile.lock CHANGED
@@ -1,48 +1,58 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- erbtex (0.3.0)
4
+ erbtex (0.4.1)
5
5
  erubis
6
+ fat_core
6
7
 
7
8
  GEM
8
9
  remote: https://rubygems.org/
9
10
  specs:
10
- byebug (3.5.1)
11
- columnize (~> 0.8)
12
- debugger-linecache (~> 1.2)
13
- slop (~> 3.6)
11
+ activesupport (5.2.3)
12
+ concurrent-ruby (~> 1.0, >= 1.0.2)
13
+ i18n (>= 0.7, < 2)
14
+ minitest (~> 5.1)
15
+ tzinfo (~> 1.1)
16
+ byebug (11.0.1)
14
17
  coderay (1.1.2)
15
- columnize (0.9.0)
16
- debugger-linecache (1.2.0)
17
- diff-lcs (1.2.5)
18
+ concurrent-ruby (1.1.5)
19
+ damerau-levenshtein (1.3.1)
20
+ diff-lcs (1.3)
18
21
  erubis (2.7.0)
19
- method_source (0.9.0)
20
- minitest (5.5.0)
21
- pry (0.11.3)
22
+ fat_core (4.5.0)
23
+ activesupport
24
+ damerau-levenshtein
25
+ i18n (1.6.0)
26
+ concurrent-ruby (~> 1.0)
27
+ method_source (0.9.2)
28
+ minitest (5.11.3)
29
+ pry (0.12.2)
22
30
  coderay (~> 1.1.0)
23
31
  method_source (~> 0.9.0)
24
- pry-byebug (3.0.1)
25
- byebug (~> 3.4)
32
+ pry-byebug (3.7.0)
33
+ byebug (~> 11.0)
26
34
  pry (~> 0.10)
27
- pry-doc (0.11.1)
28
- pry (~> 0.9)
29
- yard (~> 0.9)
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)
35
+ pry-doc (1.0.0)
36
+ pry (~> 0.11)
37
+ yard (~> 0.9.11)
38
+ rake (12.3.2)
39
+ rspec (3.8.0)
40
+ rspec-core (~> 3.8.0)
41
+ rspec-expectations (~> 3.8.0)
42
+ rspec-mocks (~> 3.8.0)
43
+ rspec-core (3.8.0)
44
+ rspec-support (~> 3.8.0)
45
+ rspec-expectations (3.8.3)
38
46
  diff-lcs (>= 1.2.0, < 2.0)
39
- rspec-support (~> 3.3.0)
40
- rspec-mocks (3.3.1)
47
+ rspec-support (~> 3.8.0)
48
+ rspec-mocks (3.8.0)
41
49
  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)
50
+ rspec-support (~> 3.8.0)
51
+ rspec-support (3.8.0)
52
+ thread_safe (0.3.6)
53
+ tzinfo (1.2.5)
54
+ thread_safe (~> 0.1)
55
+ yard (0.9.19)
46
56
 
47
57
  PLATFORMS
48
58
  ruby
@@ -58,4 +68,4 @@ DEPENDENCIES
58
68
  rspec
59
69
 
60
70
  BUNDLED WITH
61
- 1.16.0
71
+ 1.17.3
data/README.org CHANGED
@@ -2,9 +2,9 @@
2
2
 
3
3
  ** Description
4
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.
5
+ ~erbtex~ is a ruby gem that provides the ~erbtex~ command line program that
6
+ pre-processes TeX and LaTeX source files with ruby's [[http://www.kuwata-lab.com/erubis][erubis]] and then passes
7
+ the resulting file along to a real TeX program.
8
8
 
9
9
  ** Installation
10
10
 
@@ -16,35 +16,40 @@ Install ~erbtex~ with:
16
16
 
17
17
  ** Usage
18
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.
19
+ After the gem is installed, ~erbtex~ is placed in your PATH. ~erbtex~
20
+ recognizes only one command-line option, ~--invoke=<tex_program>~, which
21
+ specifies what TeX variant will process the TeX file after erubis has
22
+ pre-proceesed the input file. By default, ~erbtex~ uses ~pdflatex~ if no
23
+ --invoke option is given.
23
24
 
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.
25
+ ~Erbtex~ reads the input file and executes any ruby code between the special
26
+ delimiters ~{:~ and ~:}~. This brace-colon form of delimiters is less
27
+ disruptive of syntax highlighting than ~erubis~'s default delimiters ~<%~ and
28
+ ~%>~ delimiters, which often get confused by syntax-enabled editors with TeX
29
+ and LaTeX comments.
29
30
 
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.
31
+ If the opening delimiter is instead ~{:=~, the delimited ruby expression is
32
+ converted into a string (with ruby's ~.to_s~ method) and inserted in-place
33
+ into the TeX manuscript at that point. For example, the text ~{:= "Hello,
34
+ world".reverse :}~ places the string ~dlrow ,olleH~ at that point in the TeX
35
+ file.
35
36
 
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.
37
+ Any text /not/ enclosed in these delimiters is passed through untouched to the
38
+ TeX program.
38
39
 
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
40
+ Without the `=` the ruby code is simply executed. You can use these, for
41
+ example, to ~require~ ruby libraries or to embed loops into the file. Loops
42
+ started in one delimited ruby fragment can be continued or terminated in a
43
+ later fragment, and variables defined in one fragment are accessible in later
44
+ fragments according to Ruby's usual scoping rules. The result is that you can
45
+ use the ruby programming language to greatly increase the computational
43
46
  capabilities of a normal TeX or LaTeX.
44
47
 
45
- The resulting output is then processed as a normal TeX file.
48
+ You can get the version with the --version flag and help with --help.
46
49
 
47
- ** Example
50
+ ** Examples
51
+
52
+ *** Square Roots
48
53
 
49
54
  For example, the following LaTeX file will produce a table of square
50
55
  roots when run through erbtex. It uses a ruby iterator to supply the
@@ -68,6 +73,7 @@ LaTeX.
68
73
  % The following line starts a ruby enumerator loop but does not
69
74
  % produce any output, since the delimiters are {: :}.
70
75
  {: 0.upto(100).each do |x| :}
76
+
71
77
  % But the following two lines produce output since the opening delimiter is
72
78
  % '{:='. Both call the sprintf method in ruby via the percent operator, and the
73
79
  % second line calls ruby's Math module to compute the square root. Notice that
@@ -76,19 +82,20 @@ LaTeX.
76
82
 
77
83
  {:= "\\mathversion{bold}$%0.4f$" % x :}&
78
84
  {:= "$%0.8f$" % Math.sqrt(x) :}\\
85
+
86
+ % End of the loop started above.
79
87
  {: end :}
80
- \end{longtable}
88
+ \end{longtable}
81
89
  \end{document}
82
90
  #+END_SRC
83
91
 
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
+ With the above in file ~roots.tex~, running ~$ erbtex roots.tex~ at the
93
+ command line will generate a `PDF` file with a nicely typeset table of square
94
+ roots. The generated pdf file can be seen [[file:examples/roots.pdf][here]]. As a by-product, the
95
+ pre-processed file ~roots.etx~ is left in the same directory, so you can see
96
+ what the effect of the erbtex fragments were. This is often very handy when
97
+ you are trying to debug the document; otherwise, feel free to delete it. Here,
98
+ for example is a portion of the `roots.etx` file generated by the foregoing:
92
99
 
93
100
  #+BEGIN_SRC latex
94
101
  \begin{document}
@@ -133,5 +140,8 @@ by the foregoing:
133
140
 
134
141
  And many more lines like it.
135
142
 
143
+ *** Trigonometry Table
144
+
136
145
  The examples directory installed with the erbtex gem has a few more
137
- examples.
146
+ examples, including a [[file:examples/TrigTable2.pdf][large trigonometry table]] generated from a relatively
147
+ small [[file:examples/TrigTable2.tex][input file]].
data/erbtex.gemspec CHANGED
@@ -23,6 +23,7 @@ Gem::Specification.new do |gem|
23
23
  gem.require_paths = ['lib']
24
24
 
25
25
  gem.add_dependency 'erubis'
26
+ gem.add_dependency 'fat_core'
26
27
  gem.add_development_dependency 'rake'
27
28
  gem.add_development_dependency 'bundler'
28
29
  gem.add_development_dependency 'rspec'
@@ -56,10 +56,10 @@
56
56
  ## increments of step
57
57
 
58
58
  require 'bigdecimal'
59
- step = BigDecimal.new("0.001")
59
+ step = BigDecimal("0.001")
60
60
  one = BigDecimal("1.0")
61
61
  z0 = BigDecimal("0.0")
62
- p2 = BigDecimal.new((Math::PI / 2.0).to_s)
62
+ p2 = BigDecimal((Math::PI / 2.0).to_s)
63
63
  -:}
64
64
 
65
65
  %% Treat the first line of the table, for an x value of 0 specially
@@ -76,10 +76,10 @@
76
76
  %% x one step beyond 0 and pre-computes some of the functions
77
77
  {: x = z0 + step
78
78
  while (x < p2) do
79
- tanx = BigDecimal.new(Math.tan(x).to_s)
80
- cotx = one / BigDecimal.new(Math.tan(x).to_s)
81
- secx = one / BigDecimal.new(Math.cos(x).to_s)
82
- cscx = one / BigDecimal.new(Math.sin(x).to_s)
79
+ tanx = BigDecimal(Math.tan(x).to_s)
80
+ cotx = one / BigDecimal(Math.tan(x).to_s)
81
+ secx = one / BigDecimal(Math.cos(x).to_s)
82
+ cscx = one / BigDecimal(Math.sin(x).to_s)
83
83
  :}
84
84
 
85
85
  {:
@@ -122,4 +122,4 @@
122
122
 
123
123
  %% End the table and document---this version comes to 315 pages!
124
124
  \end{longtable}
125
- \end{document}
125
+ \end{document}
File without changes
File without changes
@@ -1,26 +1,28 @@
1
- # -*- coding: utf-8 -*-
1
+ # coding: utf-8
2
2
 
3
+ # Name space for erbtex command.
3
4
  module ErbTeX
4
5
  class NoInputFile < StandardError; end
5
6
 
7
+ # Class to record and manipulate the command line typed by the user.
6
8
  class CommandLine
7
- attr_reader :erbtex_name, :tex_program, :tex_options
8
- attr_reader :tex_commands, :input_file
9
+ attr_reader :erbtex_name, :tex_program, :tex_args, :tex_commands
10
+ attr_reader :input_file, :print_version, :print_help
9
11
 
10
12
  def initialize(argv)
11
13
  # 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.
22
-
23
- @erbtex_name = File.basename($0)
14
+ # shell, so if we see things such as '&', '~', '\' in the args, these
15
+ # were quoted by the user on the command-line and need no special
16
+ # treatment here. For example, '~/junk' on the commandline will show up
17
+ # here as '/home/ded/junk'. If we see '~/junk', that means the user has
18
+ # quoted the ~ on the command line with something like '\~junk', so we
19
+ # should assume that the user wants to keep it that way. Likewise, an
20
+ # arg with spaces in it will have been quoted by the user to be seen as
21
+ # a single argument. When we output these for use by the shell in the
22
+ # system command, we should apply shellquote to everything so that the
23
+ # receiving shell sees the args in the same way.
24
+
25
+ @erbtex_name = File.basename($PROGRAM_NAME)
24
26
 
25
27
  # Find the tex_commands
26
28
  @tex_commands = []
@@ -39,8 +41,23 @@ module ErbTeX
39
41
  argv.reject! { |a| a =~ /\A--invoke=(\w+)/ }
40
42
  end
41
43
 
44
+ # Look for our --version
45
+ @print_version = false
46
+ if argv.any? { |a| a =~ /\A--version/ }
47
+ @print_version = true
48
+ argv.reject! { |a| a =~ /\A--version/ }
49
+ end
50
+
51
+ # Look for our --help
52
+ @print_help = false
53
+ if argv.any? { |a| a =~ /\A--help/ }
54
+ @print_help = true
55
+ argv.reject! { |a| a =~ /\A--help/ }
56
+ end
57
+
42
58
  # The last argument, assuming it does not start with a '-' or '&', is
43
59
  # assumed to be the name of the input_file.
60
+ @input_file = nil
44
61
  if !argv.empty? && argv[-1] !~ /\A[-&]/
45
62
  @input_file = CommandLine.expand_input_file(argv.pop)
46
63
  end
@@ -48,12 +65,12 @@ module ErbTeX
48
65
  # What remains in argv should be the tex program's '-options', which
49
66
  # should be passed through untouched. So, can form the full command line
50
67
  # for tex_processing
51
- @tex_options = argv.dup
68
+ @tex_args = argv.dup
52
69
  end
53
70
 
54
71
  def tex_command(tex_file = input_file)
55
72
  "#{tex_program} " \
56
- "#{tex_options.shelljoin} " \
73
+ "#{tex_args.shelljoin} " \
57
74
  "#{tex_commands.shelljoin} " \
58
75
  "#{tex_file}"
59
76
  .strip.squeeze(' ')
@@ -62,19 +79,25 @@ module ErbTeX
62
79
  # Return the name of the input file based on the name given in the command
63
80
  # line. Try to find the right extension for the input file if none is given.
64
81
  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"
82
+ return '' if input_file.blank?
83
+
84
+ md = %r{\A(.*)(\.[\w.]+)?\z}.match(input_file)
85
+ if md
86
+ input_base = md[1]
87
+ input_ext = md[2]
88
+ end
89
+ if input_ext.nil?
90
+ if File.exist?("#{input_base}.tex.erb")
91
+ "#{input_base}.tex.erb"
92
+ elsif File.exist?("#{input_base}.tex")
93
+ "#{input_base}.tex"
94
+ elsif File.exist?("#{input_base}.erb")
95
+ "#{input_base}.erb"
73
96
  else
74
- input_file
97
+ input_base
75
98
  end
76
99
  else
77
- input_file
100
+ input_base
78
101
  end
79
102
  end
80
103
  end
@@ -111,14 +134,14 @@ end
111
134
  # program is run, regardless of any input file location; or, in a few
112
135
  # cases, output is to standard output.
113
136
 
114
- # For example, if you run tex /tmp/foo’, for example, the output will
137
+ # For example, if you run 'tex /tmp/foo', for example, the output will
115
138
  # be in ./foo.dvi and ./foo.log, not /tmp/foo.dvi and /tmp/foo.log.
116
139
 
117
- # You can use the ‘-output-directory option to cause all output files
140
+ # You can use the '-output-directory' option to cause all output files
118
141
  # that would normally be written in the current directory to be written
119
142
  # in the specified directory instead. See Common options.
120
143
 
121
- # If the current directory is not writable, and ‘-output-directory is
144
+ # If the current directory is not writable, and '-output-directory' is
122
145
  # not specified, the main programs (TeX, Metafont, MetaPost, and BibTeX)
123
146
  # make an exception: if the config file or environment variable value
124
147
  # TEXMFOUTPUT is set (it is not by default), output files are written to
@@ -126,5 +149,5 @@ end
126
149
 
127
150
  # TEXMFOUTPUT is also checked for input files, as TeX often generates
128
151
  # files that need to be subsequently read; for input, no suffixes (such
129
- # as ‘.tex) are added by default and no exhaustive path searching is
152
+ # as '.tex') are added by default and no exhaustive path searching is
130
153
  # done, the input name is simply checked as given.
data/lib/erbtex/runner.rb CHANGED
@@ -1,44 +1,52 @@
1
1
  require 'tempfile'
2
2
  require 'pathname'
3
+ require 'English'
3
4
 
5
+ # Name space module for erbtex program.
4
6
  module ErbTeX
5
- # When we are handed a command line, it will be one that was
6
- # originally intended for the real tex processor, e.g., pdflatex.
7
- #
8
- # We want to find the intended input file and the intended output
9
- # directory using the ErbTeX::CommandLine object.
10
- #
11
- # We want to process the intended input file with Erubis and save the
12
- # output in a temporary file with an .etx extension.
13
- #
14
- # Write the .etx file to the current directory unless it is not
15
- # writable, in which case write it to /tmp.
16
- #
17
- # Perhaps change the Erubis pattern to something other than the erbtex
18
- # default '{: :}'. Erubis normally by uses '<%= %>' by default. Erubis -p
19
- # commandline -p '\.{ }\.'
20
-
21
- # If there are no Erubis patterns in the file, skip the Erubis phase
22
- # and just pass the original command on to the system.
23
- #
24
- # But wait. What if there are \include{file} or \input file
25
- # statements in the input and those have Erubis patterns in them? We
26
- # have to invoke erbtex recursively on those, replacing the
27
- # orginal with a processed temporary and patching up the
28
- # \include{tmp-file}, and so on.
29
- #
30
- # If there is an error in the Erubis phase, we want the error message
31
- # to make it clear what happened and exit without invoking the tex
32
- # processor.
33
- #
34
- # We want to find the real tex processor with find_executable and run it
35
- # on our processed .etx file and otherwise leave the commandline
36
- # intact.
37
- #
38
- def self.run(cl)
39
- tex_dir = input_dir(cl.input_file)
40
- tex_file = erb_to_tex(cl.input_file, tex_dir) if cl.input_file
41
- run_tex(cl.tex_command(tex_file), tex_dir)
7
+ def self.run(cmd_line)
8
+ report_version && exit(0) if cmd_line.print_version
9
+ report_help && exit(0) if cmd_line.print_help
10
+
11
+ tex_dir = input_dir(cmd_line.input_file)
12
+ tex_file = erb_to_tex(cmd_line.input_file, tex_dir) if cmd_line.input_file
13
+ run_tex(cmd_line.tex_command(tex_file), tex_dir)
14
+ end
15
+
16
+ def self.report_version
17
+ puts "erbtex version: #{ErbTeX::VERSION}"
18
+ puts "Ruby version: #{RUBY_VERSION}"
19
+ begin
20
+ erubis_version = `erubis -v`
21
+ rescue Errno::ENOENT
22
+ warn 'Warning: erubis does not appear to be installed!'
23
+ exit(1)
24
+ end
25
+ puts "erubis version: #{erubis_version}"
26
+ true
27
+ end
28
+
29
+ def self.report_help
30
+ puts <<~HELP
31
+ Usage: erbtex [erbtex_options] [tex_prog_args] [file]
32
+
33
+ erbtex_options are:
34
+ --version - print the version of the erbtex gem, ruby and erubis
35
+ --help - print this help message
36
+ --invoke=<tex_prog> - after pre-processing, invoke <tex_prog> on the
37
+ resulting file, tex_prog is pdflatex by default
38
+
39
+ All other arguments, except possibly the last, are passed unaltered to
40
+ the tex_prog for interpretation. If any of these arguments starts with a
41
+ '\\' or '&', then all remaining arguments are passed to tex-prog for
42
+ interpretation, even the final argument.
43
+
44
+ The last argument is taken as the input file name unless it or any earlier
45
+ argument starts with a '\\' or '&', in which case it is also passed along
46
+ as an argument to the tex-prog.
47
+
48
+ HELP
49
+ true
42
50
  end
43
51
 
44
52
  # Run the TeX program, adding add_dir to the front of TEXINPUTS, unless it is
@@ -54,26 +62,29 @@ module ErbTeX
54
62
  end
55
63
  end
56
64
  unless system(cmd)
57
- $stderr.puts "Call to '#{cmd}' failed."
58
- exit $?.exitstatus
65
+ warn "Call to '#{cmd}' failed."
66
+ exit $CHILD_STATUS
59
67
  end
60
- $?
68
+ $CHILD_STATUS
61
69
  end
62
70
 
63
71
  def self.input_dir(in_file)
64
72
  return nil unless in_file
73
+
65
74
  in_file_absolute = File.absolute_path(File.expand_path(in_file))
66
- in_file_absolute[/\A(.*\/)([^\/.]+)(\.[\w.]+)\z/, 1]
75
+ in_file_absolute[%r{\A(.*/)([^/.]+)(\.[\w.]+)\z}, 1]
67
76
  end
68
77
 
69
78
  # Pre-process the input file with erubis, adding the add_dir to the front of
70
79
  # the ruby load path if its not already in the load path. Return the name of
71
80
  # the processed file.
72
81
  def self.erb_to_tex(in_file, add_dir = nil)
73
- add_dir = File.absolute_path(File.expand_path(add_dir))
74
- unless $LOAD_PATH
75
- .any? { |p| add_dir == File.absolute_path(File.expand_path(p)) }
76
- $LOAD_PATH.unshift(add_dir)
82
+ if File.exist?(add_dir)
83
+ add_dir = File.absolute_path(File.expand_path(add_dir))
84
+ unless $LOAD_PATH
85
+ .any? { |p| add_dir == File.absolute_path(File.expand_path(p)) }
86
+ $LOAD_PATH.unshift(add_dir)
87
+ end
77
88
  end
78
89
 
79
90
  in_contents = nil
@@ -82,134 +93,59 @@ module ErbTeX
82
93
  end
83
94
  # TODO: recurse through any \input or \include commands
84
95
 
85
- pat =
86
- if ENV['ERBTEX_PATTERN']
87
- ENV['ERBTEX_PATTERN']
88
- else
89
- '{: :}'
90
- end
96
+ pat = ENV['ERBTEX_PATTERN'] || '{: :}'
91
97
 
92
- out_file = set_out_file(in_file)
98
+ out_file = out_file_name(in_file)
93
99
  File.open(out_file, 'w') do |f|
94
100
  er = ::Erubis::Eruby.new(in_contents, pattern: pat)
95
101
  f.write(er.result)
96
102
  end
97
103
  out_file
98
- rescue SystemCallError => ex
99
- $stderr.puts "Error: #{ex}"
104
+ rescue SystemCallError => e
105
+ warn "Error: #{e}"
100
106
  exit 1
101
- rescue ScriptError => ex
102
- $stderr.puts "Erubis pre-processing failed: #{ex}"
107
+ rescue ScriptError => e
108
+ warn "Erubis pre-processing failed: #{e}"
103
109
  exit 1
104
110
  end
105
111
 
106
- def self.set_out_file(in_file)
112
+ def self.out_file_name(in_file)
107
113
  in_file_absolute = File.absolute_path(File.expand_path(in_file))
108
- in_dir = in_file_absolute[/\A(.*\/)([^\/.]+)(\.[\w.]+)\z/, 1]
109
- in_base = in_file_absolute[/\A(.*\/)([^\/.]+)(\.[\w.]+)\z/, 2]
110
- in_ext = in_file_absolute[/\A(.*\/)([^\/.]+)(\.[\w.]+)\z/, 3]
111
-
112
- if in_ext.empty?
113
- if File.exists?("#{in_file}.tex.erb")
114
- out_ext = '.tex'
115
- elsif File.exists?("#{in_file}.tex")
116
- out_ext = '.etx'
117
- elsif File.exists?("#{in_file}.erb")
118
- out_ext = '.tex'
119
- else
120
- out_ext = '.tex'
121
- end
122
- else
123
- case in_ext
124
- when '.tex.erb'
125
- out_ext = '.tex'
126
- when '.tex'
127
- out_ext = '.etx'
128
- when '.erb'
129
- out_ext = '.tex'
130
- else
131
- out_ext = '.tex'
132
- end
133
- end
114
+ in_dir = File.dirname(in_file_absolute)
115
+ in_base = File.basename(in_file_absolute)
116
+ in_ext = File.extname(in_file_absolute)
117
+
118
+ out_ext = if in_ext.empty?
119
+ if File.exist?("#{in_file}.tex.erb")
120
+ '.tex'
121
+ elsif File.exist?("#{in_file}.tex")
122
+ '.etx'
123
+ elsif File.exist?("#{in_file}.erb")
124
+ '.tex'
125
+ else
126
+ '.tex'
127
+ end
128
+ else
129
+ case in_ext
130
+ when '.tex.erb'
131
+ '.tex'
132
+ when '.tex'
133
+ '.etx'
134
+ when '.erb'
135
+ '.tex'
136
+ else
137
+ '.tex'
138
+ end
139
+ end
134
140
 
135
141
  # Find a writable directory, prefering the one the input file came
136
142
  # from, or the current directory, and a temp file as a last resort.
137
143
  if File.writable?(in_dir)
138
- out_file = File.join(in_dir, "#{in_base}#{out_ext}")
144
+ File.join(in_dir, "#{in_base}#{out_ext}")
139
145
  elsif File.writable?('.')
140
- out_file = File.join('.', "#{in_base}#{out_ext}")
146
+ File.join('.', "#{in_base}#{out_ext}")
141
147
  else
142
- out_file = Tempfile.new([in_base, out_ext]).path
148
+ Tempfile.new([in_base, out_ext]).path
143
149
  end
144
- out_file
145
150
  end
146
151
  end
147
- # def ErbTeX.run(command)
148
- # cl = CommandLine.new(command)
149
- # Dir.chdir(cl.run_dir) do
150
- # if cl.input_file
151
- # new_infile = process(cl.input_file, cl.input_path)
152
- # else
153
- # new_infile = nil
154
- # end
155
- # if new_infile
156
- # new_infile = Pathname.new(new_infile).
157
- # relative_path_from(Pathname.new(cl.run_dir))
158
- # end
159
- # new_progname = ErbTeX.find_executable(command.lstrip.split(' ')[0])
160
- # cmd = cl.new_command_line(new_progname, new_infile)
161
- # cmd.sub!('\\', '\\\\\\')
162
- # cmd.sub!('&', '\\\\&')
163
- # puts "Executing: #{cmd}"
164
- # system(cmd)
165
- # end
166
- # end
167
-
168
- # Run erbtex on the content of file_name, a String, and return the
169
- # name of the file where the processed content can be found. This
170
- # could be the orignal file name if no processing was needed, or a
171
- # temporary file if the erubis pattern is found anywhere in the file.
172
- # def ErbTeX.process(file_name, dir)
173
- # puts "Input path: #{dir}"
174
- # contents = nil
175
- # File.open(file_name) do |f|
176
- # contents = f.read
177
- # end
178
- # # TODO: recurse through any \input or \include commands
179
-
180
- # # Add current directory to LOAD_PATH
181
- # $: << '.' unless $:.include?('.')
182
-
183
- # if ENV['ERBTEX_PATTERN']
184
- # pat = ENV['ERBTEX_PATTERN']
185
- # else
186
- # pat = '{: :}'
187
- # end
188
-
189
- # # Otherwise process the contents
190
- # # Find a writable directory, prefering the one the input file came
191
- # # from, or the current directory, and a temp file as a last resort.
192
- # file_absolute = File.absolute_path(File.expand_path(file_name))
193
- # file_dir = File.dirname(file_absolute)
194
- # if file_absolute =~ /\.tex\.erb$/
195
- # file_base = File.basename(file_absolute, '.tex.erb')
196
- # else
197
- # file_base = File.basename(file_absolute, '.tex')
198
- # end
199
- # of = nil
200
- # if File.writable?(file_dir)
201
- # out_file = file_dir + '/' + file_base + '.etx'
202
- # elsif File.writable?('.')
203
- # out_file = './' + file_base + '.etx'
204
- # else
205
- # of = Tempfile.new([File.basename(file_name), '.etx'])
206
- # out_file = of.path
207
- # end
208
- # unless of
209
- # of = File.open(out_file, 'w+')
210
- # end
211
- # er = Erubis::Eruby.new(contents, :pattern => pat)
212
- # of.write(er.result)
213
- # of.close
214
- # out_file
215
- # end
@@ -1,3 +1,3 @@
1
1
  module ErbTeX
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.1"
3
3
  end
data/lib/erbtex.rb CHANGED
@@ -8,8 +8,8 @@ require 'bundler/setup' if $LOAD_PATH.none? { |p| p =~ /erbtex/ }
8
8
 
9
9
  require 'shellwords'
10
10
  require 'erubis'
11
+ require 'fat_core'
11
12
 
12
13
  require 'erbtex/version'
13
14
  require 'erbtex/command_line'
14
- require 'erbtex/find_binary'
15
15
  require 'erbtex/runner'
@@ -18,6 +18,17 @@ module ErbTeX
18
18
  -recorder -shell-escape -src-specials cr,display,hbox,math,par
19
19
  -translate-file willy -version &myformat file_name.tex.erb
20
20
  )
21
+ @argv_with_invoke_and_file =
22
+ %w(
23
+ --invoke=lualatex
24
+ -draftmode -enc -etex -file-line-error -fmt junk
25
+ -halt-on-error -ini -interaction batchmode -ipc -ipc-start
26
+ -jobname junk -kpathsea-debug 8 -mktex tex --invoke=pdflatex
27
+ -mltex -nomktex tfm -ouptput-comment This\ is\ a\ long\ comment
28
+ -output-directory ~/texmf/tex -parse-first-line -progname pdflatex
29
+ -recorder -shell-escape -src-specials cr,display,hbox,math,par
30
+ -translate-file willy -version &myformat file_name.tex.erb
31
+ )
21
32
  @argv_with_cmds =
22
33
  %w(
23
34
  -draftmode -enc -etex -file-line-error -fmt junk
@@ -58,6 +69,22 @@ module ErbTeX
58
69
  EOS
59
70
  end
60
71
 
72
+ it 'parse command line with invoke and file name' do
73
+ cl = CommandLine.new(@argv_with_invoke_and_file)
74
+ expect(cl.erbtex_name).to eq('erbtex')
75
+ expect(cl.tex_program).to eq('lualatex')
76
+ expect(cl.input_file).to eq('file_name.tex.erb')
77
+ expect(cl.tex_command).to eq(<<~'EOS'.tr("\n", ' ').strip)
78
+ lualatex -draftmode -enc -etex -file-line-error -fmt junk -halt-on-error
79
+ -ini -interaction batchmode -ipc -ipc-start -jobname junk -kpathsea-debug 8
80
+ -mktex tex -mltex -nomktex tfm
81
+ -ouptput-comment This\ is\ a\ long\ comment
82
+ -output-directory \~/texmf/tex -parse-first-line -progname pdflatex
83
+ -recorder -shell-escape -src-specials cr,display,hbox,math,par
84
+ -translate-file willy -version \&myformat file_name.tex.erb
85
+ EOS
86
+ end
87
+
61
88
  it 'parse command line with TeX commands' do
62
89
  cl = CommandLine.new(@argv_with_cmds)
63
90
  expect(cl.erbtex_name).to eq('erbtex')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: erbtex
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel E. Doherty
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: fat_core
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rake
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -146,16 +160,14 @@ files:
146
160
  - examples/TrigTable.tex
147
161
  - examples/TrigTable2.tex
148
162
  - examples/dms.rb
149
- - examples/roots.tex.erb
163
+ - examples/roots.tex
150
164
  - examples/testbind.rb
151
- - examples/testbind.tex.erb
165
+ - examples/testbind.tex
152
166
  - lib/erbtex.rb
153
167
  - lib/erbtex/command_line.rb
154
- - lib/erbtex/find_binary.rb
155
168
  - lib/erbtex/runner.rb
156
169
  - lib/erbtex/version.rb
157
170
  - spec/lib/command_line_spec.rb
158
- - spec/lib/find_executable_spec.rb
159
171
  - spec/spec_helper.rb
160
172
  homepage: ''
161
173
  licenses: []
@@ -175,8 +187,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
175
187
  - !ruby/object:Gem::Version
176
188
  version: '0'
177
189
  requirements: []
178
- rubyforge_project:
179
- rubygems_version: 2.6.13
190
+ rubygems_version: 3.0.3
180
191
  signing_key:
181
192
  specification_version: 4
182
193
  summary: Preprocesses TeX and LaTeX files with erubis for ruby.
@@ -1,41 +0,0 @@
1
- module ErbTeX
2
- # Find the first executable file in the PATH that is the same
3
- # basename, but not the same absolute name as calling_prog. If this
4
- # program has been linked to the name pdflatex, for example, and is
5
- # located in ~/bin/pdflatex, this function will take '~/bin/pdflatex'
6
- # as it parameter, expand it to /home/ded/pdflatex, then walk through
7
- # the PATH looking for an executable with the same basename, pdflatex,
8
- # but not the same absolute name /home/ded/bin/pdflatex.
9
- #
10
- # This allows us to make several symlinks to our erbtex program with
11
- # the name of the actual program we want to invoke. So our link
12
- # version of pdflatex will know to invoke the *real* pdflatex in
13
- # /usr/bin/pdflatex after we've done the pre-processing. Also, other
14
- # programs that want to invoke pdflatex will still work, except that
15
- # we'll sneak in and do ruby pre-processing before invoking the real
16
- # program.
17
-
18
- # If the calling program is 'erbtex', treat it as 'pdflatex' just as
19
- # if it were a pdflatex link to erbtex
20
-
21
- def ErbTeX.find_executable(calling_prog)
22
- calling_prog = File.absolute_path(calling_prog)
23
- call_path = File.dirname(calling_prog)
24
- call_base = File.basename(calling_prog).sub(/^erbtex$/, 'pdflatex')
25
- executable = nil
26
- ENV['PATH'].split(':').each do |p|
27
- next unless File.directory?(p)
28
- next if File.absolute_path(p) == call_path
29
- Dir.chdir(p) do
30
- Dir.glob(call_base).each do |f|
31
- if system("file -L #{f} | grep -q ELF")
32
- executable = File.join(p, f)
33
- break
34
- end
35
- end
36
- end
37
- break if executable
38
- end
39
- executable
40
- end
41
- end
@@ -1,43 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module ErbTeX
4
- describe 'FindExecutable' do
5
- # Here we set up the situation as we expect it to be after
6
- # installation. There is a "real" pdflatex executable binary and
7
- # there is one that is just a link to our script, the "fake" binary.
8
- # The fake binary is earlier in PATH than the real binary, and we want
9
- # this function, when fed the name of the fake binary to deduce the
10
- # name of the real binary.
11
- before :all do
12
- # Create a "fake" ruby script named pdflatex
13
- @fake_dir = File.dirname(File.absolute_path(__FILE__)) + '/fake_bin'
14
- FileUtils.mkdir(@fake_dir) unless File.exist?(@fake_dir)
15
- @fake_binary = @fake_dir + '/pdflatex'
16
- @erbtex = @fake_dir + '/erbtex'
17
- FileUtils.touch(@erbtex)
18
- FileUtils.chmod(0700, @erbtex)
19
- FileUtils.rm_rf(@fake_binary) if File.exist?(@fake_binary)
20
- FileUtils.ln_s(@erbtex, @fake_binary)
21
-
22
- # Point to "real" pdflatex to find
23
- @real_binary = '/usr/bin/pdflatex'
24
- @real_dir = '/usr/bin'
25
-
26
- # Put the fake dir on the PATH before the real dir
27
- ENV['PATH'] = @fake_dir + ':' + @real_dir + ':' + ENV['PATH']
28
- end
29
-
30
- after :all do
31
- FileUtils.rm_rf(@fake_dir)
32
- end
33
-
34
- it 'should find the real executable from fake' do
35
- expect(ErbTeX.find_executable(@fake_binary)).to eq @real_binary
36
- end
37
-
38
- it 'should find the real executable from erbtex' do
39
- expect(ErbTeX.find_executable(@erbtex)).to eq @real_binary
40
- end
41
-
42
- end
43
- end