22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/asciidoctor-diagram/tikz/converter.rb', line 22
def convert(source, format, options)
latexpath = source.find_command('pdflatex')
if format == :svg
svgpath = source.find_command('pdf2svg')
else
svgpath = nil
end
if options[:preamble]
preamble, body = source.to_s.split(/^~~~~$/, 2)
unless body
body = preamble
preamble = ''
end
else
preamble = ''
body = source.to_s
end
latex = <<'END'
\documentclass[border=2bp, tikz]{standalone}
\usepackage{tikz}
END
latex << preamble
latex << <<'END'
\begin{document}
\begingroup
\tikzset{every picture/.style={scale=1}}
END
latex << body
latex << <<'END'
\endgroup
\end{document}
END
pdf = generate_file(latexpath, 'tex', 'pdf', latex) do |tool_path, input_path, output_path|
{
:args => [tool_path, '-shell-escape', '-file-line-error', '-interaction=nonstopmode', '-output-directory', Platform.native_path(File.dirname(output_path)), Platform.native_path(input_path)],
:out_file => "#{File.dirname(input_path)}/#{File.basename(input_path, '.*')}.pdf"
}
end
if svgpath
generate_file(svgpath, 'pdf', 'svg', pdf) do |tool_path, input_path, output_path|
{
:args => [tool_path, Platform.native_path(input_path), Platform.native_path(output_path)],
:chdir => source.base_dir
}
end
else
pdf
end
end
|