Premise: I have to use ShareLaTeX (or Overleaf) because I can't install anything on the computer I'm working with.
I'm writing a document with a lot of SAS code snippets, I'm using minted and I'm quite content of the result, but I would like to add some more keywords to the pre-defined ones.
I saw this post: How to add custom C++ keywords to be recognized by Minted? but the solution is too difficult for me, and I don't even know if I could do such a thing in ShareLaTeX.
I tried with a workaround, but it's not convenient, because I have to correct the code and not simply cut and paste it from the SAS editor.
So, I decided to try with listings. I'm almost there but I don't manage to have my style \color{green}\ttfamily for comments.
\documentclass[a4paper,12pt, twoside]{book}
\usepackage{microtype}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[utf8]{inputenc}
\usepackage[a4paper]{geometry}
\geometry{verbose,tmargin=3cm,bmargin=3.5cm,lmargin=4cm,rmargin=3cm,marginparwidth=70pt}
\usepackage{mwe}
\usepackage{minted}
\usemintedstyle{vs}
\newcommand{\saskeyword}[1]{\textcolor{blue}{#1}}
\newenvironment{sasminted}{\VerbatimEnvironment\begin{minted}[escapeinside=||,fontsize=\small,baselinestretch=1, samepage=true]{sas}}
{\end{minted}}
\usepackage{listings}
\lstset{%
basicstyle=\small\ttfamily\bfseries,
columns=flexible,
language=SAS,
keywordstyle=\color{blue}\bfseries,
morecomment=[s]{/*}{*/},
morecomment=[s]{*}{;},
morecomment=[n]{/*}{*/},
morecomment=[n]{*}{;},
escapechar=|,
commentstyle=\color{green}\ttfamily,
stringstyle=\color[rgb]{0.639,0.082,0.082}\ttfamily,
showstringspaces=false,
keepspaces=true,
sensitive=false,
otherkeywords={*,/},
}
\newenvironment{saslst}{\VerbatimEnvironment\noindent\begin{minipage}{\linewidth}\begin{lstlisting}}
{\end{lstlisting}\end{minipage}}
\begin{document}
\noindent Pure \texttt{minted}:
\begin{sasminted}
/* comment */
data pippo; |\emph{within escape chars}|
set pluto (firstobs=10 obs=14);
keep paperino;
minnie='a string';
* another comment;
run;
\end{sasminted}
This is what I would like to have (without my workaround):
\begin{sasminted}
/* comment */
data pippo; |\emph{within escape chars}|
set pluto (|\saskeyword{firstobs}|=10 |\saskeyword{obs}|=14);
keep paperino;
minnie='a string';
* another comment;
run;
\end{sasminted}
\noindent with \texttt{listing}:
\begin{lstlisting}
/* comment */
data pippo; |\emph{within escape chars}|
set pluto (firstobs=10 obs=14);
keep paperino;
minnie='a string';
* another comment;
run;
\end{lstlisting}
\noindent\texttt{minted} also recognizes when the \texttt{*} has to be put in black or in green:
\begin{sasminted}
/* this with minted */
proc freq data = pippo;
tables pluto * paperino;
run;
* another comment;
\end{sasminted}
\noindent I prefer minted highlighting also here:
\begin{lstlisting}
/* this with listings */
proc freq data = pippo;
tables pluto * paperino;
run;
* another comment;
\end{lstlisting}
\end{document}


/and*as keywords (seelstlang3.sty), the short rules often comes first. So we probably have to get more sneaky. It is a bit sad that those the who made the SAS setup, did not include the comment stuff for SAS – daleif Aug 30 '17 at 14:15\lstdefinelanguageand remove*and/from the list of keywords, your comments come out green. – Alan Munn Aug 30 '17 at 14:20//and not*in c++ – koleygr Aug 30 '17 at 14:31minted. – CarLaTeX Aug 30 '17 at 14:32otherkeywordsis the solution in https://tex.stackexchange.com/a/186095/3929, akaotherkeywords={!,!=,~,$,\&,_,<,>=,=<,>},% removed *,/– daleif Aug 30 '17 at 14:39*also used as the multiplication operator, or is is just like%in latex? Because, if it is the latter, then*probably should not be inotherkeywords– daleif Aug 30 '17 at 14:41/* ... */or from the*to the first;. The first is usually used to comment a piece of code (one or more steps), the second one to comment a single instruction (statement), since all the SAS instructions end with;. – CarLaTeX Aug 30 '17 at 14:45*is used also as operator, not only for multiplication, example:proc freq data = pippo; tables pluto * paperino; run;– CarLaTeX Aug 30 '17 at 14:54* paperino;is not an error? Probably symantics. I don't think listings can tell the difference (not sure if minted can either) – daleif Aug 30 '17 at 14:56minteddoes it, see my MWE... and when the*is aftertablesis black (inminted). – CarLaTeX Aug 30 '17 at 15:02