Stack Exchange

“Beware the tikzmark, my son.”

2013-04-18 by . 0 comments

Post to Twitter

It has finally happened. The tikzmark has burst its bonds and is loose upon an unsuspecting TeX public. We can only hope that they are spared the worst of it.

No-one, repeat no-one, should download it from CTAN unless they truly understand the consequences of using the tikzmark. There is a tikzmark support group for those who find themselves (ab)using it and who need help.

The TikZMark

The \tikzmark macro burst onto the scene in a blaze of glory on TeX-SX. Since then, it has proved embarrassingly (to its original author) popular. The idea behind it is extremely simple: that the machinery underneath TikZ provides a way to “mark” a point on a page for further use. This functionality is already provided by several other packages. The point of this one is that as TikZ can provide this feature, if already loading TikZ then it makes sense to use the TikZ version than another version. Moreover, if the goal is to use these marks with some TikZ code then this version is already set up for that purpose (not that it would be exactly difficult to add this to any of the other implementations).

History

I wrote the original \tikzmark macro in 2009 for use in lecture slides prepared with the beamer package. It’s original definition was:

\newcommand{\tikzmark}[1]{\tikz[overlay,remember picture] \node (#1) {};}

Its first use was in the (inelegant) code:

\begin{frame}
\frametitle{Structure of Continuous Functions}
\begin{tikzpicture}[overlay, remember picture]
\useasboundingbox (0,0);
\draw[red,->] (bsp) .. controls +(-1,-1) and ($(cnvs.north)+(1,1)$) .. ($(cnvs.north)+(0,1)$) .. controls ($(cnvs.north)+(-1,1)$) and +(-1,0) .. (cnvs.north);
\draw[green!50!black,->] (cplt) .. controls +(-1,-1) and +(-1,0) .. (mcplt.north);
\draw[blue,->] (norm) .. controls +(-1,-.5) and ($(nvs.north)+(0,1.5)$) .. ($(nvs.north)+(0,1.5)$) .. controls ($(nvs.north)+(-1.5,1.5)$) and +(-1.5,0) .. (nvs.north);
\draw[purple,->] (vector) .. controls +(-1,-1) and ($(vsp.north)+(2,2)$) .. ($(vsp.north)+(0,2)$) .. controls ($(vsp.north)+(-2,2)$) and +(-2,0) .. (vsp.north);
\end{tikzpicture}
\begin{theorem}
\centering
\(\big(C([0,1],\R),d_\infty\big)\) \\
is a \\
\alert{Banach\tikzmark{bsp} space}
\end{theorem}
\pause
\bigskip
\begin{itemize}
\item[\tikzmark{cnvs}] {\color{green!50!black}Comp\tikzmark{cplt}lete} {\color{blue}nor\tikzmark{norm}med} {\color{purple}vector\tikzmark{vector} space}.
\bigskip
\bigskip
\pause
\begin{itemize}[]
\item[\tikzmark{mcplt}] {\color{green!50!black}Cauchy sequences converge.}
\medskip
\item[\tikzmark{nvs}] {\color{blue}Metric from a norm.}
\medskip
\item[\tikzmark{vsp}] {\color{purple}Functions behave like vectors.}
\end{itemize}
\end{itemize}
\end{frame}

This produced, on the final slide, the following figure.

First recorded use of the TikZmark

Its first appearance on TeX-SX was in an answer to a question about how to put overlapping braces on a mathematical text. This was in July 2010. The opening statement of the answer was not overly encouraging: “This may not be the best solution…”. And for a macro that would go on to become quite ubiquitous, its initial appearance only garnered it 2 votes. However, it started out in life as a useful macro for me and as such I found more uses for it in my own code and thus more opportunity for using it to answer questions on TeX-SX. The one that seems to have been where it got noticed came in August 2010, again about putting braces in text but in a more complicated fashion. From this answer, it got picked up, picked over, and picked apart. A common use was in highlighting or adding marks to text. Gradually, as it got used, it developed. A major revision dates from an answer given in March 2012 where the question was actually about \tikzmark. This version added two important features: a TikZ coordinate system for referencing saved marks directly and the ability to refer to marks earlier in the document than they are defined (the mechanism for remembering points uses the aux file anyway so this was more about exposing the information earlier than anything complicated). Then in October 2012 there was a question where it would have been useful to remember which page the mark was on and a question where for some reason using the \tikz macro didn’t work so the \pgfmark macro was introduced.

Extras

As well as the \tikzmark and \pgfmark macros and the coordinate system for referring to the marks in a tikzpicture, the tikzmark package defines a \subnode command for referring to fragments of a node. That is, putting \subnode{name}{content} inside a TikZ node makes name look like a node around its contents as far as TikZ is concerned. This came from the question tikz nodes for subformulae (nested in nodes).

There’s also a plan to build libraries on top of tikzmark that use it to provide other functionality. The first of these is packaged with the main package and is for annotating code listings. It works with the listings package and puts marks at various points on lines of the code. It was inspired by questions such as Marking lines in listings and Macros for code annotations.

Acknowledgements

The \tikzmark macro has been used and abused by many users of TeX-SX. Of particular note (but in no particular order) are Peter Grill, Gonzalo Medina, Claudio Fiandrino, and percusse. I would also like to mention David Carlisle whose knowledge of TikZ continues to astound us all.

Filed under LaTeX Packages TikZ

Subscribe to comments with RSS.

Leave a comment

Log in
with Stack Exchange
or