3

I have a somehow curious problem. I have a large document with a list of acronyms, several glossaries, plots and an index. For the creation of the list of acronyms and the glossaries I use the glossaries package. As the creation of the pgfplots and tikz plots can take some time, I use \usepgfplotslibrary{external} to externalize the figure creation. Finally, I use imakeidx for the creation of my index. Currently, there is only one index, but a second one is planned. The index is the last thing I added to my document.

The following thing happens: If I add \printindex[$INDEXNAME] to my document, all of a sudden the externalization of pgfplots does not work. No pdf is created for the figures and in my original document I get an error: Package imakeidx Error: Misplaced \printindex. However, in the MWE I get another error: ! No room for a new \write.

Before adding the \printindex everything worked fine. Also, I have no problem with the compilation if I disable the externalization or use one less glossary.

Is this problem related to the limited amount of registers in TeX? How can I circumvent this behavior? I thought I had this covered using the packages morewrites and a hack to filecontents from this thread.


Unfortunately not so MWE

\documentclass{scrreprt}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Header                           %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 
% Compilation: %S - main tex source file name
% 
%   pdflatex %S.tex
%   makeindex -s %S.ist -t %S.slg1 -o %S.syi1 %S.syg1
%   makeindex -s %S.ist -t %S.slg2 -o %S.syi2 %S.syg2
%   ...
%   pdflatex %S.tex
%   pdflatex %S.tex

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Preamble                         %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\usepackage{blindtext}
\usepackage{filecontents}
% http://tex.stackexchange.com/a/312910/44634 for fixing clash between filecontents and morewrites
\newwrite\fcwrite
\makeatletter
\let\zzzz\filec@ntents
\def\filec@ntents{\def\chardef##1\write{\let\reserved@c\fcwrite}\zzzz}
\makeatother
\usepackage[
  acronym,
  toc,
]{glossaries}
\usepackage{imakeidx}
\usepackage{morewrites}
\usepackage{pgfplots}
\usepackage{tabu}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Own glossaries                   %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newglossary[slg1]{list1}{syi1}{syg1}{List 1}
\newglossary[slg2]{list2}{syi2}{syg2}{List 2}
\newglossary[slg3]{list3}{syi3}{syg3}{List 3}
\newglossary[slg4]{list4}{syi4}{syg4}{List 4}
\newglossary[slg5]{list5}{syi5}{syg5}{List 5}
\newglossary[slg6]{list6}{syi6}{syg6}{List 6}
\newglossary[slg7]{list7}{syi7}{syg7}{List 7}
\newglossary[slg8]{list8}{syi8}{syg8}{List 8}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Symbols                          %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newglossaryentry{symb:coordinate:xyz:l1}{%
  symbol      ={\ensuremath{x$,$y$,$z}},%
  name        ={},%
  description ={Entry},%
  type        =list1,%
  sort        =rlxyz,%
}

\newglossaryentry{symb:coordinate:xyz:l2}{%
  symbol      ={\ensuremath{x$,$y$,$z}},%
  name        ={},%
  description ={Entry},%
  type        =list2,%
  sort        =rlxyz,%
}

\newglossaryentry{symb:coordinate:xyz:l3}{%
  symbol      ={\ensuremath{x$,$y$,$z}},%
  name        ={},%
  description ={Entry},%
  type        =list3,%
  sort        =rlxyz,%
}

\newglossaryentry{symb:coordinate:xyz:l4}{%
  symbol      ={\ensuremath{x$,$y$,$z}},%
  name        ={},%
  description ={Entry},%
  type        =list4,%
  sort        =rlxyz,%
}

\newglossaryentry{symb:coordinate:xyz:l5}{%
  symbol      ={\ensuremath{x$,$y$,$z}},%
  name        ={},%
  description ={Entry},%
  type        =list5,%
  sort        =rlxyz,%
}

\newglossaryentry{symb:coordinate:xyz:l6}{%
  symbol      ={\ensuremath{x$,$y$,$z}},%
  name        ={},%
  description ={Entry},%
  type        =list6,%
  sort        =rlxyz,%
}

\newglossaryentry{symb:coordinate:xyz:l7}{%
  symbol      ={\ensuremath{x$,$y$,$z}},%
  name        ={},%
  description ={Entry},%
  type        =list7,%
  sort        =rlxyz,%
}

\newglossaryentry{symb:coordinate:xyz:l8}{%
  symbol      ={\ensuremath{x$,$y$,$z}},%
  name        ={},%
  description ={Entry},%
  type        =list8,%
  sort        =rlxyz,%
}

\newacronym{GPL}{GPL}{GNU General Public License}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Own styles                       %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\renewcommand*{\glspostdescription}{}

\newglossarystyle{myacronymstyle}{%
  \renewenvironment{theglossary}%
    {\begin{longtabu} to \linewidth {lX}}%
    {\end{longtabu}}%
  \renewcommand*{\glossaryheader}{}%
  \renewcommand*{\glsgroupskip}{\tabularnewline}%
  \renewcommand*{\glossaryentryfield}[5]{%
    \glsentryitem{##1}\glstarget{##1}{##2} 
      & ##3\glspostdescription ##5\\
  }
}

\newglossarystyle{myglostyle}{%
  \renewcommand*{\glsclearpage}{}%
  \renewenvironment{theglossary}%
    {\begin{longtabu} to \linewidth {cX}}%
    {\end{longtabu}}%
  % Header line
  \renewcommand*{\glossaryheader}{%
    \textbf{Symbol} & \textbf{Description}%
    \tabularnewline%
    \tabularnewline%
    \endhead%
    \endfoot%
  }%
  \renewcommand*{\glsgroupskip}{\tabularnewline}
  \renewcommand*{\glossentry}[1]{%
    \glsentryitem{##1}
    \glstarget{##1}{\glossentrysymbol{##1}} &
    \glossentrydesc{##1}        %& % Description
    \tabularnewline%
  }%
}

\makeglossaries

% ---------------------------
% Setup
% ---------------------------

\indexsetup{%
  level=\chapter*,%
  toclevel=chapter,%
}

\newcommand{\idxKeywordName}{Keyword}

\makeindex[%
  name=\idxKeywordName,%
  title=\idxKeywordName{} index,
  intoc,
]

% ---------------------------
% Externalization
% ---------------------------

\pgfplotsset{compat=1.15}
\usepgfplotslibrary{external}
\tikzexternalize[%
  mode=convert with system call,%
  shell escape=-enable-write18,% Use for MiKTeX
]
\tikzsetexternalprefix{ZZZ_TikZ/}
\tikzset{%
  external/system call={%
    pdflatex \tikzexternalcheckshellescape -halt-on-error %
    -interaction=batchmode -jobname "\image" "\texsource"% && %
    %convert -density 600 -transparent white "\image.pdf" "\image.png"
  }
}
\tikzexternaldisable

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Document                         %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}

\clearpage
\chapter*{List of Symbols}

\setglossarysection{section}
\addcontentsline{toc}{chapter}{List of Symbols}

\printglossary[type=list1,style=myglostyle,nonumberlist]
\printglossary[type=list2,style=myglostyle,nonumberlist]
\printglossary[type=list3,style=myglostyle,nonumberlist]
\printglossary[type=list4,style=myglostyle,nonumberlist]
\printglossary[type=list5,style=myglostyle,nonumberlist]
\printglossary[type=list6,style=myglostyle,nonumberlist]
\printglossary[type=list7,style=myglostyle,nonumberlist]
\printglossary[type=list8,style=myglostyle,nonumberlist]

% Acronyms
\setglossarysection{chapter}
\printglossary[type=\acronymtype,style=myacronymstyle,nonumberlist]

\glsaddall

\chapter{First chapter}

Index entry 1\index[\idxKeywordName]{Entry 1}. \blindtext[1]

\begin{figure}[htbp]
  \centering
  \tikzexternalenable
  \tikzsetnextfilename{Test}
  \begin{tikzpicture}
    \node (image) at (0,0) {\includegraphics[width=0.5\linewidth]{example-image-a}};
  \end{tikzpicture}
  \tikzexternaldisable
  \caption{A figure}
  \label{fig:Figure}
\end{figure}

\blindtext[1]

\chapter{Second chapter}

Index entry 2\index[\idxKeywordName]{Entry 2}. \blindtext[4]

\printindex[\idxKeywordName]

\end{document}

No error is given if:

  • \tikzexternalenable,\tikzsetnextfilename & \tikzexternaldisable is commented out
  • \printindex is not used
  • everyhting belonging to list8 is commented out

Update

I found the reason for the error in my original document compared to the "not so MWE". However, I don't know what causes it exactly.

If I put the imakeidx-related parts of the preamble, especially \makeindex[...]

\indexsetup{%
  level=\chapter*,%
  toclevel=chapter,%
}

\newcommand{\idxKeywordName}{Keyword}

\makeindex[%
  name=\idxKeywordName,%
  title=\idxKeywordName{} index,
  intoc,
]

before the externalization-part of pgfplots

\pgfplotsset{compat=1.15}
\usepgfplotslibrary{external}
\tikzexternalize[%
  mode=convert with system call,%
  shell escape=-enable-write18,% Use for MiKTeX
]
\tikzsetexternalprefix{ZZZ_TikZ/}
\tikzset{%
  external/system call={%
    pdflatex \tikzexternalcheckshellescape -halt-on-error %
    -interaction=batchmode -jobname "\image" "\texsource"% && %
    %convert -density 600 -transparent white "\image.pdf" "\image.png"
  }
}
\tikzexternaldisable

everything works and the external figures are created correctly. If I switch the positions in the preamble, no external figs are created and I get the above mentioned error Package imakeidx Error: Misplaced \printindex.

Any idea why this happens?


This works

\documentclass{scrreprt}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Header                           %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 
% Compilation: %S - main tex source file name
% 
%   pdflatex %S.tex
%   makeindex -s %S.ist -t %S.slg1 -o %S.syi1 %S.syg1
%   makeindex -s %S.ist -t %S.slg2 -o %S.syi2 %S.syg2
%   ...
%   pdflatex %S.tex
%   pdflatex %S.tex

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Preamble                         %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\usepackage{blindtext}
\usepackage{filecontents}
% http://tex.stackexchange.com/a/312910/44634 for fixing clash between filecontents and morewrites
\newwrite\fcwrite
\makeatletter
\let\zzzz\filec@ntents
\def\filec@ntents{\def\chardef##1\write{\let\reserved@c\fcwrite}\zzzz}
\makeatother
\usepackage[
  acronym,
  toc,
]{glossaries}
\usepackage{imakeidx}
\usepackage{morewrites}
\usepackage{pgfplots}
\usepackage{scrwfile}
\usepackage{tabu}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Own glossaries                   %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newglossary[slg1]{list1}{syi1}{syg1}{List 1}
\newglossary[slg2]{list2}{syi2}{syg2}{List 2}
\newglossary[slg3]{list3}{syi3}{syg3}{List 3}
\newglossary[slg4]{list4}{syi4}{syg4}{List 4}
\newglossary[slg5]{list5}{syi5}{syg5}{List 5}
\newglossary[slg6]{list6}{syi6}{syg6}{List 6}
\newglossary[slg7]{list7}{syi7}{syg7}{List 7}
\newglossary[slg8]{list8}{syi8}{syg8}{List 8}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Symbols                          %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newglossaryentry{symb:coordinate:xyz:l1}{%
  symbol      ={\ensuremath{x$,$y$,$z}},%
  name        ={},%
  description ={Entry},%
  type        =list1,%
  sort        =rlxyz,%
}

\newglossaryentry{symb:coordinate:xyz:l2}{%
  symbol      ={\ensuremath{x$,$y$,$z}},%
  name        ={},%
  description ={Entry},%
  type        =list2,%
  sort        =rlxyz,%
}

\newglossaryentry{symb:coordinate:xyz:l3}{%
  symbol      ={\ensuremath{x$,$y$,$z}},%
  name        ={},%
  description ={Entry},%
  type        =list3,%
  sort        =rlxyz,%
}

\newglossaryentry{symb:coordinate:xyz:l4}{%
  symbol      ={\ensuremath{x$,$y$,$z}},%
  name        ={},%
  description ={Entry},%
  type        =list4,%
  sort        =rlxyz,%
}

\newglossaryentry{symb:coordinate:xyz:l5}{%
  symbol      ={\ensuremath{x$,$y$,$z}},%
  name        ={},%
  description ={Entry},%
  type        =list5,%
  sort        =rlxyz,%
}

\newglossaryentry{symb:coordinate:xyz:l6}{%
  symbol      ={\ensuremath{x$,$y$,$z}},%
  name        ={},%
  description ={Entry},%
  type        =list6,%
  sort        =rlxyz,%
}

\newglossaryentry{symb:coordinate:xyz:l7}{%
  symbol      ={\ensuremath{x$,$y$,$z}},%
  name        ={},%
  description ={Entry},%
  type        =list7,%
  sort        =rlxyz,%
}

\newglossaryentry{symb:coordinate:xyz:l8}{%
  symbol      ={\ensuremath{x$,$y$,$z}},%
  name        ={},%
  description ={Entry},%
  type        =list8,%
  sort        =rlxyz,%
}

\newacronym{GPL}{GPL}{GNU General Public License}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Own styles                       %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\renewcommand*{\glspostdescription}{}

\newglossarystyle{myacronymstyle}{%
  \renewenvironment{theglossary}%
    {\begin{longtabu} to \linewidth {lX}}%
    {\end{longtabu}}%
  \renewcommand*{\glossaryheader}{}%
  \renewcommand*{\glsgroupskip}{\tabularnewline}%
  \renewcommand*{\glossaryentryfield}[5]{%
    \glsentryitem{##1}\glstarget{##1}{##2} 
      & ##3\glspostdescription ##5\\
  }
}

\newglossarystyle{myglostyle}{%
  \renewcommand*{\glsclearpage}{}%
  \renewenvironment{theglossary}%
    {\begin{longtabu} to \linewidth {cX}}%
    {\end{longtabu}}%
  % Header line
  \renewcommand*{\glossaryheader}{%
    \textbf{Symbol} & \textbf{Description}%
    \tabularnewline%
    \tabularnewline%
    \endhead%
    \endfoot%
  }%
  \renewcommand*{\glsgroupskip}{\tabularnewline}
  \renewcommand*{\glossentry}[1]{%
    \glsentryitem{##1}
    \glstarget{##1}{\glossentrysymbol{##1}} &
    \glossentrydesc{##1}        %& % Description
    \tabularnewline%
  }%
}

\makeglossaries

% ---------------------------
% Setup
% ---------------------------

\indexsetup{%
  level=\chapter*,%
  toclevel=chapter,%
}

\newcommand{\idxKeywordName}{Keyword}

\makeindex[%
  name=\idxKeywordName,%
  title=\idxKeywordName{} index,
  intoc,
]

% ---------------------------
% Externalization
% ---------------------------
% THIS MUST COME AFTER \makeindex[...] from above to avoid error

\pgfplotsset{compat=1.15}
\usepgfplotslibrary{external}
\tikzexternalize[%
  mode=convert with system call,%
  shell escape=-enable-write18,% Use for MiKTeX
]
\tikzsetexternalprefix{ZZZ_TikZ/}
\tikzset{%
  external/system call={%
    pdflatex \tikzexternalcheckshellescape -halt-on-error %
    -interaction=batchmode -jobname "\image" "\texsource"% && %
    %convert -density 600 -transparent white "\image.pdf" "\image.png"
  }
}
\tikzexternaldisable

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Document                         %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}

\clearpage
\chapter*{List of Symbols}

\setglossarysection{section}
\addcontentsline{toc}{chapter}{List of Symbols}

\printglossary[type=list1,style=myglostyle,nonumberlist]
\printglossary[type=list2,style=myglostyle,nonumberlist]
\printglossary[type=list3,style=myglostyle,nonumberlist]
\printglossary[type=list4,style=myglostyle,nonumberlist]
\printglossary[type=list5,style=myglostyle,nonumberlist]
\printglossary[type=list6,style=myglostyle,nonumberlist]
\printglossary[type=list7,style=myglostyle,nonumberlist]
\printglossary[type=list8,style=myglostyle,nonumberlist]

% Acronyms
\setglossarysection{chapter}
\printglossary[type=\acronymtype,style=myacronymstyle,nonumberlist]

\glsaddall

\chapter{First chapter}

Index entry 1\index[\idxKeywordName]{Entry 1}. \blindtext[1]

\begin{figure}[htbp]
  \centering
  \tikzexternalenable
  \tikzsetnextfilename{Test}
  \begin{tikzpicture}
    \node (image) at (0,0) {\includegraphics[width=0.5\linewidth]{example-image-a}};
  \end{tikzpicture}
  \tikzexternaldisable
  \caption{A figure}
  \label{fig:Figure}
\end{figure}

\blindtext[1]

\chapter{Second chapter}

Index entry 2\index[\idxKeywordName]{Entry 2}. \blindtext[4]

\printindex[\idxKeywordName]

\end{document}

This does not work

\documentclass{scrreprt}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Header                           %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 
% Compilation: %S - main tex source file name
% 
%   pdflatex %S.tex
%   makeindex -s %S.ist -t %S.slg1 -o %S.syi1 %S.syg1
%   makeindex -s %S.ist -t %S.slg2 -o %S.syi2 %S.syg2
%   ...
%   pdflatex %S.tex
%   pdflatex %S.tex

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Preamble                         %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\usepackage{blindtext}
\usepackage{filecontents}
% http://tex.stackexchange.com/a/312910/44634 for fixing clash between filecontents and morewrites
\newwrite\fcwrite
\makeatletter
\let\zzzz\filec@ntents
\def\filec@ntents{\def\chardef##1\write{\let\reserved@c\fcwrite}\zzzz}
\makeatother
\usepackage[
  acronym,
  toc,
]{glossaries}
\usepackage{imakeidx}
\usepackage{morewrites}
\usepackage{pgfplots}
\usepackage{scrwfile}
\usepackage{tabu}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Own glossaries                   %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newglossary[slg1]{list1}{syi1}{syg1}{List 1}
\newglossary[slg2]{list2}{syi2}{syg2}{List 2}
\newglossary[slg3]{list3}{syi3}{syg3}{List 3}
\newglossary[slg4]{list4}{syi4}{syg4}{List 4}
\newglossary[slg5]{list5}{syi5}{syg5}{List 5}
\newglossary[slg6]{list6}{syi6}{syg6}{List 6}
\newglossary[slg7]{list7}{syi7}{syg7}{List 7}
\newglossary[slg8]{list8}{syi8}{syg8}{List 8}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Symbols                          %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newglossaryentry{symb:coordinate:xyz:l1}{%
  symbol      ={\ensuremath{x$,$y$,$z}},%
  name        ={},%
  description ={Entry},%
  type        =list1,%
  sort        =rlxyz,%
}

\newglossaryentry{symb:coordinate:xyz:l2}{%
  symbol      ={\ensuremath{x$,$y$,$z}},%
  name        ={},%
  description ={Entry},%
  type        =list2,%
  sort        =rlxyz,%
}

\newglossaryentry{symb:coordinate:xyz:l3}{%
  symbol      ={\ensuremath{x$,$y$,$z}},%
  name        ={},%
  description ={Entry},%
  type        =list3,%
  sort        =rlxyz,%
}

\newglossaryentry{symb:coordinate:xyz:l4}{%
  symbol      ={\ensuremath{x$,$y$,$z}},%
  name        ={},%
  description ={Entry},%
  type        =list4,%
  sort        =rlxyz,%
}

\newglossaryentry{symb:coordinate:xyz:l5}{%
  symbol      ={\ensuremath{x$,$y$,$z}},%
  name        ={},%
  description ={Entry},%
  type        =list5,%
  sort        =rlxyz,%
}

\newglossaryentry{symb:coordinate:xyz:l6}{%
  symbol      ={\ensuremath{x$,$y$,$z}},%
  name        ={},%
  description ={Entry},%
  type        =list6,%
  sort        =rlxyz,%
}

\newglossaryentry{symb:coordinate:xyz:l7}{%
  symbol      ={\ensuremath{x$,$y$,$z}},%
  name        ={},%
  description ={Entry},%
  type        =list7,%
  sort        =rlxyz,%
}

\newglossaryentry{symb:coordinate:xyz:l8}{%
  symbol      ={\ensuremath{x$,$y$,$z}},%
  name        ={},%
  description ={Entry},%
  type        =list8,%
  sort        =rlxyz,%
}

\newacronym{GPL}{GPL}{GNU General Public License}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Own styles                       %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\renewcommand*{\glspostdescription}{}

\newglossarystyle{myacronymstyle}{%
  \renewenvironment{theglossary}%
    {\begin{longtabu} to \linewidth {lX}}%
    {\end{longtabu}}%
  \renewcommand*{\glossaryheader}{}%
  \renewcommand*{\glsgroupskip}{\tabularnewline}%
  \renewcommand*{\glossaryentryfield}[5]{%
    \glsentryitem{##1}\glstarget{##1}{##2} 
      & ##3\glspostdescription ##5\\
  }
}

\newglossarystyle{myglostyle}{%
  \renewcommand*{\glsclearpage}{}%
  \renewenvironment{theglossary}%
    {\begin{longtabu} to \linewidth {cX}}%
    {\end{longtabu}}%
  % Header line
  \renewcommand*{\glossaryheader}{%
    \textbf{Symbol} & \textbf{Description}%
    \tabularnewline%
    \tabularnewline%
    \endhead%
    \endfoot%
  }%
  \renewcommand*{\glsgroupskip}{\tabularnewline}
  \renewcommand*{\glossentry}[1]{%
    \glsentryitem{##1}
    \glstarget{##1}{\glossentrysymbol{##1}} &
    \glossentrydesc{##1}        %& % Description
    \tabularnewline%
  }%
}

\makeglossaries

% ---------------------------
% Externalization
% ---------------------------
% THIS MUST COME AFTER \makeindex[...] to avoid error

\pgfplotsset{compat=1.15}
\usepgfplotslibrary{external}
\tikzexternalize[%
  mode=convert with system call,%
  shell escape=-enable-write18,% Use for MiKTeX
]
\tikzsetexternalprefix{ZZZ_TikZ/}
\tikzset{%
  external/system call={%
    pdflatex \tikzexternalcheckshellescape -halt-on-error %
    -interaction=batchmode -jobname "\image" "\texsource"% && %
    %convert -density 600 -transparent white "\image.pdf" "\image.png"
  }
}
\tikzexternaldisable

% ---------------------------
% Setup
% ---------------------------

\indexsetup{%
  level=\chapter*,%
  toclevel=chapter,%
}

\newcommand{\idxKeywordName}{Keyword}

\makeindex[%
  name=\idxKeywordName,%
  title=\idxKeywordName{} index,
  intoc,
]

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Document                         %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}

\clearpage
\chapter*{List of Symbols}

\setglossarysection{section}
\addcontentsline{toc}{chapter}{List of Symbols}

\printglossary[type=list1,style=myglostyle,nonumberlist]
\printglossary[type=list2,style=myglostyle,nonumberlist]
\printglossary[type=list3,style=myglostyle,nonumberlist]
\printglossary[type=list4,style=myglostyle,nonumberlist]
\printglossary[type=list5,style=myglostyle,nonumberlist]
\printglossary[type=list6,style=myglostyle,nonumberlist]
\printglossary[type=list7,style=myglostyle,nonumberlist]
\printglossary[type=list8,style=myglostyle,nonumberlist]

% Acronyms
\setglossarysection{chapter}
\printglossary[type=\acronymtype,style=myacronymstyle,nonumberlist]

\glsaddall

\chapter{First chapter}

Index entry 1\index[\idxKeywordName]{Entry 1}. \blindtext[1]

\begin{figure}[htbp]
  \centering
  \tikzexternalenable
  \tikzsetnextfilename{Test}
  \begin{tikzpicture}
    \node (image) at (0,0) {\includegraphics[width=0.5\linewidth]{example-image-a}};
  \end{tikzpicture}
  \tikzexternaldisable
  \caption{A figure}
  \label{fig:Figure}
\end{figure}

\blindtext[1]

\chapter{Second chapter}

Index entry 2\index[\idxKeywordName]{Entry 2}. \blindtext[4]

\printindex[\idxKeywordName]

\end{document}
raedma
  • 1,794
  • 1
    Since you're using nonumberlist you could try adding savewrites to the glossaries package's option list. This saves the glossary indexing information in a token register for the associated glossary which is then written at the end of the document. (This makes it susceptible to TeX's asynchronous output routine, so I wouldn't recommend it without the nonumberlist setting.) It's slower but it requires fewer write registers. – Nicola Talbot Sep 28 '17 at 15:52
  • On a first try with my MWE this seems to help as well as using \usepackage{scrwfile} as explained in the glossaries package documentation. However, I get the same error as before for my actual document :( – raedma Sep 28 '17 at 16:13
  • 1
    I found a fix for my problem. If I put \makeindex[...] before tikz/pgfplots externalization, my figures are created externally and the index is created. If I switch their order in the preamble, I get the error from my actual document. Any ideas why this happens? – raedma Nov 01 '17 at 16:48
  • I had a similar issue appear out of nowhere (it used to work without, and still works on my CI, no TeXLive update in between); with \makeglossaries. I had to put \makeglossaries above the call to \tikzexternalize, it wouldn't work after, even if calling makeglossaries manually. I used some glossary entries in the externalized plots, and log files for externalized jobs complained that see= needed \makeglossaries, even though it was in the preamble, just after the externalize macro. Hope this helps someone else. – MayeulC Apr 13 '23 at 09:29

0 Answers0