Consider the following MCE that makes use of:
tikzmarklibrary and itslistingslibrary that let us add marks tolstlistingenvironments,- the high level
\balloonmacro (provided by thetikzmark's author in https://tex.stackexchange.com/a/86457/18401) that puts a fancy node behind certain lines of the code (it is here a bit modified in order to avoid overlapping of the line preceding the first one wanted, see Jellby's comment on Mar 9 '14 at 18:26 in https://tex.stackexchange.com/a/79787/18401).
The point is, this code works nicely with e.g. the article class but not with the beamer one: with the latter, the node isn't displayed.
% \documentclass{beamer}
\documentclass{article}\usepackage{beamerarticle}
%
\usepackage{listings}
\usepackage{tikz}
\usetikzlibrary{tikzmark,fit,calc}
\usetikzmarklibrary{listings}
\lstset{basicstyle=\ttfamily}
\tikzset{
balloon/.style={
draw,
fill=blue!20,
opacity=0.4,
inner sep=4pt,
rounded corners=2pt
},
}
%
\newcommand{\balloon}[4]{%
\pgfmathtruncatemacro\firstline{%
#3-1%
}%
\iftikzmark{line-#2-\firstline-start}{%
\iftikzmark{line-#2-#3-first}{%
\xdef\blines{($ ({pic cs:line-#2-\firstline-start} -| {pic
cs:line-#2-#3-first})!.5!({pic cs:line-#2-#3-first}) $)}%
}{%
\iftikzmark{line-#2-#3-start}{%
\xdef\blines{({pic cs:line-#2-\firstline-start} -| {pic
cs:line-#2-#3-start})}%
}{%
\xdef\blines{(pic cs:line-#2-\firstline-start)}%
}%
}%
}{%
\xdef\blines{}%
}%
\foreach \k in {#3,...,#4} {%
\iftikzmark{line-#2-\k-first}{%
\xdef\blines{\blines (pic cs:line-#2-\k-first) }%
}{} \iftikzmark{line-#2-\k-end}{%
\xdef\blines{\blines (pic cs:line-#2-\k-end) }%
}{}%
}%
\ifx\blines\empty
\else
\edef\temp{\noexpand\tikz[remember picture,overlay]
\noexpand\node[fit={\blines},balloon] (#1) {};}%
\temp
\fi
}
%
\begin{document}
\begin{frame}[fragile]
\balloon{comment}{code}{3}{4}
\begin{lstlisting}[name=code]
Foo Bar Baz
Foo Baz Bar
Bar Foo Baz
Bar Baz Foo
Baz Foo Bar
Baz Bar Foo
\end{lstlisting}
\end{frame}
\end{document}



beamerin this question and its answer and comments. Could you elaborate? Thanks! – Denis Bitouzé Jan 31 '17 at 13:23\marktopleftand\markbottomrightas escaped code sequences inside your listing? – samcarter_is_at_topanswers.xyz Jan 31 '17 at 13:26tikzmarklibrary (and itslistingslibrary) and the\balloonmacro is that they don't need the listing content to be changed. Therefore they apply to a listing input thanks to\lstinputlisting. Currently, I don't see why\marktopleftand\markbottomrightfrom this question work nicely and not this\balloonmacro. – Denis Bitouzé Jan 31 '17 at 13:47