I am trying to define a listing style in order to have fortran source codes which look like vim style colors.
For example, I would like to give a specific color to end program or end module or double precision ect ...
It is easy for keywords without blank character but I do not know how to do for keyword such as those above.
As you can see in the example below, the color of program is the good one but the color of end program is not the good one.
\documentclass{article}
\usepackage{xcolor}
\definecolor{keycolor}{RGB}{172, 42, 42}
\definecolor{vimvert}{RGB}{46, 139, 87}
\usepackage{listings}
% global parameters
\lstdefinestyle{global}{
basicstyle=\ttfamily\scriptsize\color{black!90},%
stringstyle=\itshape\color{magenta},%
showstringspaces=false,%
keywordstyle=\bfseries\color{keycolor},%
commentstyle=\color{gray}\slshape,%
}
% fortran style
\lstdefinestyle{fortranstyle}{
language=Fortran,%
style=global,%
emph=[1]{implicit none, integer, real, double precision, character, len, parameter, structure, common},%
emphstyle=[1]\bfseries\color{vimvert},%
emph=[2]{program,end program, module, end module, subroutine, end subroutine, function, end function},%
emphstyle=[2]\color{violet}\bfseries\slshape,%
emph=[3]{call, true, false},%
emphstyle=[3]\color{teal}\slshape%
}
\begin{document}
\begin{lstlisting}[style=fortranstyle]
program calcPi
implicit none
integer :: i, nbreDansCercle
integer, parameter :: npts = 1000000000
double precision :: x, y, r, pi
nbreDansCercle = 0
do i = 1, npts, 1
call random_number(x)
call random_number(y)
x = 2.d0 * x - 1.d0
y = 2.d0 * y - 1.d0
r = x**2 + y**2
if (r < 1.d0) then
nbreDansCercle = nbreDansCercle + 1
end if
end do
pi = 4.d0 * dble(nbreDansCercle) / dble(npts)
write(*,"('pi = ', F20.17)") pi
end program calcPi
\end{lstlisting}
\end{document}


moredelim=[s][emphstyle]{implicit}{none}does not work. If I did that, all the text afterimplicit noneis green. – Ger Sep 20 '12 at 08:27