# tikzmark — suffix use fails

I try to put tikzmarks in tabulars and to prevent to have tikzmarks with the smae name, I use a different prefix in each tabular to create the tikzmarks, but how use them after ?

\documentclass[10pt]{article}
\usepackage{calc,array,tikz,xparse,siunitx,amsmath}
\usetikzlibrary{tikzmark}

\def\CS{pic cs:}

% suffix : different for each tabular
\newcounter{TabEq}

% tikzmark name : different on each line of a tabular
\newcounter{ResEq}[TabEq]

% extra space for \dfrac
\newcommand{\vtab}[1][1.2]{\rule[-0.9em*\real{#1}]{0pt}{2.3em*\real{#1}}}

\NewDocumentEnvironment{arrayl}{sO{rcl}}%
{\setlength{\arraycolsep}{1.5pt}%
% new suffix in each new table
\stepcounter{TabEq}
\IfBooleanTF{#1}{%
$\left\{\begin{array}{#2}}{%$\begin{array}[t]{#2}}%
}%
{\end{array}%
\IfBooleanTF{#1}{\right.$}{$}%
}%

% I prefer not to use it as global, beacause of interraction with
% other tikzmarks in defferent context, but even with a global
% tikzset it dosen't properly.

\tikzset{tikzmark suffix={-\theTabEq}}

\newcommand{\EqFleche}[1]{%
\begin{tikzpicture}[blue,
% as in the marmot's related example, but locally
overlay,
remember picture,
%tikzmark suffix={-\theTabEq} % local use
]
\foreach \Label [count=\i from 1,
evaluate=\i as \j using int(\i+1)]
in {#1} {%
% arrow on a left side between to lines
\draw[-stealth,
shorten >= 2pt,
shorten <= 2pt] (\CS L\i)
to [out=200,in=165,looseness=1.8]
node[midway,anchor=east] {\footnotesize$\Label$}
(\CS L\j) ;
% arrow on a right side between to lines
\draw[-stealth,
shorten >= 1,
shorten <= 1] (\CS R\i)
to [out=-15,in=20,looseness=1.8]
node[midway,anchor=west] {\footnotesize$\Label$}
(\CS R\j) ;
} ;
\end{tikzpicture}%
}

% nouveau \hfill dans un tableau sinon clash avec colortab
\newcommand{\hfilll}{\hspace{0pt plus 1filll}}

% tikzmark on the left side - prefix L
\newcommand{\EqL}{\tikzmark
%[tikzmark suffix={-\theTabEq}] % local use
{L\theResEq}\hfilll}

% tikzmark on the right side - prefix R
\newcommand{\EqR}{\hfilll\tikzmark
%[tikzmark suffix={-\theTabEq}] %local use
{R\theResEq}%
% step the line counter
\stepcounter{ResEq}}

\pagestyle{empty}

\begin{document}

% a table with tikzmark left and right on each lines
4x-5    &= 7 \\
4x      &= 12 \\
x       &= 3 \\
\end{arrayl}

We are in tabular \theTabEq.
% put the arrows on the sides :
\EqFleche{+5,\div4}

But the arrow are alsewhere ...

\medskip

% idem
7x+3    &= 9-3x \\
10x+3   &= 9 \\
10x     &= 6 \\
x       &= \num{.6} \\
\end{arrayl}

\EqFleche{+3x,-3,\div10}

\medskip

\dfrac{x}{2}-3  &=  12\\
\smash[t]{\vtab}\dfrac{x}{2}    &=  15\\
x               &=  30\\
\end{arrayl}

\EqFleche{+3,\times2}

\end{document}

• Your code is too complicated for me to understand, but here you can find another example that provides unique tikzmark nodes by invoking \stepcounter{tmkcount} in an arguably more elegant way. (At least, this code even I can understand.;-) – user121799 Apr 2 '18 at 14:01
• I have used this example to make my code, but setting globally or locally tikzmark suffix={-\theTabEq} makes things different but not correct. I put some comments to make it more clear, my elegant \stepcounter{TabEq} invocation was hidden in the arrayl environment. – Tarass Apr 2 '18 at 14:40

My Frenglish is not very good, but I hope to have fixed it. I only shifted one counter, and marked it in the code.

\documentclass[10pt]{article}
\usepackage{calc,array,tikz,xparse,siunitx,amsmath}
\usetikzlibrary{tikzmark}

\def\CS{pic cs:}

\newcounter{TabEq}

\newcounter{ResEq}[TabEq]

% extra space for \dfrac
\newcommand{\vtab}[1][1.2]{\rule[-0.9em*\real{#1}]{0pt}{2.3em*\real{#1}}}

\NewDocumentEnvironment{arrayl}{sO{rcl}}%
{\setlength{\arraycolsep}{1.5pt}%
% new suffix in each new table
\stepcounter{TabEq}
\IfBooleanTF{#1}{%
$\left\{\begin{array}{#2}}{%$\begin{array}[t]{#2}}%
}%
{\end{array}%
\IfBooleanTF{#1}{\right.$}{$}%
}%

\tikzset{tikzmark suffix={-\theTabEq}}

\newcommand{\EqFleche}[1]{%
\begin{tikzpicture}[blue,
% as in the marmot's related example, but locally
overlay,
remember picture,
%tikzmark suffix={-\theTabEq} % local use
]
\foreach \Label [count=\i from 0, %<- this is the only thing I changed
evaluate=\i as \j using int(\i+1)]
in {#1} {%
% arrow on a left side between to lines
\draw[-stealth,
shorten >= 2pt,
shorten <= 2pt] ([yshift=1.1mm]\CS L\i)
to [out=200,in=165,looseness=1.8]
node[midway,anchor=east] {\footnotesize$\Label$}
([yshift=1.3mm]\CS L\j) ;
% arrow on a right side between to lines
\draw[-stealth,
shorten >= 1,
shorten <= 1] ([yshift=1.1mm]\CS R\i)
to [out=-15,in=20,looseness=1.8]
node[midway,anchor=west] {\footnotesize$\Label$}
([yshift=1.3mm]\CS R\j) ;
} ;
\end{tikzpicture}%
}

% new \hfill since original clashes with colortab
\newcommand{\hfilll}{\hspace{0pt plus 1filll}}

% tikzmark on the left side - prefix L
\newcommand{\EqL}{\tikzmark
%[tikzmark suffix={-\theTabEq}] % local use
{L\theResEq}\hfilll}

% tikzmark on the right side - prefix R
\newcommand{\EqR}{\hfilll\tikzmark
%[tikzmark suffix={-\theTabEq}] %local use
{R\theResEq}%
% step the line counter
\stepcounter{ResEq}}

\pagestyle{empty}

\begin{document}

% a table with tikzmark left and right on each lines
4x-5    &= 7 \\
4x      &= 12 \\
x       &= 3 \\
\end{arrayl}

We are in tabular \theTabEq.
\EqFleche{+5,\div4}

And the arrows are where they should be.

\medskip

7x+3    &= 9-3x \\
10x+3   &= 9 \\
10x     &= 6 \\
x       &= \num{.6} \\
\end{arrayl}

\EqFleche{+3x,-3,\div10}

\medskip

\dfrac{x}{2}-3  &=  12\\
\smash[t]{\vtab}\dfrac{x}{2}    &=  15\\
x               &=  30\\
\end{arrayl}

\EqFleche{+3,\times2}

\end{document}

• Of course thank you, as in the precedent version with only one counter, it started from 1, and now from 0. Thank you very much for your effort. – Tarass Apr 2 '18 at 16:45
• @Tarass I really like your idea. Very useful for kids and ducks! In my update I moved the arrows a bit up and apart, what do you think? – user121799 Apr 2 '18 at 18:45
• Yes thay had to moved up. I was my try to convert from custom tikzmarks to tikzmak library. My custom tzm contained the vertical shift. Finally I gave up with the library because of the mess caused the fact that prefix stuff has to be global and interrac with other tmz that are not in a tabular. Your is fine and nice. For a room purpose and to avoid big arrows when lines are bigger like in the third example, I turn to square arrows that don't horizontaly expand. Sorry for my frenglish ;-) and thank you your involment. – Tarass Apr 2 '18 at 19:46
• Finally it will look like this : dropbox.com/s/uwhrj1t4n1518gb/EqArrows.png?dl=0 – Tarass Apr 2 '18 at 20:20
• @Tarass Congratulations! Looks nice! (In France, you write 6/10 as 0,6 rather than 0.6 ?) – user121799 Apr 2 '18 at 20:25