impossible to display code blocks with Beamer in Latex

101 views Asked by At

I have lines of code to display in a presentation with beamer, but as soon as I use the \begin{lstlisting} tags in the \begin{frames} tags, my document can't compile. But as soon as I put the lstlisting section aside, it displays correctly. inside the frame tags

outside the frame tags

complete code link

1

There are 1 answers

0
samcarter_is_at_topanswers.xyz On

The problem are the é in your listing. You can enable them like this:

\documentclass{beamer}
\usetheme{Warsaw}
\usecolortheme{beaver}
\usepackage[utf8]{inputenc}
\usepackage[french]{babel}
\usepackage{caption}
\usepackage{tikz}
\usepackage{listings}
\definecolor{codegreen}{rgb}{0,0.6,0}
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
\definecolor{codepurple}{rgb}{0.58,0,0.82}
\definecolor{backcolour}{rgb}{0.95,0.95,0.92}

\lstset{
    language=Python,
    basicstyle=\small\ttfamily,
    keywordstyle=\color{blue},
    stringstyle=\color{red},
    commentstyle=\color{green},
    morecomment=[l][\color{magenta}]{\#},
    numbers=left,
    numberstyle=\tiny\color{gray},
    stepnumber=1,
    numbersep=10pt,
    tabsize=4,
    showspaces=false,
    showstringspaces=false,
    literate={é}{{\'e}}1  
}

\begin{document}

\begin{frame}[fragile]

\begin{lstlisting}
    def euler(f, x0, y0, h, n):
        x = np.zeros(n)
        y = np.zeros(n)
        x[0], y[0] = x0, y0
        for i in range(1, n):
            y[i] = y[i-1] + h * f(x[i-1], y[i-1])
            x[i] = x[i-1] + h
        return x, y
\end{lstlisting}

\begin{lstlisting}
    from scipy.integrate import odeint
    y = odeint(équation, condition, durée)
\end{lstlisting}

\end{frame}

\end{document}

enter image description here