% !Mode:: "TeX:DE:UTF-8:Main"
\DocumentMetadata{uncompress,tagging=on}
\documentclass{article}
\usepackage{amsmath}
\usepackage[ngerman]{babel}
\usepackage{listings}
\makeatletter
%\def\lst@outputspace{\pdffakespace\ } %not so good
% this here works fine with luatex, if the font has a space glyph:
% the pdf then has four space glyphs. But this doesn't mean that they get copied&pasted!
\def\lst@visiblespace{\lst@ttfamily{\char32}{\char32}}
% with pdftex this could work
%\def\lst@visiblespace{\lst@ttfamily{\pdffakespace\ }{\pdffakespace\ }}
\begin{document}\pagestyle{empty}
\tagpdfparaOff

\begin{lstlisting}[showspaces]
aaa aaa    xxxx
\end{lstlisting}

\end{document}  