Created
June 21, 2015 12:46
-
-
Save hyuki0000/fc1f2fd6fe72167c6b80 to your computer and use it in GitHub Desktop.
Which figure files are not used during LaTeXing?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This script shows the list of figure files that are not used during LaTeXing.