# Tag Archives: lstinputlisting

## LaTeX syntax highlighting examples

Syntax highlighting in LaTeX using the listings package is very powerful. Below, I will provide a few examples for your convenience.

First, let me briefly summarize the usage of the listings package.

\usepackage{listings}
\usepackage{color}
\definecolor{name}{rgb}{0.5,0.5,0.5}
...
\lstset{key1=value1,
key2=value2}
...
\begin{lstlisting}
Code
\end{lstlisting}
...
\lstinputlisting{filename.java}


So below you’ll find a few complete code examples to reuse and modify for your purposes:

“The Pseudo Code Box”

\definecolor{lightpurple}{rgb}{0.8,0.8,1}

\lstset{
numbers=left,
stepnumber=1,
numbersep=5pt,
numberstyle=\small\color{black},
basicstyle=\ttfamily,
keywordstyle=\color{black},
stringstyle=\color{black},
frame=single,
tabsize=2,
backgroundcolor=\color{lightpurple},
caption=Fibonacci numbers pseudo code}


I copied the code from here

“OOP: Java”

\definecolor{javared}{rgb}{0.6,0,0} % for strings
\definecolor{javapurple}{rgb}{0.5,0,0.35} % keywords

\lstset{language=Java,
basicstyle=\ttfamily,
keywordstyle=\color{javapurple}\bfseries,
stringstyle=\color{javared},
numbers=left,
numberstyle=\tiny\color{black},
stepnumber=2,
numbersep=10pt,
tabsize=4,
showspaces=false,
showstringspaces=false}


“The Trickiest: LaTeX”

\definecolor{lightgrey}{rgb}{0.9,0.9,0.9}
\definecolor{darkgreen}{rgb}{0,0.6,0}

\lstset{language=[LaTeX]TeX,
texcsstyle=*\bf\color{blue},
numbers=none,
breaklines=true,
keywordstyle=\color{darkgreen},
otherkeywords={\$, \{, \}, $,$},