我想要显示一些类似 SAS Enterprise Guide 中的 SAS 代码:
以下是我目前所得到的,但只有“字符串”或多或少像我想要的。
请注意,我在工作中需要这个(最终,我找到了在工作中使用 LaTeX 的机会,耶!),因此我无法在我的计算机上安装任何东西,我只能使用 Overleaf、ShareLaTeX 或 Verbosus。
\documentclass[a4paper,12pt, twoside]{book}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[italian]{babel}
\usepackage[top=1.5in,bottom=1in,right=1in,left=1.3in,headheight=65pt,headsep=1cm]{geometry}
\usepackage{xcolor}
\usepackage{listings}
\lstset{language=SAS,
breaklines=true,
basicstyle=\ttfamily\bfseries,
columns=fixed,
keepspaces=true,
identifierstyle=\color{blue}\ttfamily,
keywordstyle=\color{cyan}\ttfamily,
stringstyle=\color{purple}\ttfamily,
commentstyle=\color{green}\ttfamily,
}
\begin{document}
\begin{lstlisting}
/* librerie */
libname mylib '/mydir/mysubdir';
/* ordinamento */
proc sort data=mylib.myfile out=myfilesorted nodupkey;
by mykey;
run;
* data myfile2; /* istruzione commentata */
data myfilejoinsanother;
merge myfilesorted (in=my)
anotherfile (in=theother rename=(myfield=mykey));
by mykey;
if my;
run;
\end{lstlisting}
\end{document}
答案1
部分解决方案:您可以使用minted
。它有一个词法分析器,您可以使用类似于或的sas
样式来满足您的需求。borland
vs
% arara: pdflatex: { shell: yes }
\documentclass[a4paper,12pt, twoside]{book}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[italian]{babel}
\usepackage[top=1.5in,bottom=1in,right=1in,left=1.3in,headheight=65pt,headsep=1cm]{geometry}
\usepackage{xcolor}
\usepackage{listings}
\usepackage{minted}
\usemintedstyle{borland}
\lstset{language=SAS,
breaklines=true,
basicstyle=\ttfamily\bfseries,
columns=fixed,
keepspaces=true,
identifierstyle=\color{blue}\ttfamily,
keywordstyle=\color{cyan}\ttfamily,
stringstyle=\color{purple}\ttfamily,
commentstyle=\color{green}\ttfamily,
}
\begin{document}
\begin{minted}{sas}
/* librerie */
libname mylib '/mydir/mysubdir';
/* ordinamento */
proc sort data=mylib.myfile out=myfilesorted nodupkey;
by mykey;
run;
* data myfile2; /* istruzione commentata */
data myfilejoinsanother;
merge myfilesorted (in=my)
anotherfile (in=theother rename=(myfield=mykey));
by mykey;
if my;
run;
\end{minted}
\end{document}