2

I have a problem with PythonTeX and Beamer : I don't understand why the code below doesn't work: \stdoutpythontex is supposed to print the last output of the last block of python instructions, but it doesn't here.

Moreover, when you call \stderrpythontex, the line number is false, even with the option fragile=singleslide.

Could you please help me with this?

\documentclass{beamer}


\usepackage[french]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[framemethod=TikZ]{mdframed}
\usepackage[makestderr]{pythontex}
\usepackage{multicol}

\begin{document}

\begin{frame}[fragile]
\frametitle{Affichage à l'écran: Commande \pyv{print()} }  
\begin{itemize}
\item En mode console:   résultats automatiquement affichés.
\item Dans l'éditeur: utiliser \pyv{print()}
\end{itemize}
%

\begin{pyblock}[][numbers=left]
a, b =  2, 3
print(a, 'hello', a+b)
\end{pyblock}
%
a pour résultat
\stdoutpythontex

De plus, 
\begin{pyblock}[][numbers=left]
a = 5
print('a vaut ' a)
\end{pyblock}
donne
\stderrpythontex
\end{frame}


\end{document}
2
  • A tip: You can use backticks ` to mark your inline code as I did in my edit.
    – jub0bs
    Commented Aug 7, 2014 at 8:18
  • ok, sorry I'll do it from now
    – guillaume
    Commented Aug 7, 2014 at 8:27

1 Answer 1

4

In your current configuration, everything is executed in a single Python session. The second chunk of code triggers a syntax error, which is caught before any code is executed. The syntax error prevents any code from running, so the first chunk never gets to print.

The line numbering shown in the error (4) is correct, because the syntax error was in the 4th line of your code (again, everything is in a single session). This didn't line up with the line numbering shown in the slide, though, because you weren't using firstnumber=last.

If you want both examples to work, independently, then you should put them in separate sessions. Maybe use \begin{pyblock}[stdout][numbers=left] for the first one, and \begin{pyblock}[stderr][numbers=left] for the second one.

2
  • OK, thanks for these explanations (though I spent many hours on your exhaustive documentation, I realize I didn't understand the idea of many sessions, which is actually great!) By the way, thanks again for you PythonTex package!
    – guillaume
    Commented Aug 7, 2014 at 14:56
  • @guillaume Accepting and upvoting answers is the preferred way here to say “thank you” to users who helped you.
    – jub0bs
    Commented Aug 7, 2014 at 21:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .