From 7874a57a4a25afe671087c16ea08f394a54f2bdb Mon Sep 17 00:00:00 2001 From: Baldur Kristinsson Date: Sun, 14 Feb 2016 17:40:07 +0000 Subject: [PATCH] Export options tweaking * Add pandoc_pdf_export_cleanup option, false by default. * Correct specification of some configuration options related to export. --- CHANGELOG | 6 ++++++ README.md | 2 ++ pandoc.pm | 55 +++++++++++++++++++++++++++++++++++-------------------- 3 files changed, 43 insertions(+), 20 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index c2fa829..9b64baa 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,9 @@ +0.4.1 (2016-02-14) +================== + +* Add `pandoc_pdf_export_cleanup` option, false by default. +* Corrected the specification of some configuration options. + 0.4 (2016-02-03) ================= diff --git a/README.md b/README.md index 87f9e7c..753819a 100644 --- a/README.md +++ b/README.md @@ -132,6 +132,8 @@ There are several configuration options related to the export functionality: * `pandoc_beamer_extra_options`: List of extra pandoc options for Beamer PDF generation. +* `pandoc_pdf_export_cleanup`: Whether to cleanup LaTeX auxiliary files after doing a PDF export (including Beamer). The default is to keep this False, since it often speeds PDF regeneration up considerably when updating a page. + * `pandoc_revealjs_template`: Path to pandoc template for Reveal.js slides output. * `pandoc_revealjs_extra_options`: List of extra pandoc options for Reveal.js slides generation. **Please note** that the option `--self-contained` is added automatically. In order for this to work, pandoc has to know where to find the reveal.js Javascript and CSS files. The easiest way of making sure of this is to keep them in pandoc's default user data directory. You can see the name of this folder by running `pandoc --version`; usually it is `~/.pandoc`, in which case the reveal.js files would be in the subdirectory `~/.pandoc/reveal.js/`. You can download the most recent reveal.js release [here](https://github.com/hakimel/reveal.js/releases). diff --git a/pandoc.pm b/pandoc.pm index d0daf33..fb496a0 100755 --- a/pandoc.pm +++ b/pandoc.pm @@ -236,90 +236,97 @@ sub getsetup () { safe => 1, rebuild => 1, }, - pandoc_latex_template { + pandoc_latex_template => { type => "string", example => "", description => "Path to pandoc template for LaTeX and normal PDF output", safe => 1, rebuild => 0, }, - pandoc_latex_extra_options { + pandoc_latex_extra_options => { type => "internal", default => [], description => "List of extra pandoc options for LaTeX (and PDF) generation", safe => 0, rebuild => 0, }, - pandoc_beamer_template { + pandoc_beamer_template => { type => "string", example => "", description => "Path to pandoc template for Beamer PDF output", safe => 1, rebuild => 0, }, - pandoc_beamer_extra_options { + pandoc_beamer_extra_options => { type => "internal", default => [], description => "List of extra pandoc options for Beamer PDF generation", safe => 0, rebuild => 0, }, - pandoc_revealjs_template { + pandoc_pdf_export_cleanup => { + type => "boolean", + example => "0", + description => "Whether to clean up LaTeX auxiliary files after PDF generation", + safe => 0, + rebuild => 0, + }, + pandoc_revealjs_template => { type => "string", example => "", description => "Path to pandoc template for Reveal.js slides output", safe => 1, rebuild => 0, }, - pandoc_revealjs_extra_options { + pandoc_revealjs_extra_options => { type => "internal", default => [], description => "List of extra pandoc options for Reveal.js slides generation", safe => 0, rebuild => 0, }, - pandoc_docx_template { + pandoc_docx_template => { type => "string", example => "", description => "Path to pandoc template for MS Word (docx) output", safe => 1, rebuild => 0, }, - pandoc_docx_extra_options { + pandoc_docx_extra_options => { type => "internal", default => [], description => "List of extra pandoc options for DOCX generation", safe => 0, rebuild => 0, }, - pandoc_odt_template { + pandoc_odt_template => { type => "string", example => "", description => "Path to pandoc template for OpenDocument (odt) output", safe => 1, rebuild => 0, }, - pandoc_odt_extra_options { + pandoc_odt_extra_options => { type => "internal", default => [], description => "List of extra pandoc options for ODT generation", safe => 0, rebuild => 0, }, - pandoc_epub_template { + pandoc_epub_template => { type => "string", example => "", description => "Path to pandoc template for EPUB3 output", safe => 1, rebuild => 0, }, - pandoc_epub_extra_options { + pandoc_epub_extra_options => { type => "internal", default => [], description => "List of extra pandoc options for EPUB3 generation", safe => 0, rebuild => 0, - }, + }; } @@ -605,6 +612,12 @@ sub export_file { push @extra_args, @$cnf; } } + my $pdf_cleanup = 0; + if (defined $pagestate{$page}{meta}{"pandoc_pdf_export_cleanup"}) { + $pdf_cleanup = $pagestate{$page}{meta}{"pandoc_pdf_export_cleanup"}; + } elsif ($config{"pandoc_pdf_export_cleanup"}) { + $pdf_cleanup = 1; + } # If the user has asked for native LaTeX bibliography handling in the # extra_args for this export format (using --biblatex or --natbib), # some extra care is needed. Among other things, we need an external @@ -644,12 +657,14 @@ sub export_file { $plain_fn =~ s/\.tex//; system('latexmk', @latexmk_args, $plain_fn) == 0 or die "Could not run latexmk for pdf generation ($export_path): $!"; - system('latexmk', '-c', '-quiet', '-silent', $plain_fn) == 0 - or die "Could not run latexmk for cleanup ($export_path): $!"; - # These files are apparently not cleaned up by latexmk -c. - foreach ('run.xml', 'bbl') { - my $fn = "$subdir/$plain_fn.$_"; - unlink($fn) if -f $fn; + if ($pdf_cleanup) { + system('latexmk', '-c', '-quiet', '-silent', $plain_fn) == 0 + or die "Could not run latexmk for cleanup ($export_path): $!"; + # These files are apparently not cleaned up by latexmk -c. + foreach ('run.xml', 'bbl') { + my $fn = "$subdir/$plain_fn.$_"; + unlink($fn) if -f $fn; + } } } $pagestate{$page}{pandoc_extra_formats}{$ext} = $export_url; @@ -697,7 +712,7 @@ sub compile_string { my $compiled_string = ''; foreach my $word_or_space (@uncompiled) { next unless ref $word_or_space eq 'HASH'; - my $type = $word_or_space->{'t'}; + my $type = $word_or_space->{'t'} || ''; $compiled_string .= compile_string(@{ $word_or_space->{c} }) if $type eq 'MetaInlines'; next unless $type eq 'Str' || $type eq 'Space' || $type eq 'MetaString'; $compiled_string .= $type eq 'Space' ? ' ' : $word_or_space->{c}; -- 2.39.2