Skip to content

Instantly share code, notes, and snippets.

@abcang
Last active November 29, 2016 18:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abcang/aaec2855b1803120167b to your computer and use it in GitHub Desktop.
Save abcang/aaec2855b1803120167b to your computer and use it in GitHub Desktop.
いい感じにlatexのログからエラーを抽出するやつ
# coding: utf-8
log_file = ARGV.shift
File.open(log_file) do |file|
tex_file = ""
error_msg = []
error_flag = false
file.each_line do |line|
line = line.chomp
# inputされているtexファイル名を見つけて、エラー内容の起点とする
tmp_tex_file = line.scan(%r{^[^!]*\(\./(.*?\.tex)}).flatten.last
if tmp_tex_file
# 一つ前に見つかったtexファイル名がエラーが起きているファイル
# ファイル名とエラーを出力
if error_flag
puts tex_file
puts error_msg.join("\n")
puts ''
end
# リセットして次を探す
tex_file = tmp_tex_file
error_msg = []
error_flag = false
else
# texファイル名が含まれない場合で
# 先頭が「!」が含まれるとエラーと判定
error_flag = true if line =~ /^!.*/
error_msg << line
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment