i have to include a do-file from stata into my Bachelor Thesis and i wanted to do that with the listing option. Because there is no possibility for do files, i defined a new language by myself.
Everything works now except one thing: i want to color one word after using $ in blue, like this:
I tried several possibilities but all i get is either everything is black and nothing is blue or everything between two of this $ is blue, like this:
I don't know how i can solve this Problem and i would be very thankful if you could help me!



Thank you in advance!
Here is one of the codes i tried:
Code: Select all
\NeedsTeXFormat{LaTeX2e}
\documentclass[a4paper,12pt,twoside,openright,DIV=15,BCOR25mm]{scrbook}
\KOMAoptions{DIV=last}
\usepackage{listings}
\usepackage{xcolor}
\usepackage{fontspec}
\definecolor{darkgreen}{rgb}{0,0.55,0}
\definecolor{darkblue}{rgb}{0,0,0.55}
\definecolor{blue}{rgb}{0,0,1}
\definecolor{lightblue}{rgb}{0,0.5,0.5}
\definecolor{marron}{rgb}{0.58,0.08,0}
\lstdefinelanguage{Stata}{
morekeywords={generate, label, keep, if,
},
morekeywords=[2]{group,
},
morecomment=[l]{//},
morestring=[b]",
morecomment=[n][keywordstyle9]{`}{'},
morestring=[b][\color{lightblue}]\$,
sensitive=true,
}
\lstdefinestyle{numbers}{
numbers=left,
stepnumber=1,
numberstyle=\tiny,
xleftmargin=2em
}
\lstdefinestyle{nonumbers}{
numbers=none
}
\lstdefinestyle{stata-plain}{
language=Stata,
basicstyle=\setmonofont{Consolas}\scriptsize\ttfamily,
}
\lstdefinestyle{stata-editor}{
language=Stata,
basicstyle=\setmonofont{Consolas}\scriptsize\ttfamily,
keywordstyle={\color{darkblue}},
keywordstyle=[2]{\color{blue}},
keywordstyle=[9]{\color{lightblue}},
stringstyle=\color{marron},
commentstyle=\color{darkgreen},
}
\lstset{language=Stata, style=stata-plain, style=numbers, style=stata-editor, showstringspaces=false, breaklines, frame=single,
}
\begin{document}
\begin{lstlisting}
//Comment
"String list"
`macro variable'
generate label keep if
group(...)
$exp_main something between $exp_traffic $exp_XRF
\end{lstlisting}
\end{document}