Skip to content

Instantly share code, notes, and snippets.

@imaizume
Created January 13, 2017 09:12
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 imaizume/7c71ae2c9867ae13895586af1204c6f6 to your computer and use it in GitHub Desktop.
Save imaizume/7c71ae2c9867ae13895586af1204c6f6 to your computer and use it in GitHub Desktop.
tex-boxでゲストからホストにtexディレクトリをrsyncして指定したtexファイルをPDF変換し返却するRubyスクリプト
#! /bin/sh
exec ruby -S -x "$0" "$@"
#! ruby
require 'fileutils'
src_path = ARGV[0]
unless File.exist?(src_path)
puts 'Specified file path does not exist.'
exit(0)
end
ext_src = File.extname(src_path)
unless ext_src == ".tex"
puts 'Specified file path was not latex file.'
exit(0)
end
src_dir = File.dirname(src_path)
src_file = File.basename(src_path, ext_src)
working_dir = File.expand_path(src_dir)
working_path = "#{working_dir}/#{src_file}"
unless `rsync -ur /vagrant/texs/ ~/texs/`
puts 'rsync failed.'
exit(0)
end
puts "Conversion started from #{src_file + ext_src} into #{src_file}.pdf"
Dir.chdir(working_dir) do
2.times do
cmd_platex = "platex -output-dir=#{working_dir} #{working_path + ext_src}"
unless system(cmd_platex)
puts 'Error occrred during platex conversion.'
exit(0)
end
cmd_dvipdfmx = "dvipdfmx -o #{working_path}.pdf #{working_path}.dvi"
unless system(cmd_dvipdfmx)
puts 'Error occrred during dvipdfmx conversion.'
exit(0)
end
end
puts "Converion finished!"
puts "#{working_path}.pdf"
FileUtils.copy("#{working_path}.pdf", '/vagrant')
puts "Copy PDF back to the local directory!"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment