Here is an advanced example using lstlistings, more or less copied verbatim from a production version.
\lstdefinestyle{steden}{basicstyle=\ttfamily,
keywordstyle=\color{blue}\bfseries\ttfamily,
stringstyle=\color{yac}\ttfamily,
showstringspaces=false,
commentstyle=\color{darkgray}\sl\ttfamily,
emph={process,new,parfill,multifill,release,fetch,releaseAll,fetchAll,spawn,processDC,\#},
emphstyle={\color{blue}\bfseries},
emph={[2]ChanName,Process,RD,Trans,NFData,reduce,fold,parMapDC,reduceDC,parMapAt,map_par,map_farm,map_wp,parMap,farm,ssf,workpool,par,pseq},
emphstyle={[2]\color{blue}\bfseries},
emphstyle={[3]\color{red}\bfseries},
emph={[3]r0,rwhnf,rnf,rdeepseq,unsafePerformIO,IO,merge},
captionpos=b,
lineskip=-0.1ex,
frame=lines,
language=Haskell,
literate={+}{{$+$}}1 {/}{{$/$}}1 {*}{{$*$}}1 {=}{{$=$}}1
{`+`}{{+}}1 {`-`}{{-}}1 {`*`}{{*}}1
{>}{{$>$}}1 {<}{{$<$}}1 {\\}{{$\lambda$}}1 {\\n}{{\textbackslash
n}}2 {\\\\}{{\char`\\\char`\\}}1
{->}{{$\rightarrow$}}2 {>=}{{$\geq$}}2
{<-}{{$\in$}}2 % the list comprehension <-
{<--}{{$\leftarrow$}}2 % the monadic <-
{<=}{{$\leq$}}2 {=>}{{$\Rightarrow$}}2
{\ .\ }{{ $\circ$ }}3
{(.)}{{($\circ$)}}3
{>>}{{>>}}2 {>>=}{{>>=}}2 {/=}{{$\neq$}}2
{|}{{$\mid$}}1
%%% vector operations
{v+}{{$\overrightarrow{+}$}}1 {v-}{{$\overrightarrow{-}$}}1
{v*}{{$\overrightarrow{\cdot}$}}1
%%% number fields
{NN}{{$\N$}}1 {ZZ}{{$\Z$}}1 {QQ}{{$\Q$}}1
{xdd}{{$\delta$}}1
{xaa}{{$\alpha$}}1
%%% further hacks
{`l_p`}{{l\textsubscript{p}}}2
{`=`}{{$=$}}1
{p^k}{{p\textsuperscript{k}}}2
{`p^k`}{{p\textsuperscript{k}}}2
{`^2`}{{\textsuperscript{2}}}1
{`xsinn`}{{$\zeta_n^n$}}2
{bottom}{{$\bot$}}1
%% do not highlight "reduce" in a special case
{xreduce}{{reduce}}6
}
Further environments for simpler usage:
\lstnewenvironment{code*}
{%
\lstset{style=steden,
}} {}
\newcommand{\cd}[1]{\lstinline[style=steden,keepspaces=true,
breaklines=true,basicstyle=\ttfamily];#1;}
\newcommand{\inputcode}[1]{\lstinputlisting[style=steden,xleftmargin=0pt,
xrightmargin=0pt]{#1}}
\lstnewenvironment{code}
{%
\lstset{style=steden,
frame=none,
xleftmargin=30pt,
xrightmargin=10pt,
}} {}
〉character? Note also a related ticket: https://tex.stackexchange.com/questions/307062/warning-uncodable-character-in-lyx-lstlisting – scottkosty Nov 24 '18 at 17:11