7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/pdflatex.rb', line 7
def self.convert(latex_file, output_path)
path_to_latex_file = File.expand_path(latex_file)
expanded_output_path = File.expand_path(output_path)
latex_file_name = File.basename(latex_file)
dont_use_docker = ENV.has_key?('DONT_USE_DOCKER')
cmd = if dont_use_docker
<<-CMD.gsub(/\s+/, ' ')
latexmk -outdir=#{expanded_output_path} -pdf #{path_to_latex_file}
CMD
else
<<-CMD.gsub(/\s+/, ' ')
docker run
--rm
--user $(id -u)
-v #{path_to_latex_file}:/pdflatex/#{latex_file_name}
-v #{expanded_output_path}:/pdflatex/out
swissdrg/pdflatex:ride
latexmk -outdir=out -pdf #{latex_file_name}
CMD
end
output = `#{cmd}`
if $?.success?
file_name = File.basename(latex_file_name, '.tex')
%w(aux fdb_latexmk fls log).each do |ext|
file_path = File.join(expanded_output_path, "#{file_name}.#{ext}")
File.delete(file_path) if File.exist?(file_path)
end
end
output
end
|