I have a document with a lot of diagrams created with PGFPlots and want to externalize those. All other tikz snippets should not get externalized. I achieve this by setting \tikzset{external/only named=true}
and give the plots a sweet name.
This seems to work with anything but graphics created by the chemfig
package. Consider following MWE:
% file: chemfigbug.tex
% arara: pdflatex: { action: nonstopmode}
% arara: make: { task: -B -f chemfigbug.makefile }
% arara: pdflatex: { action: nonstopmode}
%
\documentclass{article}
\usepackage{chemfig}
%
\usetikzlibrary{external}
\tikzexternalize[shell escape=-enable-write18]
\tikzsetexternalprefix{extern/}
\tikzset{external/only named=true}
\tikzset{external/mode=list and make}
%
\begin{document}
%
\tikzsetnextfilename{house}
\begin{tikzpicture}
\draw[thick] (0,0) -- (0,2) -- (1,3.25) -- (2,2) -- (2,0) -- (0,2) -- (2,2) -- (0,0) -- (2,0);
\end{tikzpicture}
\begin{equation}
%
%\begin{tikzpicture}
\definesubmol\nobond{-[,0.2,,,draw=none]}
\chemfig[][scale=0.4]{[:30]*6(=-=-=(-*6(-(!\nobond\bullet)=-=-=))-)}
\chemsign{+}\chemfig{C_2H_2}\chemrel{->}
\chemfig[][scale=0.4]{[:30]*6(=-=-=(-*6(-(-=_[0,]-[:-60])=-=-=))-)}
\chemsign{+}\chemfig{H}
%\end{tikzpicture}
\end{equation}
\end{document}
Running make
on the makefile failes to compile. house.log
shows the following error:
Runaway argument?
! File ended while scanning use of \tikzexternal@laTeX@collect@until@end@tikzpicture.
<inserted text>
\par
<*> ...rnalrealjob{chemfigbug}\input{chemfigbug}
A possible solution I found proposed putting the chemfig
-code in a tikzpicture
environment. Uncommenting those commands yields to flawless compilation, however the alignment of the equation gets totally messed up. Not exteralizing the "house" seems to solve it all, but I really need to externalize some in the real use-case.
Update
Further playing around with the code I managed to get horizontal alignment done by introducing not only a tikzpicture
-environment but also putting the chemfig
code into a \node
. Vertically I have been experimenting with the [baseline]
option of tikz
and achieved OK-ish results. Some fine tuning is still required in my view.
What I came up with:
\documentclass{article}
\usepackage{chemfig}
\begin{document}
\begin{equation}
\begin{tikzpicture}[baseline=-1.15ex]
\node at (0,0) {%
\definesubmol\nobond{-[,0.2,,,draw=none]}
\chemfig[][scale=0.4]{[:-30]*6(=-=(-*6(-=-=-=))-(!\nobond\bullet)=-)}
\chemsign{+}\chemfig{C_2H_2}\chemrel{->}
\chemfig[][scale=0.4]{[:-30]*6(=-=*6(-*6(-=-=-=)--=--)-=-)}
\chemsign{+}\chemfig{H}
};
\end{tikzpicture}
\end{equation}
\end{document}
What it looks like:
The alignment with the "(1)" still has room for improvement.
Possible solutions:
- How to make it compile without altering the code for the equation?
How to get the alignment right when putting the equation in asolvedtikzpicture
?- (
Bonus: If someone more adapt with) solvedchemfig
has a prettier solution for my workaround to create the 3-ring I would be more than thankful :)