pgf-tikz / pgf

A Portable Graphic Format for TeX
https://pgf-tikz.github.io/
1.14k stars 108 forks source link

[external] improve support for \cite in externalized pictures #648

Open Naikless opened 5 years ago

Naikless commented 5 years ago

Currently I can only successfully use \cite inside an externalized tikzpicture if

This seems like it is generally possible but the correct command to recompile the tikzpicture after the first main comilation seems to fail without the \ref.

Additionally, is there a setting to force tikz to always use the pdf (=overwrite the up-to-date check to true)? Apart from just adding .pdf to the file name.

hmenke commented 5 years ago

You can just use \nocite{...} before the picture where you use the references if you don't want to cite them elsewhere. You shouldn't have to add \ref to make it work but it's impossible to tell without MWE, therefore closing it for now. Once a MWE is added I will reopen.

You can set external/up to date check=simple. That will just check whether the file exists rather than whether it changed. Therefore it will only rerun if the output file was deleted or if force remake or remake next was given.

Naikless commented 5 years ago

Sorry for the missing MWE, I have looked further into this and found natbib to be the cause:

MWE:

\documentclass{article}

% it works when commenting out the following line 
\usepackage{natbib}

\usepackage{pgfplots}
\usepgfplotslibrary{external}
% deactivating externalization also works
\tikzexternalize

\begin{filecontents}{bib.bib}
    @article{dummy}
\end{filecontents}

\begin{document}

    % \nocite is required in any case
    \nocite{dummy}

    \begin{tikzpicture}
    \node{\cite{dummy}};
    \end{tikzpicture}

    \bibliographystyle{plain}
    \bibliography{bib}

\end{document}

Can't tell whether the fault lies with natbib or with the external library, but disabling externalization also works.