Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
    
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
    
Since you have some responses below that seem to answer your question, please consider marking one of them as ‘Accepted’ by clicking on the tickmark below their vote count (see How do you accept an answer?). This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). It's part of this site's idea to identify good questions and answers through upvotes and acceptance of answers. –  Jubobs Mar 7 at 10:56
add comment

1 Answer

up vote 11 down vote accepted

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},
  commentstyle=\color{green},
  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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.