2

With help of this Question I managed to realize a parallel externalization of multiple tikz picture rendering using the tikzexternalize option mode=list and make. Considering the following example

\documentclass{article}

\usepackage{tikz,pgfplots}
\usetikzlibrary{external}
\tikzexternalize[mode=list and make]

\begin{filecontents}{plot.tikz}
\begin{tikzpicture}
  \begin{axis}
    \addplot coordinates {(1,1) (2,2) (3,3)};
  \end{axis}
\end{tikzpicture}%
\end{filecontents}

\begin{document}
  \input{plot.tikz}
\end{document}

the procedure to get a document is the following:

  1. compile document to create list of tikz pictures
  2. use make via latexmk to create tikz picture pdf files
  3. compile again to include tikz pictures and create final pdf document

I tried to automate these three steps with the tool chain in Texstudio. If a PDF file of the tikzpicture is already available the toolchain runs without problems. But if the chain is started for the first time the first compilation ends with the error:

===== mode=`list and make': Use 'make -f texstudio_cB6136.makefile' to generate all images. Then, re-run (pdf)latex texstudio_cB6136. =====

! Package tikz Warning: Some images are not up-to-date and need to be generated

The error is expected but it interrupts the toolchain. So I wonder if there is the possibility to either ignore the error during execution of the toolchain in texstudio or to directly supress the error?

The commands I use are

  1. pdflatex.exe -enable-write18 -synctex=1 -interaction=nonstopmode %.tex
  2. make -j <number of threads> -f %.makefile
  3. pdflatex.exe -enable-write18 -synctex=1 -interaction=nonstopmode %.tex

1 Answer 1

4

This can be done by configuring latexmk. The following code is to be put in a latexkmrc file. It is improved and corrected from the code in the linked question Integrating latexmk and TikZ external mode=list and make.

$clean_ext .= ' %R.figlist %R-figure* %R.makefile fls.tmp';
$latex    = 'internal tikzlatex latex    %B %O %S';
$pdflatex = 'internal tikzlatex pdflatex %B %O %S';
$lualatex = 'internal tikzlatex lualatex %B %O %S';
$xelatex  = 'internal tikzlatex xelatex  %B %O %S';
$hash_calc_ignore_pattern{'pdf'} = '^(/CreationDate|/ModDate|/ID)';
$hash_calc_ignore_pattern{'ps'} = '^%%CreationDate';

sub tikzlatex {
  my ($engine, $base, @args) = @_;
  my $ret = 0;
  print "Tikzlatex: ===Running '$engine @args'...\n";
  $ret = system( $engine, @args );
  print "Tikzlatex: Fixing .fls file ...\n";
  system "echo INPUT \"$aux_dir1$base.figlist\"  >  \"$aux_dir1$base.fls.tmp\"";
  system "echo INPUT \"$aux_dir1$base.makefile\" >> \"$aux_dir1$base.fls.tmp\"";
  system "cat \"$aux_dir1$base.fls\"    >> \"$aux_dir1$base.fls.tmp\"";
  rename "$aux_dir1$base.fls.tmp", "$aux_dir1$base.fls";
  if ($ret) { return $ret; }
  if ( -e "$aux_dir1$base.makefile" ) {
    if ($engine eq 'xelatex') {
      print "Tikzlatex: ---Correcting '$aux_dir1$base.makefile' made under xelatex\n";
      system( 'perl', '-i', '-p', '-e', 's/^\^\^I/\t/', "$aux_dir1$base.makefile" );
    }
    elsif ($engine eq 'latex') {
      print "Tikzlatex: ---Correcting '$aux_dir1$base.makefile' made under latex\n";
      system( 'perl', '-i', '-p', '-e', 's/\.epsi/\.ps/', "$aux_dir1$base.makefile" );
    }
    print "Tikzlatex: ---Running 'make -f $aux_dir1$base.makefile' ...\n";
    if ($aux_dir) {
      # latexmk has set $ENV{TEXINPUTS} in this case.
      my $SAVETEXINPUTS = $ENV{TEXINPUTS};
      $ENV{TEXINPUTS} = good_cwd().$search_path_separator.$ENV{TEXINPUTS};
      pushd( $aux_dir );
      $ret = system "make",  "-j", "5", "-f", "$base.makefile";
      &popd;
      $ENV{TEXINPUTS} = $SAVETEXINPUTS;
    }
    else {
      $ret = system "make",  "-j", "5", "-f", "$base.makefile";
    }
    if ($ret) {
      print "Tikzlatex: !!!!!!!!!!!!!! Error from make !!!!!!!!! \n",
            "  The log files for making the figures '$aux_dir1$base-figure*.log'\n",
            "  may have information\n";
    }
  }
  else {
    print "Tikzlatex: No '$aux_dir1$base.makefile', so I won't run make.\n";
  }
  return $ret;
}

Then just run latexmk, which you can do from TeXstudio.

4
  • Where do I have to put that latekmkrc file? Or how does make know that it should use this? Aug 14, 2018 at 11:28
  • I tried the script and it ends up with the same error as before. The script runs through pdflatex once and the starts the make process to create the externalized pictures. After that an additional run of pdflatex seems to be missing. Aug 16, 2018 at 10:26
  • I tried it with a bigger document and this didn't work. The example itself runs perfectly. Are there any hints when changing the document? Aug 16, 2018 at 10:32
  • It's going to be difficult to debug this remotely. I've only tested this with simple examples. One general suggestion: Examine the output of the call to latexmk very carefully to find any errors, and investigate their cause. In this kind of set-up, it's quite easy for there to be an error in the running of make that leads latexmk not to do the last run, but for the details to be not easy to notice or to locate. Aug 18, 2018 at 16:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .