2

In my document, I have an equation where I would like to connect two parts with an arrow, just as the way, as Alan Munn did it here. When I copy his example using \tikzexternalize, I get the error

! Package tikz Error: Sorry, the system call 'pdflatex -shell-escape -halt-on-error -interaction=batchmode -jobname "texstudio_v59040-figure2" "\def\tikzexternalrealjob{texstudio_v59040}\input{texstudio_v59040}"' did NOT result in a usable output file 'texstudio_v59040-figure2' (expected one of .pdf:.jpg:.jpeg:.png:). Please verify that you have enabled system calls. For pdflatex, this is 'pdflatex -shell-escape'. Sometimes it is also named 'write 18' or something like that. Or maybe the command simply failed? Error messages can be found in 'texstudio_v59040-figure2.log'. If you continue now, I'll try to typeset the picture.

and

! Package pgf Error: No shape named a is known.

! Package pgf Error: No shape named b is known.

My question is whether there is a possible workaround for this problem. Here is the MWE (again, thanks for the original answer)

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{external}
\tikzexternalize

\newcommand{\tikzmark}[1]{\tikz[overlay,remember picture] \node (#1) {};}

\tikzset{square arrow/.style={
    to path={-- ++(0,-.25)  -| (\tikztotarget) \tikztonodes},below,pos=.25}}

\begin{document}
\begin{equation}
  a\tikzmark{a}x^2 + bx + c = 5\tikzmark{b}x^2 + bx + c.
  \tikz[overlay,remember picture]
   {\path[draw,->,square arrow] (b.south) to node{x} (a.south) ;
    }
\end{equation}
\end{document}

EDIT: In the MWE, it is possible to add \tikzset{external/export=false} before and \tikzset{external/export=false} after the equation environment which solves the issue, though in general it would be nicer to have everything externalized to speed up compiling.

  • 1
    This can't work. Even if you would be somehow able to externalize the arrow: Its length depends on the marks, and if you add something to the equation how should a external graphic be able to adapt to the changed locations? – Ulrike Fischer Mar 17 '16 at 15:22
  • @Ulrike: good point, I agree! It would be very complicated to implement a check if the underlying equation changed or not. I'll try to keep very simple in my annotations and implement more "expensive" annotations with equations inside of \tikzpictures – riddleculous Mar 17 '16 at 15:40
2

It probably doesn't take much more time to create this arrow on every compilation compared to including it with \includegraphics.

I suggest you use the idea you had, to disable and enable externalization around the equation. To save you some trouble, you could redefine the equation environment to include this.

Since you're using amsmath, the definition of the environment will be:

\renewenvironment{equation}{%
  \incr@eqnum
  \mathdisplay@push
  \st@rredfalse \global\@eqnswtrue
  \mathdisplay{equation}%
}{%
  \endmathdisplay{equation}%
  \mathdisplay@pop
  \ignorespacesafterend
}

You can change this in your preamble with something like:

\makeatletter
\renewenvironment{equation}{%
  \incr@eqnum
  \mathdisplay@push
  \st@rredfalse \global\@eqnswtrue
  \tikzexternaldisable
  \mathdisplay{equation}%
}{%
  \endmathdisplay{equation}%
  \tikzexternalenable
  \mathdisplay@pop
  \ignorespacesafterend
}
\makeatother

Then you're guaranteed not to run into this problem. I think it will be hard to externalize the arrow since it uses in total three tikz environments, but someone else might have a solution!


Update

Here's a much better solution that saves you the trouble to find the correct definition. Use

\usepackage{etoolbox} 
\AtBeginEnvironment{equation}{\tikzexternaldisable}
\AtEndEnvironment{equation}{\tikzexternalenable}

and substitute equation to what ever environment you want to use. Read more in etoolbox's manual

  • the three tikz "pictures" are what I see as problematic, too. You're right, probably it won't consume so much extra time even though I plan to use many of those arrows. I like the idea with redefining the whole environment. Where did you get the implementation from? I might want to use align or other math environments later. – riddleculous Mar 17 '16 at 14:22
  • 1
    @riddleculous I just found the definition in the question I linked to and added tikzexternaldisable/\tikzexternalenable where it seemed to fit. I updated my answer now with a solution that should work for any environment! – Grimler Mar 17 '16 at 14:43
  • see Ulrike's comment to my posting, it's probably not possible. I'll just use your comfortable etoolbox approach! – riddleculous Mar 17 '16 at 15:42
  • @riddleculous Glad to hear that this is sufficient for you! – Grimler Mar 17 '16 at 16:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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