class Rake4LaTeX::TeXfile

This class collects informations for an existing (La)TeX-File.

It can be used to determine dependecies of a LaTeX project.

What’s not done:

*

end

Attributes

bibliography[R]

If bibTeX is used, this Array contains all bibliography.

end

gloss[R]

If gloss.sty is used, this Hash contains all glossaries and there bibliography.

end

splitindex[R]

If splitindex is used, this Array contains all indeces.

end

Public Class Methods

new( filename ) click to toggle source

Define a TeXfile.

If the include-analyse should work correct, the work directory should be the place, where you find your file.

If filename is :dummy, you get a dummy-file for little extracts.

end

# File lib/rake4latex/analyse_texfile.rb, line 31
def initialize( filename )

  @filename = filename      
  @@log.debug("TeXfile to analyse: #{@filename}")
  #~ @@log.warn("Start TeXfile analyse in foreign directory") unless File.dirname(filename) == '.'

  #List of filenames of the includes
  @includes = []
  #Hash with the objects for the include files.
  @include_object = {}
  @bibliography = []
  @gloss = {} #bib-files for gloss.sty
  @splitindex = {}
  
  if @filename != :dummy
    @basename = File.basename(filename)
    raise ArgumentError, "File #{@filename} not found" unless File.exist?(@filename)
    analyse( File.read(@filename) )
  end
end

Public Instance Methods

analyse(content ) click to toggle source

Analyse the file.

Search dependecies by sanning for

  • input/include

  • bibliography

  • printgloss (gloss.sty, like bibliography)

  • newindex (splitindex, like makeindex)

end

# File lib/rake4latex/analyse_texfile.rb, line 89
def analyse(content )

  content.each_line{ |line|
    #Skip comments
    #Remarks/Bug:
    #* \% is not detected.
    #* \iffalse...\fi is not detected.
    line.sub!(/%.*/, '')
    break if line =~ %r{\\endinput(\s|\Z)}  #Stop at \endinput
    #Detect \macro[]{}
    line.scan(/\\(include|input|includeonly|bibliography|printgloss|newindex)(\[.*?\])?\{([^}]+)\}/){|m|
      case m[0]
        #~ when 'includeonly'
        when 'include', 'input'
          includename = m[2].ext('tex')  #add the extension tex if not already done.
          @includes << includename
        when 'bibliography'
          #~ @bibliography << m[2].ext('bib')
          @bibliography << m[2].split(/,/).map{|f| f.ext('bib')}
          @bibliography.flatten!
        when 'printgloss'
          m[1]  = 'gls' unless m[1]
          @gloss[m[1]] ||= [] << m[2].split(/,/).map{|f| f.ext('bib')}
          @gloss[m[1]].flatten!
        when 'newindex'
          #m[1] contains the optional name
          @splitindex[m[2]] = m[1]
      end #case m[0]
    }#line.scan
  }#File.foreach

  @includes.each{|includename|
    if File.exist?(includename)
      if @include_object[includename]
        #fixme recursiv...
        #This check detects only a double input in one file.
        @@log.warn("Double input of #{includename} in #{@filename}")
      else
        @include_object[includename] = TeXfile.new(includename)
      end
    else
      @@log.warn("Include-File #{includename} not found")
    end
  }

  #Check the bibTeX-File in the TeXMF-trees (using kpsewhich)
  @bibliography.map!{|bib| kpsewhich(bib) }
  @gloss.each{|key,bibs| bibs.map!{|bib| kpsewhich(bib) }}
end
includes( *options ) click to toggle source

List of all includes.

Options:

  • :recurssive - get all includes, including includes of includes

  • :uniq - delete double includes

end

# File lib/rake4latex/analyse_texfile.rb, line 58
def includes( *options )
  if options.include?(:recursive)
    includes = tree.flatten - [ @filename ]
  else
    includes = @includes
  end
  includes.uniq! if options.include?(:uniq)
  includes
end
inspect() click to toggle source
# File lib/rake4latex/analyse_texfile.rb, line 168
def inspect()
  "<TeXfile #{@filename}>"
end
kpsewhich( filename ) click to toggle source

Check with kpsewhich to get a file location.

If nothing is found, take the original name.

end

# File lib/rake4latex/analyse_texfile.rb, line 143
def kpsewhich( filename )
  hit = `kpsewhich #{filename}`
  @@log.warn("Include-File #{filename} not found") if hit.empty?
  hit.empty? ? filename : hit.strip
end
tree() click to toggle source

Get a tree-like view of all includes.

end

# File lib/rake4latex/analyse_texfile.rb, line 151
def tree()
  tree = [@filename]
  #Only first occurence and without a sequence
  #~ @include_object.each{|name, inc|
    #~ tree << inc.tree
  #~ }

  @includes.each{|name|
    if @include_object[name]
      tree << @include_object[name].tree
    else
      tree << name
    end
  }

  tree
end