4

I want to use \tikzmark outside tikzpicture to remember some coordinates, and then use them inside tikzpicture (it seems a rather standard thing). I have this minimal working example that draws a rectangle:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{tikzmark}

\begin{document}

Some random text outside\tikzmark{label}

\begin{tikzpicture}[remember picture, overlay]
\draw (0.1,0.1) rectangle (pic cs:label);
\end{tikzpicture}

\end{document}

The link to the class is here:

https://www.acm.org/binaries/content/assets/publications/article-templates/sig-alternate-05-2015.cls

Now, the problem happens when I switch to a SIG ACM format, for example this one:

\documentclass{sig-alternate-05-2015}

Then, this error happens (but during the SECOND Latex pass):

! Missing number, treated as zero.
<to be read again> 
                   \thepage 
l.13 \draw (0.1,0.1) rectangle (pic cs:label)
                                             ;
?

Now, I tracked the problem down to the remember picture part - if it's removed, the error disappears. However, it seems crucial to use with the tikzmark feature.

I will be grateful for any hints.

  • for journals it's better to externalize your pictures as you can't be sure whether they will compile enough number of times to get the final result. – percusse Dec 7 '16 at 17:13
  • Thanks! Yes, I would do it if it was just a picture. However, the example above is minimal to make it simple - my ultimate goal is to put these tikz pictures onto a listing, and this cannot be externalized (or at least not easily). – Mac Dec 7 '16 at 17:28
  • Does the class not have page numbers (even invisible ones)? Is this intended for an online format or something? – cfr Dec 7 '16 at 17:56
  • What happens if you add \pagenumbering{arabic} after \begin{document}? [Note: you may get an error. I don't know the class: this is by way of finding stuff out rather than proposing a solution.] – cfr Dec 7 '16 at 17:57
  • Can you provide a link to the class as it is not in TeX Live? – cfr Dec 7 '16 at 17:58
4

The problem is that \thepage is set to \relax in the \write statement and hence is written literally to the aux file, instead of being replaced by the page number. I suggest to patch the tikzmark library such that it doesn't use \thepage. Add the following lines after \usetikzlibrary{tikzmark}.

\usepackage{xpatch}
\expandafter\xpatchcmd
   \csname pgfk@/tikz/every picture/.@cmd\endcsname
   {\thepage}{\arabic{page}}{}{}
  • 3
    I have a vague memory of this being raised before, but the source for tikzmark still has \thepage so I guess if it did then I didn't get round to fixing it. \arabic{page} is far more robust than \thepage so I'll put that in the next release. – Loop Space Dec 7 '16 at 18:32
  • Thank you! This worked like a charm. I also provided the link to the CLS file in the question. – Mac Dec 8 '16 at 9:11

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.