Arrows between adjustbox minted blocks in two columns using tikzmarks?

I'd like to

• put two minted source code blocks in two beamer columns
• with arrows pointing between the two (tikzmark-based)
• and use adjustbox to scale the code blocks down to columnwidth

This works ok without adjustbox (based on Is it possible to use tikzmark inside minted? and Drawing overlay graphics over minted code, mostly). See the first frame in the sample below.

However, when surrounding the minted blocks with adjustbox/varwidth environments for scaling, the tikzmarks appear to be off and store wrong positions (which make intuitive sense). See second frame in the example below. Putting the second tikzpicture at different places in the frame makes a difference, but all options I tried produced in correct results.

(Side remark: of course these code examples are stupid; just to make the effect pronounced).

Illustration: The first version works, but does not scale the code blocks.

With an adjustbox, the red arrow is all over the place:

\documentclass[ignorenonframetext,nooutline]{beamer}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\usepackage{minted}
\usetheme[hideothersubsections]{Goettingen}

\begin{document}

\begin{columns}
\tiny
\begin{column}{0.5\columnwidth}

\begin{minted}[frame=lines,linenos=true,autogobble,escapeinside=??]{c}
int main (void)
{
zmq_send (sender, "Some long text to have a wide line", 5, 0); ?\tikzmark{start}?

return 0;
}

\end{minted}

\end{column}

\begin{column}{0.5\columnwidth}

\begin{minted}[frame=lines,linenos=true,autogobble,escapeinside=??]{c}
int main (void)
{
// some comment
// some more comment

?\tikzmark{eend}? zmq_receive (s, buffer, 100, 0);
}

\end{minted}

\end{column}

\begin{tikzpicture}[remember picture]
\draw [overlay, ->, line width=5pt, red] (pic cs:start) -- (pic cs:eend);
\end{tikzpicture}

\end{columns}
\end{frame}

% ------------------------

\begin{columns}
\begin{column}{0.5\columnwidth}
\begin{block}{Sender}
\begin{varwidth}{\columnwidth}

\begin{minted}[frame=lines,linenos=true,mathescape=true,escapeinside=??]{c}
int main (void)
{
zmq_send (sender, "Some long text to have a wide line", 5, 0); ?\tikzmark{start1}?

return 0;
}
\end{minted}

\end{varwidth}
\end{block}
\end{column}

\begin{column}{0.5\columnwidth}
\begin{varwidth}{\columnwidth}

\begin{minted}[frame=lines,linenos=true,mathescape=true,escapeinside=??]{c}
int main (void)
{
// some comment
// some more comment

?\tikzmark{end2}? zmq_receive (s, buffer, 100, 0);
}
\end{minted}

\end{varwidth}
\end{block}
\end{column}

\begin{tikzpicture}[remember picture]
\draw[overlay, ->, line width=5pt, red] (pic cs:start1) -- (pic cs:end1);
\end{tikzpicture}

\end{columns}
\end{frame}

\end{document}

• For what it is worth: there does not seem to be any nice way of doing this. breaklines options of minted is not ideal, but seems to do the job for me. (listings package not much different in this respect). Would be interesting to understand the interplay of tikzmark and adjustbox better, though... – Holger Karl Apr 16 '18 at 18:31

Scaling fonts is not a good idea, either manually select an appropriate font size (which is already very small, so probably nobody will be able to read it) or you could use a linebreak instead of scaling:

% !TeX program = txs:///arara
% arara: pdflatex: {synctex: on, interaction: nonstopmode, shell: yes}
\documentclass{beamer}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\usepackage{minted}

\begin{document}

\begin{columns}
\tiny
\begin{column}{0.48\columnwidth}
\begin{minted}[frame=lines,linenos=true,autogobble,escapeinside=??,breaklines]{c}
int main (void)
{
zmq_send (sender, "Some long text to have a wide line", 5, 0); ?\tikzmark{start}?

return 0;
}
\end{minted}
\end{column}
\begin{column}{0.48\columnwidth}
\begin{minted}[frame=lines,linenos=true,autogobble,escapeinside=??,breaklines]{c}
int main (void)
{
// some comment
// some more comment

?\tikzmark{eend}? zmq_receive (s, buffer, 100, 0);
}
\end{minted}
\end{column}
\begin{tikzpicture}[remember picture]
\draw [overlay, ->, line width=5pt, red] (pic cs:start) -- (pic cs:eend);
\end{tikzpicture}
\end{columns}
\end{frame}

\end{document}


• As I said, the example is artifical. Scaling will be necessary for longer examples; the \tiny is in here just for demonstration. I'd much rather not use font scaling, of course - as you correctly, point out. – Holger Karl Apr 8 '18 at 8:23