[Tex/LaTex] Change space style using listings package

listingsspacing

I'd like to make all space characters in the code gray. Is there an easy way to do this?
Is there something like spacestyle (I've commented it)?

\documentclass[a4paper, 10pt]{book}

\usepackage[UTF8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[T2A]{fontenc}
\usepackage[russian, ukrainian]{babel}

\usepackage{amsmath}
\usepackage{listings}

\usepackage[usenames, dvipsnames]{color}

\lstset{%
    language     = [77]Fortran,
    basicstyle   = \ttfamily,
    keywordstyle = \color{black},
    stringstyle  = \color{Gray},
    showspaces   = true,
%   spacestyle   = \color{Gray} 
    numbers      = left,
    numberstyle  = \ttfamily \color{black}
}

\begin{document}

\begin{lstlisting}
      PROGRAM HELLO
      WRITE(*, *) "Hello, World!"
      END PROGRAM
\end{lstlisting}

\end{document}

enter image description here
Also I want to change all spaces to gray bullets. Is it possible?

Best Answer

The listings package uses \lst@visiblespace for these spaces so you just need to define it:

enter image description here

Here's the latex code. I removed your font encoding as I didn't want to generate all of the required fonts.

\documentclass[a4paper, 10pt]{book}

\usepackage{amsmath}
\usepackage{listings}

\usepackage[usenames, dvipsnames]{color}

\makeatletter
\def\lst@visiblespace{$\color{Gray}\bullet$}
\makeatother

\lstset{%
    language     = [77]Fortran,
    basicstyle   = \ttfamily,
    keywordstyle = \color{black},
    stringstyle  = \color{Gray},
    showspaces   = true,
%   spacestyle   = \color{Gray}
    numbers      = left,
    numberstyle  = \ttfamily \color{black}
}

\begin{document}

\begin{lstlisting}
      PROGRAM HELLO
      WRITE(*, *) "Hello, World!"
      END PROGRAM
\end{lstlisting}

\end{document}
Related Question