# Fortran syntax highlighting in listings

I've got some Fortran 90 source code I want to put into my thesis appendix. For this I'm using the listings package. Is it possible to have colored syntax highlighting for the Fortran code?

-
listings should recognise Fortran as one of the known languages: what did you try? –  Joseph Wright Nov 8 '11 at 10:51
I found a good solution: use the 'minted' package. This appears to be the best way to auto-color-highlight syntax in code listings. code.google.com/p/minted –  Eddy Nov 8 '11 at 11:58
Yeah but it doesn't colour the syntax at all –  Eddy Nov 8 '11 at 11:59
You can find minted in the list of my link several alternative packages for syntax highlighting. And there are at least two more packages using the Pygments library: verbments and texments. –  Schweinebacke Nov 8 '11 at 12:39

You have to set the language and the kind of highlighting, e.g.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{xcolor}
\usepackage{lmodern}
\usepackage{listings}
\lstset{language=[90]Fortran,
basicstyle=\ttfamily,
keywordstyle=\color{red},
morecomment=[l]{!\ }% Comment only with space after !
}
\begin{document}

\begin{lstlisting}
! Der folgende Fortran-Code ist bei Wikipedia geklaut.
SUBROUTINE test( Argument1, Argument2, Argument3 )
REAL,              INTENT(IN) :: Argument1
CHARACTER(LEN= *), INTENT(IN) :: Argument2
INTEGER,           INTENT(IN), OPTIONAL :: Argument3
! This makes sense
END SUBROUTINE
\end{lstlisting}
\end{document}


For more information about the used settings with \lstset see the manual of listings package.

BTW: There are several alternative packages for syntax highlighting. With fortran there seems to be even a package to print Fortran programs. But I've never used this, it cannot be used for syntax highlighting and was made to be used with plainTeX. So maybe if you want to try an alternative, e.g., highlight would be ab better suggestion.

-