Skip to content

Instantly share code, notes, and snippets.

@hyuki0000
Created June 21, 2015 12:46
Show Gist options
  • Save hyuki0000/fc1f2fd6fe72167c6b80 to your computer and use it in GitHub Desktop.
Save hyuki0000/fc1f2fd6fe72167c6b80 to your computer and use it in GitHub Desktop.
Which figure files are not used during LaTeXing?
#! /usr/bin/ruby
require "fileutils"
if ARGV.length != 2
puts <<-"EOD"
Which figure files are not used during LaTeXing?
Usage: ruby not-used-fig.rb LOGDIR FIGDIR
Example: ruby not-used-fig.rb . fig
LOGDIR contains *.log files.
FIGDIR contains figure files.
EOD
abort
end
LOGDIR = ARGV[0]
FIGDIR = ARGV[1]
Dir.chdir(LOGDIR)
logs = Dir.glob("*.log")
exist_figs = []
exist_figs += Dir.glob("#{FIGDIR}/*.png")
exist_figs += Dir.glob("#{FIGDIR}/*.jpg")
exist_figs += Dir.glob("#{FIGDIR}/*.pdf")
exist_figs += Dir.glob("#{FIGDIR}/*.eps")
used_figs = []
logs.each do |logname|
File.open(logname, "r") do |f|
f.readlines.each do |line|
if line.match(/^File: (\S+) Graphic file \(type \w+\)/)
used_figs << $1
end
end
end
end
exist_figs = exist_figs.map {|fig| File.expand_path(fig) }.sort
used_figs = used_figs.map {|fig| File.expand_path(fig) }.sort
puts exist_figs - used_figs
@hyuki0000
Copy link
Author

This script shows the list of figure files that are not used during LaTeXing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment