erbtex 0.3.0 → 0.4.1
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.
- checksums.yaml +5 -5
- data/Gemfile.lock +41 -31
- data/README.org +45 -35
- data/erbtex.gemspec +1 -0
- data/examples/TrigTable.tex +7 -7
- data/examples/{roots.tex.erb → roots.tex} +0 -0
- data/examples/{testbind.tex.erb → testbind.tex} +0 -0
- data/lib/erbtex/command_line.rb +54 -31
- data/lib/erbtex/runner.rb +92 -156
- data/lib/erbtex/version.rb +1 -1
- data/lib/erbtex.rb +1 -1
- data/spec/lib/command_line_spec.rb +27 -0
- metadata +18 -7
- data/lib/erbtex/find_binary.rb +0 -41
- data/spec/lib/find_executable_spec.rb +0 -43
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 | 
            -
             | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 2 | 
            +
            SHA256:
         | 
| 3 | 
            +
              metadata.gz: 73e049b2407795a0ba4acd0b5e0bb7f962c072695ba245f6a42d12b96bdfea41
         | 
| 4 | 
            +
              data.tar.gz: e15af14509ec54c2fbc4fc4bfadb75d5ff04a0a74b5fb4e1b581cd4d1abae978
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 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. | 
| 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 | 
            -
                 | 
| 11 | 
            -
                   | 
| 12 | 
            -
                   | 
| 13 | 
            -
                   | 
| 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 | 
            -
                 | 
| 16 | 
            -
                 | 
| 17 | 
            -
                diff-lcs (1. | 
| 18 | 
            +
                concurrent-ruby (1.1.5)
         | 
| 19 | 
            +
                damerau-levenshtein (1.3.1)
         | 
| 20 | 
            +
                diff-lcs (1.3)
         | 
| 18 21 | 
             
                erubis (2.7.0)
         | 
| 19 | 
            -
                 | 
| 20 | 
            -
             | 
| 21 | 
            -
             | 
| 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 | 
| 25 | 
            -
                  byebug (~>  | 
| 32 | 
            +
                pry-byebug (3.7.0)
         | 
| 33 | 
            +
                  byebug (~> 11.0)
         | 
| 26 34 | 
             
                  pry (~> 0.10)
         | 
| 27 | 
            -
                pry-doc (0. | 
| 28 | 
            -
                  pry (~> 0. | 
| 29 | 
            -
                  yard (~> 0.9)
         | 
| 30 | 
            -
                rake ( | 
| 31 | 
            -
                rspec (3. | 
| 32 | 
            -
                  rspec-core (~> 3. | 
| 33 | 
            -
                  rspec-expectations (~> 3. | 
| 34 | 
            -
                  rspec-mocks (~> 3. | 
| 35 | 
            -
                rspec-core (3. | 
| 36 | 
            -
                  rspec-support (~> 3. | 
| 37 | 
            -
                rspec-expectations (3.3 | 
| 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. | 
| 40 | 
            -
                rspec-mocks (3. | 
| 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. | 
| 43 | 
            -
                rspec-support (3. | 
| 44 | 
            -
                 | 
| 45 | 
            -
                 | 
| 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. | 
| 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  | 
| 6 | 
            -
            TeX and LaTeX source files with ruby's erubis and then passes | 
| 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~ | 
| 20 | 
            -
            only one command-line option,  | 
| 21 | 
            -
            variant will process the TeX file after erubis has | 
| 22 | 
            -
            By default, ~ | 
| 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~  | 
| 25 | 
            -
             | 
| 26 | 
            -
             | 
| 27 | 
            -
             | 
| 28 | 
            -
             | 
| 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  | 
| 31 | 
            -
             | 
| 32 | 
            -
             | 
| 33 | 
            -
             | 
| 34 | 
            -
             | 
| 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 | 
            -
             | 
| 37 | 
            -
             | 
| 37 | 
            +
            Any text /not/ enclosed in these delimiters is passed through untouched to the
         | 
| 38 | 
            +
            TeX program.
         | 
| 38 39 |  | 
| 39 | 
            -
             | 
| 40 | 
            -
             | 
| 41 | 
            -
             | 
| 42 | 
            -
             | 
| 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 | 
            -
             | 
| 48 | 
            +
            You can get the version with the --version flag and help with --help.
         | 
| 46 49 |  | 
| 47 | 
            -
            **  | 
| 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 | 
            -
             | 
| 88 | 
            +
                \end{longtable}
         | 
| 81 89 | 
             
              \end{document}
         | 
| 82 90 | 
             
            #+END_SRC
         | 
| 83 91 |  | 
| 84 | 
            -
            With the above in file  | 
| 85 | 
            -
            line will generate a `PDF` file with a nicely typeset table of square | 
| 86 | 
            -
             | 
| 87 | 
            -
             | 
| 88 | 
            -
             | 
| 89 | 
            -
             | 
| 90 | 
            -
             | 
| 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
    
    
    
        data/examples/TrigTable.tex
    CHANGED
    
    | @@ -56,10 +56,10 @@ | |
| 56 56 | 
             
            ## increments of step
         | 
| 57 57 |  | 
| 58 58 | 
             
               require 'bigdecimal'
         | 
| 59 | 
            -
               step = BigDecimal | 
| 59 | 
            +
               step = BigDecimal("0.001")
         | 
| 60 60 | 
             
               one = BigDecimal("1.0")
         | 
| 61 61 | 
             
               z0 = BigDecimal("0.0")
         | 
| 62 | 
            -
               p2 = BigDecimal | 
| 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 | 
| 80 | 
            -
                  cotx = one / BigDecimal | 
| 81 | 
            -
                  secx = one / BigDecimal | 
| 82 | 
            -
                  cscx = one / BigDecimal | 
| 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
         | 
    
        data/lib/erbtex/command_line.rb
    CHANGED
    
    | @@ -1,26 +1,28 @@ | |
| 1 | 
            -
            #  | 
| 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, : | 
| 8 | 
            -
                attr_reader : | 
| 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 | 
| 13 | 
            -
                  # quoted by the user on the command-line and need no special | 
| 14 | 
            -
                  # here. For example, '~/junk' on the commandline will show up | 
| 15 | 
            -
                  # '/home/ded/junk'. If we see '~/junk', that means the user has | 
| 16 | 
            -
                  # ~ on the command line with something like '\~junk', so we | 
| 17 | 
            -
                  # that the user wants to keep it that way. Likewise, an | 
| 18 | 
            -
                  # it will have been quoted by the user to be seen as | 
| 19 | 
            -
                  # When we output these for use by the shell in the | 
| 20 | 
            -
                  # should apply shellquote to everything so that the | 
| 21 | 
            -
                  # the args in the same way.
         | 
| 22 | 
            -
             | 
| 23 | 
            -
                  @erbtex_name = File.basename($ | 
| 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 | 
            -
                  @ | 
| 68 | 
            +
                  @tex_args = argv.dup
         | 
| 52 69 | 
             
                end
         | 
| 53 70 |  | 
| 54 71 | 
             
                def tex_command(tex_file = input_file)
         | 
| 55 72 | 
             
                  "#{tex_program} " \
         | 
| 56 | 
            -
                  "#{ | 
| 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 | 
            -
                   | 
| 66 | 
            -
             | 
| 67 | 
            -
             | 
| 68 | 
            -
             | 
| 69 | 
            -
                     | 
| 70 | 
            -
             | 
| 71 | 
            -
             | 
| 72 | 
            -
             | 
| 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 | 
            -
                       | 
| 97 | 
            +
                      input_base
         | 
| 75 98 | 
             
                    end
         | 
| 76 99 | 
             
                  else
         | 
| 77 | 
            -
                     | 
| 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  | 
| 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  | 
| 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  | 
| 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  | 
| 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 | 
            -
               | 
| 6 | 
            -
             | 
| 7 | 
            -
             | 
| 8 | 
            -
             | 
| 9 | 
            -
             | 
| 10 | 
            -
             | 
| 11 | 
            -
             | 
| 12 | 
            -
               | 
| 13 | 
            -
             | 
| 14 | 
            -
               | 
| 15 | 
            -
             | 
| 16 | 
            -
             | 
| 17 | 
            -
             | 
| 18 | 
            -
             | 
| 19 | 
            -
             | 
| 20 | 
            -
             | 
| 21 | 
            -
             | 
| 22 | 
            -
             | 
| 23 | 
            -
             | 
| 24 | 
            -
             | 
| 25 | 
            -
               | 
| 26 | 
            -
             | 
| 27 | 
            -
               | 
| 28 | 
            -
             | 
| 29 | 
            -
             | 
| 30 | 
            -
             | 
| 31 | 
            -
             | 
| 32 | 
            -
             | 
| 33 | 
            -
             | 
| 34 | 
            -
             | 
| 35 | 
            -
             | 
| 36 | 
            -
             | 
| 37 | 
            -
             | 
| 38 | 
            -
               | 
| 39 | 
            -
             | 
| 40 | 
            -
             | 
| 41 | 
            -
             | 
| 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 | 
            -
                   | 
| 58 | 
            -
                  exit  | 
| 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[ | 
| 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 | 
            -
                 | 
| 74 | 
            -
             | 
| 75 | 
            -
             | 
| 76 | 
            -
             | 
| 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 =  | 
| 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 =>  | 
| 99 | 
            -
                 | 
| 104 | 
            +
              rescue SystemCallError => e
         | 
| 105 | 
            +
                warn "Error: #{e}"
         | 
| 100 106 | 
             
                exit 1
         | 
| 101 | 
            -
              rescue ScriptError =>  | 
| 102 | 
            -
                 | 
| 107 | 
            +
              rescue ScriptError => e
         | 
| 108 | 
            +
                warn "Erubis pre-processing failed: #{e}"
         | 
| 103 109 | 
             
                exit 1
         | 
| 104 110 | 
             
              end
         | 
| 105 111 |  | 
| 106 | 
            -
              def self. | 
| 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 | 
| 109 | 
            -
                in_base = in_file_absolute | 
| 110 | 
            -
                in_ext = in_file_absolute | 
| 111 | 
            -
             | 
| 112 | 
            -
                if in_ext.empty?
         | 
| 113 | 
            -
             | 
| 114 | 
            -
             | 
| 115 | 
            -
             | 
| 116 | 
            -
             | 
| 117 | 
            -
             | 
| 118 | 
            -
             | 
| 119 | 
            -
             | 
| 120 | 
            -
             | 
| 121 | 
            -
             | 
| 122 | 
            -
             | 
| 123 | 
            -
             | 
| 124 | 
            -
             | 
| 125 | 
            -
             | 
| 126 | 
            -
             | 
| 127 | 
            -
             | 
| 128 | 
            -
             | 
| 129 | 
            -
             | 
| 130 | 
            -
             | 
| 131 | 
            -
             | 
| 132 | 
            -
             | 
| 133 | 
            -
             | 
| 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 | 
            -
                   | 
| 144 | 
            +
                  File.join(in_dir, "#{in_base}#{out_ext}")
         | 
| 139 145 | 
             
                elsif File.writable?('.')
         | 
| 140 | 
            -
                   | 
| 146 | 
            +
                  File.join('.', "#{in_base}#{out_ext}")
         | 
| 141 147 | 
             
                else
         | 
| 142 | 
            -
                   | 
| 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
         | 
    
        data/lib/erbtex/version.rb
    CHANGED
    
    
    
        data/lib/erbtex.rb
    CHANGED
    
    
| @@ -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. | 
| 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 | 
| 163 | 
            +
            - examples/roots.tex
         | 
| 150 164 | 
             
            - examples/testbind.rb
         | 
| 151 | 
            -
            - examples/testbind.tex | 
| 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 | 
            -
             | 
| 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.
         | 
    
        data/lib/erbtex/find_binary.rb
    DELETED
    
    | @@ -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
         |