0

I would like to include some python code in my document, and here is what I have written so far:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage[spanish]{babel}
\usepackage{listings}
\usepackage{xcolor}

\definecolor{codegreen}{rgb}{0.04314,0.6745,0.07843}
\definecolor{codegray}{rgb}{0.7059,0.6863,0.702}
\definecolor{codered}{rgb}{0.5373,0.02745,0.06275}
\definecolor{codeblue}{rgb}{0.071,0.0258,0.9882}
\definecolor{codepurple}{rgb}{0.6,0.02745,0.5961}
\definecolor{backcolour}{rgb}{0.95,0.95,0.92}

\lstdefinestyle{mystyle}{
    commentstyle=\color{codegray},
    keywordstyle=\color{codepurple},
    otherkeywords={range, print, max, len},
    classoffset=1, % starting new class
    keywordstyle=\color{codeblue},
    numberstyle=\color{codered},
    stringstyle=\color{codegreen},
    basicstyle=\ttfamily,
    showspaces=false,                
    showstringspaces=false,
}

\lstset{style=mystyle}

\begin{document}
\begin{lstlisting}[language=Python]
        sd.play(audio.astype('int16'))

        paso = 5
        for i in range(0,ntramas,paso):
    \end{lstlisting}
\end{document}

I would want the code to appear like this:

enter image description here

However, this is what I get in latex:

enter image description here

The difference is in the colour of numbers, which appear in black despite I have indicated with the numberstyle sentence I want them in red.

Thank you for your answers.

3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.