tikztag.sty (5700B)
1 %%%%%%%%%%%%%%%%%%%% tikztag.sty %%%%%%%%%%%%%%%%%%%% 2 % This code is released under the CC0 license (i.e. in the Public Domain 3 % or under a very permissive license if your country does not recognise 4 % dedications to the Public Domain. 5 % Author: Suzanne Soy. 6 %%%%%%%%%% \documentclass{article} 7 %%%%%%%%%% \makeatletter 8 \usepackage{amsmath, tikz, hyperref, lipsum} 9 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 10 % Parse options into: 11 % \if@tikztag@star 12 % \if@tikztag@label@ 13 % \@tikztag@label 14 % \if@tikztag@labeltext@ 15 % \@tikztag@label 16 \newif\if@tikztag@star@ 17 \newif\if@tikztag@label@ 18 \newif\if@tikztag@labeltext@ 19 \def\tikztag{\@ifstar\@tikztag@star\@tikztag@nostar} 20 \def\@tikztag@star{\@tikztag@star@true\expandafter\@tikztag@common} 21 \def\@tikztag@nostar{\@tikztag@star@false\expandafter\@tikztag@common} 22 \def\@tikztag@common{\@ifnextchar[{% 23 \@tikztag@label@true\@tikztag@get@label% 24 }{% 25 \@tikztag@label@false\@tikztag% 26 }} 27 \def\@tikztag@get@label[#1]{\def\@tikztag@label{#1}\expandafter\@tikztag@get@maybe@labeltext} 28 \def\@tikztag@get@maybe@labeltext{\@ifnextchar[{% 29 \@tikztag@labeltext@true\@tikztag@get@labeltext% 30 }{% 31 \@tikztag@labeltext@false\@tikztag% 32 }} 33 \def\@tikztag@get@labeltext[#1]{\def\@tikztag@labeltext{#1}\expandafter\@tikztag} 34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 35 % Implementation: 36 \edef\tikztagnumber{0} 37 \newcommand{\@tikztag}[1]{% 38 % place the marker: 39 \pgfmathtruncatemacro{\tikztagnumber}{\tikztagnumber+1}% 40 \xdef\tikztagnumber{\tikztagnumber}% 41 \tikz[remember picture]\coordinate(tikztagmarker\tikztagnumber){};% 42 % dispatch given the options 43 \expandafter\gdef\csname @tikztag@tag@\tikztagnumber\endcsname{#1}% 44 \if@tikztag@label@% 45 \if@tikztag@labeltext@% 46 \if@tikztag@star@% 47 \edef\@@tikztag{\noexpand\@@@tikztag{\expandafter\noexpand\@tikztag@label}{\expandafter\noexpand\@tikztag@labeltext}{\expandafter\noexpand\csname @tikztag@tag@\tikztagnumber\endcsname}{\tikztagnumber}{\noexpand\@firstoftwo}}% 48 \else% 49 \edef\@@tikztag{\noexpand\@@@tikztag{\expandafter\noexpand\@tikztag@label}{\expandafter\noexpand\@tikztag@labeltext}{(\expandafter\noexpand\csname @tikztag@tag@\tikztagnumber\endcsname)}{\tikztagnumber}{\noexpand\@firstoftwo}}% 50 \fi% 51 \else% 52 \if@tikztag@star@% 53 \edef\@@tikztag{\noexpand\@@@tikztag{\expandafter\noexpand\@tikztag@label}{\expandafter\noexpand\csname @tikztag@tag@\tikztagnumber\endcsname}{\expandafter\noexpand\csname @tikztag@tag@\tikztagnumber\endcsname}{\tikztagnumber}{\noexpand\@firstoftwo}}% 54 \else% 55 \edef\@@tikztag{\noexpand\@@@tikztag{\expandafter\noexpand\@tikztag@label}{\expandafter\noexpand\csname @tikztag@tag@\tikztagnumber\endcsname}{(\expandafter\noexpand\csname @tikztag@tag@\tikztagnumber\endcsname)}{\tikztagnumber}{\noexpand\@firstoftwo}}% 56 \fi% 57 \fi% 58 \else% 59 \if@tikztag@star@% 60 \edef\@@tikztag{\noexpand\@@@tikztag{no label}{no label text}{\expandafter\noexpand\csname @tikztag@tag@\tikztagnumber\endcsname}{\tikztagnumber}{\noexpand\@secondoftwo}}% 61 \else% 62 \edef\@@tikztag{\noexpand\@@@tikztag{no label}{no label text}{(\expandafter\noexpand\csname @tikztag@tag@\tikztagnumber\endcsname)}{\tikztagnumber}{\noexpand\@secondoftwo}}% 63 \fi% 64 \fi% 65 \@@tikztag% 66 } 67 \newcommand{\@@@tikztag}[5]{% 68 \g@addto@macro\accumulatetikztag{\@@@@tikztag{#1}{#2}{#3}{#4}{#5}}% 69 } 70 % #1=label #2=label text #3=text #4=\tikztagnumber #5=\@firstoftwo or \@secondoftwo to use label or not 71 \newcommand{\@@@@tikztag}[5]{% 72 \tikz[overlay,remember picture]% 73 \node[anchor=base east, inner xsep=0pt]% 74 at (tikztagmarker#4 -| current line right)% 75 {#3};% 76 #5{% 77 \tikz[overlay,remember picture]% 78 \node[anchor=base east, inner xsep=0pt]% 79 at (tikztagmarker#4 -| current line left)% 80 {\phantomsection\edef\@currentlabel{#2}\label{#1}};% 81 }{} 82 } 83 \def\inittikztag{% 84 \noindent\tikz[remember picture]\coordinate(current line left){};% 85 \tikz[overlay,remember picture]% 86 \coordinate[xshift=\linewidth] (current line right) at (current line left){};% 87 \xdef\accumulatetikztag{}% 88 }% 89 \def\posttikztag{\accumulatetikztag}% 90 \let\@tikztag@old@texMathDisplay\texMathDisplay% 91 \def\texMathDisplay#1{\inittikztag\@tikztag@old@texMathDisplay{#1\posttikztag}}% 92 \newenvironment{taggableequationstar}{% 93 \inittikztag% 94 \begin{equation*}% 95 }{% 96 \end{equation*}% 97 \posttikztag 98 } 99 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 100 %%%%%%%%%%\makeatother 101 %%%%%%%%%%\begin{document} 102 %%%%%%%%%% 103 %%%%%%%%%% 104 %%%%%%%%%%\lipsum[2] 105 %%%%%%%%%%\begin{equation*} 106 %%%%%%%%%% \begin{array}{@{}r@{}c@{}l@{}} 107 %%%%%%%%%% a&bbbbb&c \\ 108 %%%%%%%%%% x&y&z \\ 109 %%%%%%%%%% \end{array} 110 %%%%%%%%%%\end{equation*} 111 %%%%%%%%%%\lipsum[2] 112 %%%%%%%%%%\begin{taggableequationstar} 113 %%%%%%%%%% \begin{array}{@{}r@{}c@{}l@{}} 114 %%%%%%%%%% a&bbbbb&c \tikztag[eq:foo][abc]{a, b and c} \\ 115 %%%%%%%%%% x&y&z \tikztag[eq:bar]{other stuff}\\ 116 %%%%%%%%%% x&y&z \tikztag{more stuff}\\ 117 %%%%%%%%%% \end{array} 118 %%%%%%%%%%\end{taggableequationstar} 119 %%%%%%%%%%Foo: \ref{eq:foo}. Bar: \ref{eq:bar}. Baz: \ref{eq:baz}. Quux: \ref{eq:quux}. 120 %%%%%%%%%%\lipsum[2] 121 %%%%%%%%%%\begin{taggableequationstar} 122 %%%%%%%%%% \begin{array}{@{}r@{}c@{}l@{}} 123 %%%%%%%%%% a&bbbbb&c \tikztag*[eq:baz][baz]{a, b and c (baz)} \\ 124 %%%%%%%%%% x&y&z \tikztag*[eq:quux]{other stuff 2}\\ 125 %%%%%%%%%% x&y&z \tikztag*{more stuff 2}\\ 126 %%%%%%%%%% \end{array} 127 %%%%%%%%%%\end{taggableequationstar} 128 %%%%%%%%%% 129 %%%%%%%%%%\end{document} 130 %%%%%%%%%%%%%%%%%%%% end tikztag.sty %%%%%%%%%%%%%%%%%%%%