# vim: filetype=perl

use File::Path qw(make_path);

$pdf_mode = 4;  # (1) pdflatex, (4) lualatex

my $options = ' -interaction=nonstopmode --synctex=1 %O %S';

# if ($out_dir) {
#     # copy pdf output to root directory
#     $options .= "; cp -av $out_dir/$basename.pdf .";
# }

$pdflatex = 'pdflatex' . $options;
$lualatex = 'lualatex' . $options;

# $bibtex_use = 2;  # always delete .bbl files in a cleanup

$clean_ext = '%R.run.xml';
$clean_full_ext = '%R.synctex.gz';

$clean_ext .= ' %R.auxlock';  # generated by TikZ "external" package

# Show CPU time used.
$show_time = 1;

# Check if using Inkscape 1.0 (in beta at this point).
my $with_inkscape_1 =
    system("inkscape --version | grep -Gq '^Inkscape 1\.'") == 0;
if ($with_inkscape_1) { print "INFO: Detected Inkscape version >= 1\n"; }

# Automatically convert svg files to pdf.
add_cus_dep('svg', 'pdf', 0, 'svg2pdf');
sub svg2pdf {
    my $basename = "$_[0]";
    my $pdfout = $with_inkscape_1 ? "--export-file" : "--export-pdf";
    return system("inkscape --without-gui --export-area-drawing" .
                  " $pdfout=\"$basename.pdf\" \"$basename.svg\"");
}

show_cus_dep();
