I use beamer to create presentations with code listings. Sometimes I need to highlight some piece of text, for example one variable (
counter
in the code below). Now I do it using lstlisting
and escapechar
. Is it any way to execute external code, for example Java, Python, etc. I would modify (change counter
to |\red{counter}|
) source code externally and import modified source file. Code: Select all
Code, edit and compile here:
\documentclass{beamer}\usepackage{ucs}\usepackage[utf8x]{inputenc}\usepackage{listings}\lstset{language=Java,tabsize=4,breaklines=true,breakatwhitespace=true,escapechar=|,basicstyle=\footnotesize\ttfamily,numberstyle=\footnotesize\ttfamily,aboveskip=\baselineskip,captionpos=b,columns=fullflexible,showstringspaces=false,extendedchars=true,breaklines=true,showtabs=false,showspaces=false,showstringspaces=false,identifierstyle=\ttfamily,keywordstyle=\color[rgb]{0.498,0.0,0.333},stringstyle=\color[rgb]{0.165,0.0,0.999},commentstyle=\color[rgb]{0.247,0.498,0.372}}\newcommand\red[1]{\setlength\fboxsep{0pt}\colorbox{red}{\strut #1}}\begin{document}\begin{frame}[fragile]{Test}\begin{lstlisting}public class Main {int counter;public static void main(String[] args) {for (counter = 0; counter < 10; counter++)System.out.println('HelloWorld');}}