Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hyperref with bookmarks=true and tikzexternalize clashes in edge cases #1127

Open
ORippler opened this issue Jan 14, 2022 · 14 comments
Open
Labels

Comments

@ORippler
Copy link

ORippler commented Jan 14, 2022

Brief outline of the bug

Apparently, there are some edge-cases where hyperref with bookmarks=true and tikzexternalize clash, leading to failed resolution of refs

Minimal working example (MWE)

Consider the following MWE (thanks @JasonGross for producing this).

%\PassOptionsToPackage{bookmarks=false}{hyperref} % This fixes the problem
\documentclass{acmart}
\usepackage{tikz}
\usepackage{pgfplots}
\usepgfplotslibrary{external}
\tikzexternalize
\begin{document}
\title{}
\begin{abstract} \end{abstract}
\maketitle
\section{XXXXXXXXX}\subsection{X XXXXXXXXXX XXXXXXX}\subsection{XXXXXXXX XX XXXXXXXXXXXXXXXXX XXXX}\subsection{XXX XXXXXXXX}
\section{XXXXXX XXXXXXXXXX XXX XXXXXXXXX}\subsection{XXX XXXXXXXX XX XXXX XXXXX}
\section{XXX XXXXXXXXX XX X XXXXXXXX}\subsection{XXXXXXXXXXXXXXXX XXXXXXXXXXX XXX XXXXXXXXXX}
\subsection{XXXXXX XXXXXXXXXXXX XXXXXXXX}
\section{XXXXXXX XXXXXXXXXX}\subsection{XXXXXXXX XXXXXXXXXXXX XXXX XX XXXXX}\subsection{XXXXXXX XXXXXXX XX XXXXXXX}
\subsection{XXXXX XXXX XXXX XXXXXXXXXX}\subsection{XXXX XXXXXXXXXX XXXX XXXXXXXX XXXXXXXXXXXXXX}
\subsection{XXXXXXXXXXX XXX XXXXXXXXXXXXX}
\section{XXXXXXXXXX}\subsection{XXXXXXXXXXXXXXX}
\begin{equation}\label{eq:equation}
    x+x^2
\end{equation}
\begin{tikzpicture}
    \begin{axis}
        \addplot [color=black,solid,line width=1.0pt,domain=0:1,samples=11]{x+x^2};
        \addlegendentry{Eq. \ref{eq:equation}};
    \end{axis}
\end{tikzpicture}
\subsubsection{XXXXXXXXX XXXXX XXXXXXX}\subsubsection{XXXXXXXXXXX XXXXXXXXXXX XX XXXXXXXXXXXXXXX XXXXXXXXX}
\subsubsection{XXXXXXX XXX XXXXXXXXX XXXXXXXXX}\subsubsection{XXXX XXXXXXXXX}\subsection{XXXXXXXXXXXXXXX XXXX XXXXXXXXXXXX}
\section{XXXXXXX XXXX}
\section{XXXXXX XXXX}
\end{document}

Compiling the above document with
docker run --rm -it --volume "`pwd`:/workdir" -w "/workdir" --user `id -u`:`id -g` registry.gitlab.com/islandoftex/images/texlive:TL2021-2022-01-09-04-05 pdflatex -shell-escape test.tex fails, and the ref used inside the tikzpicture is never resolved.
However, when providing \PassOptionsToPackage{bookmarks=false}{hyperref}, and thereby disabling the bookmarks functionality, the code compiles just fine and the ref is resolved properly.

Note that I also found the same clash to happen with \documentclass{IEEEtran}, which is why I guess that it's an interaction related between tikz and hyperref, rather than a problem with \documentclass{acmart}. Related package versions are,

Package: hyperref 2021-06-07 v7.00m
Package: tikz 2021/05/15 v3.1.9a (3.1.9a)

and full reproducibility should be given by the docker image.
Since I don't know the exact interactions which cause the issue and how to best resolve them, I have also crossposted the Issue to hyperref.

Best,
ORippler

@hmenke
Copy link
Member

hmenke commented Jan 14, 2022

hyperref messes with PDF objects. When you include a file that has the same xrefs as the original file they will clash. You will have to find out which commands generate the problematic xrefs and then use

\tikzexternalize[optimize=true,optimize command away=\ProblematicHyperrefCommand]

@ORippler
Copy link
Author

ORippler commented Jan 14, 2022

While I will certainly read up on this, it's unclear to me how this relates to the fact that the MWE can be "fixed" by removing the whitespace between \begin{abstract} \end{abstract} (refer borisveytsman/acmart#436 for other "fixes").

The error message for the tikzexternalized figure under the MWE is

(/usr/local/texlive/2021/texmf-dist/tex/generic/gettitlestring/gettitlestring.s
ty
Package: gettitlestring 2019/12/15 v1.6 Cleanup title references (HO)
)
\c@section@level=\count337
)
LaTeX Info: Redefining \ref on input line 7.
LaTeX Info: Redefining \pageref on input line 7.
LaTeX Info: Redefining \nameref on input line 7.
(./test.out)
Runaway argument?
{ 
! File ended while scanning use of \@@BOOKMARK.
<inserted text> 
                \par 
l.7 \begin{document}

indicating that something with the bookmarks written to test.out is wrong (i.e. \section commands etc.).

The "broken" bookmarks written to test.out are

\BOOKMARK [1][-]{section*.1}{\376\377\000A\000b\000s\000t\000r\000a\000c\000t}{}% 1
\BOOKMARK [1][-]{section.1}{\376\377\0001\000\040\000X\000X\000X\000X\000X\000X\000X\000X\000X}{}% 2
\BOOKMARK [2][-]{subsection.1.1}{\376\377\0001\000.\0001\000\040\000X\000\040\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000\040\000X\000X\000X\000X\000X\000X\000X}{section.1}% 3
\BOOKMARK [2][-]{subsection.1.2}{\376\377\0001\000.\0002\000\040\000X\000X\000X\000X\000X\000X\000X\000X\000\040\000X\000X\000\040\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000\040\000X\000X\000X\000X}{section.1}% 4
\BOOKMARK [2][-]{subsection.1.3}{\376\377\0001\000.\0003\000\040\000X\000X\000X\000\040\000X\000X\000X\000X\000X\000X\000X\000X}{section.1}% 5
\BOOKMARK [1][-]{section.2}{\376\377\0002\000\040\000X\000X\000X\000X\000X\000X\000\040\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000\040\000X\000X\000X\000\040\000X\000X\000X\000X\000X\000X\000X\000X\000X}{}% 6
\BOOKMARK [2][-]{subsection.2.1}{\376\377\0002\000.\0001\000\040\000X\000X\000X\000\040\000X\000X\000X\000X\000X\000X\000X\000X\000\040\000X\000X\000\040\000X\000X\000X\000X\000\040\000X\000X\000X\000X\000X}{section.2}% 7
\BOOKMARK [1][-]{section.3}{\376\377\0003\000\040\000X\000X\000X\000\040\000X\000X\000X\000X\000X\000X\000X\000X\000X\000\040\000X\000X\000\040\000X\000\040\000X\000X\000X\000X\000X\000X\000X\000X}{}% 8
\BOOKMARK [2][-]{subsection.3.1}{\376\377\0003\000.\0001\000\040\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000\040\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000\040\000X\000X\000X\000\040\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X}{section.3}% 9
\BOOKMARK [2][-]{subsection.3.2}{\376\377\0003\000.\0002\000\040\000X\000X\000X\000X\000X\000X\000\040\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000\040\000X\000X\000X\000X\000X\000X\000X\000X}{section.3}% 10
\BOOKMARK [1][-]{section.4}{\376\377\0004\000\040\000X\000X\000X\000X\000X\000X\000X\000\040\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X}{}% 11
\BOOKMARK [2][-]{subsection.4.1}{\376\377\0004\000.\0001\000\040\000X\000X\000X\000X\000X\000X\000X\000X\000\040\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000\040\000X\000X\000X\000X\000\040\000X\000X\000\040\000X\000X\000X\000X\000X}{section.4}% 12
\BOOKMARK [2][-]{subsection.4.2}{\376\377\0004\000.\0002\000\040\000X\000X\000X\000X\000X\000X\000X\000\040\000X\000X\000X\000X\000X\000X\000X\000\040\000X\000X\000\040\000X\000X\000X\000X\000X\000X\000X}{section.4}% 13
\BOOKMARK [2][-]{subsection.4.3}{\376\377\0004\000.\0003\000\040\000X\000X\000X\000X\000X\000\040\000X\000X\000X\000X\000\040\000X\000X\000X\000X\000\040\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X}{section.4}% 14
\BOOKMARK [2][-]{subsection.4.4}{\376\377\0004\000.\0004\000\040\000X\000X\000X\000X\000\040\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000\040\000X\000X\000X\000X\000\040\000X\000X\000X\000X\000X\000X\000X\000X\000\040\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X}{section.4}% 15
\BOOKMARK [2][-]{subsection.4.5}{\376\377\0004\000.\0005\000\040\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000\040\000X\000X\000X\000\040\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X}{section.4}% 16
\BOOKMARK [1][-]{section.5}{\376\377\0005\000\040\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X}{}% 17
\BOOKMARK [2][-]{subsection.5.1}{\376\377\0005\000.\0001\000\040\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X}{section.5}% 18
\BOOKMARK [2][-]{subsection.5.2}{\376\377\0005\000.\0002\000\040\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000\040\000X\000X\000X\000X\000\040\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X}{section.5}% 19
\BOOKMARK [1][-]{section.6}{\376\377\0006\000\040\000X\000X\000X\000X\000X\000X\000X\000\040\000X\000X\000X\000X}{}% 20
\BOOKMARK [1][-]{section.7}{\376\377\0007\000\040\000X\000X\000X\000X\000X\000X\000\040\000X\000X\000X\000X}{}% 21

whereas the bookmarks yielded by removing the whitespaces (& where compilation suceeds) are

\BOOKMARK [1][-]{section.1}{\376\377\0001\000\040\000X\000X\000X\000X\000X\000X\000X\000X\000X}{}% 1
\BOOKMARK [2][-]{subsection.1.1}{\376\377\0001\000.\0001\000\040\000X\000\040\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000\040\000X\000X\000X\000X\000X\000X\000X}{section.1}% 2
\BOOKMARK [2][-]{subsection.1.2}{\376\377\0001\000.\0002\000\040\000X\000X\000X\000X\000X\000X\000X\000X\000\040\000X\000X\000\040\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000\040\000X\000X\000X\000X}{section.1}% 3
\BOOKMARK [2][-]{subsection.1.3}{\376\377\0001\000.\0003\000\040\000X\000X\000X\000\040\000X\000X\000X\000X\000X\000X\000X\000X}{section.1}% 4
\BOOKMARK [1][-]{section.2}{\376\377\0002\000\040\000X\000X\000X\000X\000X\000X\000\040\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000\040\000X\000X\000X\000\040\000X\000X\000X\000X\000X\000X\000X\000X\000X}{}% 5
\BOOKMARK [2][-]{subsection.2.1}{\376\377\0002\000.\0001\000\040\000X\000X\000X\000\040\000X\000X\000X\000X\000X\000X\000X\000X\000\040\000X\000X\000\040\000X\000X\000X\000X\000\040\000X\000X\000X\000X\000X}{section.2}% 6
\BOOKMARK [1][-]{section.3}{\376\377\0003\000\040\000X\000X\000X\000\040\000X\000X\000X\000X\000X\000X\000X\000X\000X\000\040\000X\000X\000\040\000X\000\040\000X\000X\000X\000X\000X\000X\000X\000X}{}% 7
\BOOKMARK [2][-]{subsection.3.1}{\376\377\0003\000.\0001\000\040\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000\040\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000\040\000X\000X\000X\000\040\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X}{section.3}% 8
\BOOKMARK [2][-]{subsection.3.2}{\376\377\0003\000.\0002\000\040\000X\000X\000X\000X\000X\000X\000\040\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000\040\000X\000X\000X\000X\000X\000X\000X\000X}{section.3}% 9
\BOOKMARK [1][-]{section.4}{\376\377\0004\000\040\000X\000X\000X\000X\000X\000X\000X\000\040\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X}{}% 10
\BOOKMARK [2][-]{subsection.4.1}{\376\377\0004\000.\0001\000\040\000X\000X\000X\000X\000X\000X\000X\000X\000\040\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000\040\000X\000X\000X\000X\000\040\000X\000X\000\040\000X\000X\000X\000X\000X}{section.4}% 11
\BOOKMARK [2][-]{subsection.4.2}{\376\377\0004\000.\0002\000\040\000X\000X\000X\000X\000X\000X\000X\000\040\000X\000X\000X\000X\000X\000X\000X\000\040\000X\000X\000\040\000X\000X\000X\000X\000X\000X\000X}{section.4}% 12
\BOOKMARK [2][-]{subsection.4.3}{\376\377\0004\000.\0003\000\040\000X\000X\000X\000X\000X\000\040\000X\000X\000X\000X\000\040\000X\000X\000X\000X\000\040\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X}{section.4}% 13
\BOOKMARK [2][-]{subsection.4.4}{\376\377\0004\000.\0004\000\040\000X\000X\000X\000X\000\040\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000\040\000X\000X\000X\000X\000\040\000X\000X\000X\000X\000X\000X\000X\000X\000\040\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X}{section.4}% 14
\BOOKMARK [2][-]{subsection.4.5}{\376\377\0004\000.\0005\000\040\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000\040\000X\000X\000X\000\040\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X}{section.4}% 15
\BOOKMARK [1][-]{section.5}{\376\377\0005\000\040\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X}{}% 16
\BOOKMARK [2][-]{subsection.5.1}{\376\377\0005\000.\0001\000\040\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X}{section.5}% 17
\BOOKMARK [2][-]{subsection.5.2}{\376\377\0005\000.\0002\000\040\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000\040\000X\000X\000X\000X\000\040\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X\000X}{section.5}% 18
\BOOKMARK [1][-]{section.6}{\376\377\0006\000\040\000X\000X\000X\000X\000X\000X\000X\000\040\000X\000X\000X\000X}{}% 19
\BOOKMARK [1][-]{section.7}{\376\377\0007\000\040\000X\000X\000X\000X\000X\000X\000\040\000X\000X\000X\000X}{}% 20

How exactly does this relate to your proposed fix (sorry I am very unfamiliar with latex internals such as xref) ? I can also not find any common typesetting errors/formatting errors of the first \BOOKMARK, that was removed by removing the whitespace in the abstract.

Best,

@hmenke
Copy link
Member

hmenke commented Jan 14, 2022

It seems like I misunderstood your problem. I thought the problem was that the reference inside the plot is not clickable, but you are now telling me that there is a Runaway argument error. However, I cannot reproduce this error on the latest TL 2021.

@ORippler
Copy link
Author

ORippler commented Jan 14, 2022

It seems like I misunderstood your problem. I thought the problem was that the reference inside the plot is not clickable, but you are now telling me that there is a Runaway argument error. However, I cannot reproduce this error on the latest TL 2021.

Weird as the docker image also uses latest TL2021. Could you try to reproduce with the provided docker image/command ? I have attached failing test.tex as well as the associated logfiles generated by running

docker run --rm -it --volume "`pwd`:/workdir" -w "/workdir" --user `id -u`:`id -g` registry.gitlab.com/islandoftex/images/texlive:TL2021-2022-01-09-04-05 pdflatex -shell-escape test.tex

twice on test.tex

test.zip

@hmenke
Copy link
Member

hmenke commented Jan 14, 2022

I'm also not able to reproduce the Runaway argument with the container. Howerver, it's not running in Docker but in Singularity instead:

singularity exec docker://registry.gitlab.com/islandoftex/images/texlive:TL2021-2022-01-09-04-05 pdflatex -shell-escape test.tex

Of course I have to run this twice to get the cross-references right.

@JasonGross
Copy link

I think there's a typo in the command. Try using lualatex rather than pdflatex. Here's a complete log (with system packages rather than docker, though): https://github.com/JasonGross/test-latex-errors/runs/4817894720?check_suite_focus=true

@u-fischer
Copy link
Contributor

u-fischer commented Jan 14, 2022

I can reproduce the error. The tikz picture contains a reference and so tikz reschedules the compilation in the enddocument/afteraux hook:

===== tikzexternal: \end{document} reached. Working on rescheduled images to resolve references... ========
===== 'mode=convert with system call': Invoking 'pdflatex -shell-escape -jobname "test-utf8-figure0" "\def\tikzexternalrealjob{test-utf8}\input{test-utf8}"' ========
runsystem(pdflatex -shell-escape -jobname "test-utf8-figure0" "\def\tikzexternalrealjob{test-utf8}\input{test-utf8}")...executed.

This rescheduled compilation also reads in auxiliary files. That is ok for the aux-file which has already been closed, but can be a problem for other auxiliary files. Not everyone is explicitly closed, often packages simply let the end of the compilation automatically close a file. Here it now breaks for the out-file from hyperref: it is still open from the main compilation and in a more or less random state and when the rescheduled compilation reads it in again it breaks (or not) depending on more or less random conditions like timing and pagebreaks).

hyperref could probably do something like

\makeatletter
\AddToHook{enddocument/afteraux}[hyperref]{\@ifundefined{@outlinefile}{}{\immediate\closeout\@outlinefile}}
\makeatother

but this wouldn't resolve similar problems with other packages.

Btw my test file is

\documentclass{article}
\usepackage[bookmarksnumbered]{hyperref}

\makeatletter
\AddToHook{enddocument/afteraux}[hyperref]{\@ifundefined{@outlinefile}{}{\immediate\closeout\@outlinefile}}
\makeatother
\usepackage{tikz}
\usepackage{pgfplots}
\usepgfplotslibrary{external}
\tikzexternalize
%to get a better log message
\pgfkeyssetvalue{/tikz/external/system call}{%
            pdflatex \tikzexternalcheckshellescape -jobname "\image" "\texsource"%
        }%

\begin{document}
\title{}
\begin{abstract} \end{abstract}
\maketitle
\section{XXXXXXXXX}\subsection{X XXXXXXXXXX XXXXXXX}\subsection{XXXXXXXX XX XXXXXXXXXXXXXXXXX XXXX}\subsection{XXX XXXXXXXX}
\section{XXXXXX XXXXXXXXXX XXX XXXXXXXXX}\subsection{XXX XXXXXXXX XX XXXX XXXXX}
\section{XXX XXXXXXXXX XX X XXXXXXXX}\subsection{XXXXXXXXXXXXXXXX XXXXXXXXXXX XXX XXXXXXXXXX}
\subsection{XXXXXX XXXXXXXXXXXX XXXXXXXX}
\section{XXXXXXX XXXXXXXXXX}\subsection{XXXXXXXX XXXXXXXXXXXX XXXX XX XXXXX}\subsection{XXXXXXX XXXXXXX XX XXXXXXX}
\subsection{XXXXX XXXX XXXX XXXXXXXXXX}\subsection{XXXX XXXXXXXXXX XXXX XXXXXXXX XXXXXXXXXXXXXX}
\subsection{XXXXXXXXXXX XXX XXXXXXXXXXXXX}
\section{XXXXXXXXXX}\subsection{XXXXXXXXXXXXXXX}
\begin{equation}\label{eq:equation}
    x+x^2
\end{equation}
\begin{tikzpicture}
    \begin{axis}
        \addplot [color=black,solid,line width=1.0pt,domain=0:1,samples=11]{x+x^2};
        \addlegendentry{Eq. \ref{eq:equation}};
    \end{axis}
\end{tikzpicture}
\subsubsection{XXXXXXXXX XXXXX XXXXXXX}\subsubsection{XXXXXXXXXXX XXXXXXXXXXX XX XXXXXXXXXXXXXXX XXXXXXXXX}
\subsubsection{XXXXXXX XXX XXXXXXXXX XXXXXXXXX}\subsubsection{XXXX XXXXXXXXX}\subsection{XXXXXXXXXXXXXXX XXXX XXXXXXXXXXXX}
\section{XXXXXXX XXXX}
\section{XXXXXX XXXX XXXXXX XXXX XXXXXX XXXX XXXXXX XXXX XXXXXX XXXX XXXXXX XXXX }
\section{XXXXXX XXXX XXXXXX XXXX XXXXXX XXXX XXXXXX XXXX XXXXXX XXXX XXXXXX XXXX }
\section{XXXXXX XXXX XXXXXX XXXX XXXXXX XXXX XXXXXX XXXX XXXXXX XXXX XXXXXX XXXX }
\section{XXXXXX XXXX XXXXXX XXXX XXXXXX XXXX XXXXXX XXXX XXXXXX XXXX XXXXXX XXXX }
\end{document}

@muzimuzhi
Copy link
Member

I can reproduce the problem locally on a latest texlive 2021 (installed on macOS), but with a condition contrast to what reported in borisveytsman/acmart#436 (comment)

  • Using pdflatex rather than lualatex makes the error go away (but I cannot use pdflatex in my real example because some of my plots are too big)

In my case, pdflatex always throws error while lualatex works fine.

Here it now breaks for the out-file from hyperref: it is still open from the main compilation and in a more or less random state and when the rescheduled compilation reads it in again it breaks (or not) depending on more or less random conditions like timing and pagebreaks).

I can see that when the second system call halts, the test.out ends with an incomplete \BOOKMARK

\BOOKMARK [1][-]{section.7}{\376\377\0007\000\040\000X\000X\000X\000X\000X\000X\000\040\000X\000X\000X\000X}{
% in the form of 
% \BOOKMARK[1][-]{...}{...

and when the compilation ends, it completes to

\BOOKMARK [1][-]{section.7}{\376\377\0007\000\040\000X\000X\000X\000X\000X\000X\000\040\000X\000X\000X\000X}{}% 21
% in the form of 
% \BOOKMARK[1][-]{...}{...}{} % 21

@mrpiggi
Copy link

mrpiggi commented Jan 14, 2022

I can reproduce the error. The tikz picture contains a reference and so tikz reschedules the compilation in the enddocument/afteraux hook:

So, would using the enddocument/end hook instead be a possible solution?

@u-fischer
Copy link
Contributor

So, would using the enddocument/end hook instead be a possible solution?

I don't think so. The problem is the same: files from the main compilations can still be open. If you look at the code in latex.ltx then you can see that the three hooks are more or less at the same place:

     \UseOneTimeHook{enddocument/afteraux}%
     \UseOneTimeHook{enddocument/info}%
   \endgroup
   \UseOneTimeHook{enddocument/end}%

@JasonGross
Copy link

According to tex.se, there doesn't seem to be a way to flush files without closing them. Would it make sense to add primitives to (lua)(pdf)(la)tex to flush files, and to ensure that bookmark writing is flushed, at least at these sort of hook boundaries?

@muzimuzhi
Copy link
Member

As a workaround specific for this use case, one can restrict the bookmarks=false hyperref setting to the external system call

\tikzset{external/system call={%
  pdflatex \tikzexternalcheckshellescape -halt-on-error-interaction=batchmode -jobname "\image"
  "\string\PassOptionsToPackage{bookmarks=false}{hyperref}\texsource"}}

It seems to work as far as the externalized tikzpicture envs have have nothing to do with the bookmarks.

@ORippler
Copy link
Author

As a workaround specific for this use case, one can restrict the bookmarks=false hyperref setting to the external system call

\tikzset{external/system call={%
  pdflatex \tikzexternalcheckshellescape -halt-on-error-interaction=batchmode -jobname "\image"
  "\string\PassOptionsToPackage{bookmarks=false}{hyperref}\texsource"}}

It seems to work as far as the externalized tikzpicture envs have have nothing to do with the bookmarks.

According to this source the workaround would fail if hyperref is loaded explicitly with bookmarks=true somewhere in the document, as this will override the value provided via \PassOptionsToPackage

@ORippler
Copy link
Author

ORippler commented Feb 22, 2022

I am facing the same issue again for the table of contents generated by the scrbook class from KOMA-script

Any ideas for a potential work-around/a generic solution ?

Edit:
The workaround for scrbook was to load the scrwfile package, which redefines & overrides \@starttoc
und \@writefile for the table of contents (refer chapter 14 of the KOMA-Script documentation)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

6 participants