Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

At the beginning of my document I have \input{tikzcommands} where tikzcommands.tex contains global settings that I want to use in the TikZ pictures. For example, in this file I define some styles.

The problem, when using the externalize library it doesn't recognizes when something changed with the tikzcommands.tex. I tried to add something like \tikzpicturedependsonfile{tikzcommands.tex} at the beginning of the TikZ environment, but it didn't help.

What is the right way to make figureA.tex (which is included using input) depended on a settings file tikzcommands.tex?

EDIT: Due to the comment of @Psirus I know that I'm doing something wrong. But I still don't manage to have the desired behavior, even when trying to use mode=list and make. Here is my original pseudo MWE.

First, I load TikZ

\usepackage{tikz}
\usetikzlibrary{snakes,calc,decorations.pathreplacing,patterns}

Then, I have the following

\makeatletter
\IfFileExists{tikzexternal.sty}
{%
  \usetikzlibrary{external}%
  \tikzexternalize%
  \tikzsetexternalprefix{figures/cache/}%
  \renewcommand{\todo}[2][]{%
    \tikzexternaldisable\@todo[##1]{##2}\tikzexternalenable}%
}%
{%
  % Empty else case
}%
\makeatother

Which checks is externalize is available, or not. This part I have to make the code compatible with older distributions of pgf which do not support the externalize package.

Then I have an included file tikzcommands.tex which contains (among other things)

\tikzset{
        robot/.style={thick,fill=green!#1},
        obstacle/.style={fill=red!80,thick}
}

Finally in the document's body I have inputs of the following form:

\input{./figures/figureA} 

In figureA I use the styles robot and obstacle.

I want to use externalize in such a way that even when I just change the file tikzcommands.tex the figures which depend on it will be re-compiled.

I understand that I have to:

  1. Change the loading of the externalize package.
  2. Add something before each input which depends on the tikzcommands.tex
  3. Probably change the building workflow. Currently I'm using latexmk alone.

I tried several combinations but nothing worked for me. I hope someone could draw the way to accomplish this.

share|improve this question
1  
please share your code (MWE), it makes it easier to debug for others. Furthermore, there are several ways to use the external library, please show/state the exact process. –  zeroth Feb 9 '13 at 20:28
    
\tikzpicturedependsonfile is only supported for mode=list and make, which is not the default. What mode are you using? –  Psirus Feb 10 '13 at 7:34
add comment

1 Answer

First off, I don't know latexmk, so my solution doesn't integrate nicely, but I guess you can adapt my crude Makefile to your latexmk logic.

The main file, here main.tex:

\documentclass{scrartcl}

\usepackage{tikz}

\makeatletter
\IfFileExists{tikzexternal.sty}
{%
  \usetikzlibrary{external}%
  \tikzset{external/mode=list and make}
  \tikzexternalize%
  \tikzsetexternalprefix{figures/cache/}%
}%
{%
  % Empty else case
}%
\makeatother

\input{tikzcommands}

\begin{document}
    \input{./figures/figureA}
\end{document}

Instead of generating the pictures directly, pdflatex now writes a main.makefile for the images. The dependency on tikzcommands.tex is set in the picture file figure/figureA.tex:

\begin{tikzpicture}
    \tikzpicturedependsonfile{tikzcommands.tex}
    \draw[myRectangle] (0,0) rectangle (2,2);
\end{tikzpicture}

And to make the example complete, a dummy tikzcommands.tex:

\tikzset{
        myRectangle/.style={thick}
}

Now you can run make -f main.makefile to make the pictures, and only rebuild them when their sources or tikzcommands.tex changes. A very crude Makefile would be:

main.pdf: main.tex
    pdflatex main.tex;
    make -f main.makefile
    latexmk -pdf main.tex

But this runs pdflatex once unnecessarily, and really displays my ignorance regarding latexmk. I'm sure you can add the line make -f main.makefile to the latexmk logic so that it is run after a first pass of pdflatex.

share|improve this answer
    
Thanks for the effort! After changing the tikzcommands.tex and running pdflatex, when I invoke the make -f main.makefile I get All images exist now. Use make -B to re-generate them. It doesn't see the change in the file. Can it be a path problem in \tikzpicturedependsonfile{tikzcommands.tex}? figureA is in ./figures and 'tikzcommands.tex is in . –  Dror Feb 10 '13 at 12:51
    
Once the main.makefile is created, the images are (re)build when I run make -f main.makefile. When I then change something in tikzcommands.tex, make -f main.makefile (re)builds the pictures AND outputs All images exist now.... There is no need to run pdflatex if you only change tikzcommands.tex to rebuild the pictures. My directory is set up just as yours. –  Psirus Feb 10 '13 at 12:58
    
Something is still not working for me. I I change something in tikzcommands.tex then neither make -f... nor make -B... nor pdflatex builds the right final result. I don't understand. –  Dror Feb 10 '13 at 19:41
    
Even when tikzcommands was changed, make -B... returns Nothing to be done for main.makefile'.` Somehow, it doesn't detect that there was a change with the tikzcommand –  Dror Feb 10 '13 at 19:43
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.