add tag
topnush
I want to be able to highlight different lines of my pseudocode on different transitions.  However, I am not sure how to highlight an indented line. This code doesn't indent "do work" at all for some reason.


```
\documentclass{beamer}
\beamertemplatenavigationsymbolsempty
\setbeamersize{text margin left=10mm,text margin right=5mm} 
\setbeamertemplate{frametitle}[default][center]
\usepackage[many]{tcolorbox}
\usepackage{listings}
\lstdefinestyle{duckstyle}{%
    moredelim=[is][\color{red}]{|}{|},
    mathescape=true,
    escapechar=@,
    basicstyle=\ttfamily,
    columns=fullflexible
}
\lstset{style=duckstyle}
\def\HiLi{\leavevmode\rlap{\hbox to \hsize{\color{yellow!50}\leaders\hrule height .55\baselineskip depth .4ex\hfill}}}

\begin{document}
\begin{frame}[fragile]{}
\begin{tcolorbox}[colback=blue!5!white, text width=4.5cm,  left=7pt, right=10pt]
\begin{lstlisting}[basicstyle=\linespread{0.9}\ttfamily, mathescape]
line one
line two
line three
line four
	if $x=0$
@\only<1>{\HiLi}@	    do work
\end{lstlisting}
\end{tcolorbox}
\end{frame}

\end{document}`
```
Top Answer
samcarter
The problem that listings looks for the indention at the start of the line, so your tab would need to be there, but then your yellow rule gets shifted as well. 

Instead I would use the `lstlinebgrd` package to highlight specific lines in listings. 

Based on https://topanswers.xyz/tex?q=1365#a1614 this can  even be adapted to make it overlay aware:

```
\documentclass{beamer}
\beamertemplatenavigationsymbolsempty
\setbeamersize{text margin left=10mm,text margin right=5mm} 
\setbeamertemplate{frametitle}[default][center]
\usepackage[many]{tcolorbox}
\usepackage{listings}
\lstdefinestyle{duckstyle}{%
    moredelim=[is][\color{red}]{|}{|},
    mathescape=true,
    escapechar=@,
    basicstyle=\ttfamily,
    columns=fullflexible
}
\lstset{style=duckstyle}
\def\HiLi{\leavevmode\rlap{\hbox to \hsize{\color{yellow!50}\leaders\hrule height .55\baselineskip depth .4ex\hfill}}}


\usepackage{listings, pgffor}

\makeatletter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  %
  % \btIfInRange{number}{range list}{TRUE}{FALSE}
  %
  % Test if int number <number> is element of a (comma separated) list of ranges
  % (such as: {1,3-5,7,10-12,14}) and processes <TRUE> or <FALSE> respectively

\newcount\bt@rangea
\newcount\bt@rangeb

\newcommand\btIfInRange[2]{%
    \global\let\bt@inrange\@secondoftwo%
    \edef\bt@rangelist{#2}%
    \foreach \range in \bt@rangelist {%
        \afterassignment\bt@getrangeb%
        \bt@rangea=0\range\relax%
        \pgfmathtruncatemacro\result{ ( #1 >= \bt@rangea) && (#1 <= \bt@rangeb) }%
        \ifnum\result=1\relax%
            \breakforeach%
            \global\let\bt@inrange\@firstoftwo%
        \fi%
    }%
    \bt@inrange%
}%
\newcommand\bt@getrangeb{%
    \@ifnextchar\relax%
        {\bt@rangeb=\bt@rangea}%
        {\@getrangeb}%
}%
\def\@getrangeb-#1\relax{%
    \ifx\relax#1\relax%
        \bt@rangeb=100000%   \maxdimen is too large for pgfmath
    \else%
        \bt@rangeb=#1\relax%
    \fi%
}%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  %
  % \btLstHL<overlay spec>{range list}
  %
\newcommand<>{\btLstHL}[1]{%
    \only#2{\btIfInRange{\value{lstnumber}}{#1}{\color{yellow!30}}{\color{blue!5!white}}}%
}%


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  %
  % \btInputEmph<overlay spec>[listing options]{range list}{file name}
  %
\newcommand<>{\btLstInputEmph}[3][\empty]{%                                                    
    \only#4{%
        \lstset{linebackgroundcolor=\btLstHL{#2}}%
        \lstinputlisting{#3}%
    }% \only
}%
\makeatletter
    \let\old@lstKV@SwitchCases\lstKV@SwitchCases
    \def\lstKV@SwitchCases#1#2#3{}
\makeatother
\usepackage{lstlinebgrd}
\makeatletter
    \let\lstKV@SwitchCases\old@lstKV@SwitchCases
    \lst@Key{numbers}{none}{%
    \def\lst@PlaceNumber{\lst@linebgrd}%
    \lstKV@SwitchCases{#1}%
        {none:\\%
        left:\def\lst@PlaceNumber{\llap{\normalfont
            \lst@numberstyle{\thelstnumber}\kern\lst@numbersep} \lst@linebgrd}\\%
        right:\def\lst@PlaceNumber{\rlap{\normalfont
            \kern\linewidth \kern\lst@numbersep
            \lst@numberstyle{\thelstnumber}}\lst@linebgrd}%
    }{\PackageError{Listings}{Numbers #1 unknown}\@ehc}}
\makeatother



\begin{document}
\begin{frame}[fragile]{}
\begin{tcolorbox}[colback=blue!5!white, text width=4.5cm,  left=7pt, right=10pt]
\begin{lstlisting}[basicstyle=\linespread{0.9}\ttfamily, mathescape,
   linebackgroundcolor={%
       \color{blue!5!white}\btLstHL<2>{6}%
   },
]
line one
line two
line three
line four
	if $x=0$
	do work
\end{lstlisting}
\end{tcolorbox}
\end{frame}

\end{document}
```

![document2.gif](/image?hash=9f5c599dea20fc612a6f2c9198a6cc47149983896040107dcb6787890c4c994e)

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.