Edit
I found something, but not working as I would like under TikZ. Here is the code :
\documentclass[a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{pythontex}
\usepackage{tikz}
\begin{document}
\begin{pycode}
from math import *
def calculus(xa,ya,xb,yb):
d=round(sqrt((xb-xa)2+(yb-ya)2),3)
xk=(xa+xb)/2
yk=(ya+yb)/2
return d,xk,yk
\end{pycode}
With \textbackslash{}py{calculus(0,0,1,1)} the result is \py{calculus(0,0,1,1)}
With \textbackslash{}py{calculus(0,0,1,1)[0]} the result is \py{calculus(0,0,1,1)[0]}
With \textbackslash{}py{calculus(0,0,1,1)[1]} the result is \py{calculus(0,0,1,1)[1]}
With \textbackslash{}py{calculus(0,0,1,1)[2]} the result is \py{calculus(0,0,1,1)[2]}
\begin{center}
\def\xa{0}
\def\ya{0}
\def\xb{1}
\def\yb{1}
\begin{tikzpicture}[x=1.0cm,y=1.0cm, scale=1, every node/.style={scale=1}]
\draw (\xa,\ya) node [circle,inner sep=1pt,fill] {} node [left] {$A$} -- (\xb,\yb) node [circle,inner sep=1pt,fill] {} node [right] {$B$};
\draw ({(\xa+\xb)/2},{(\ya+\yb)/2}) node [circle,inner sep=1pt,fill] {} node [below right] {$K$};
\end{tikzpicture}
\end{center}
\end{document}
Inside the tikz block, I would like to replace :
\draw ({(\xa+\xb)/2},{(\ya+\yb)/2}) node [circle,inner sep=1pt,fill] {} node [below right] {$K$};
with something like :
\draw ({\py{calculus(\xa,\ya,\xb,\yb)[1]}},{\py{calculus(\xa,\ya,\xb,\xb)[2]}}) node [circle,inner sep=1pt,fill] {} node [above] {$K$};
Original post
I would like to retrieve multiple variables separatly after using pythontex. I know how to retrieve a single variable, and multiples variables at the same time, but not separatly. Here is an example :
\documentclass[a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{pythontex}
\begin{document}
\begin{pycode}
def sum1(x,y):
z=x+y
return z
\end{pycode}
With sum1 the result is \py{sum1(2,3)}
\begin{pycode}
def sum2(x,y):
z=x+y
return x,y,z
\end{pycode}
With sum2 the result is \py{sum2(2,3)}
\end{document}
and the output is :
What I want to do is to use x, y and z variables returned by python code, to write for example :
The result of 2 + 3 = 5.
And I want to know if it's possible to do that outside the python code.
Thanks


pusybenvironment can be useful, for example: https://tex.stackexchange.com/a/65294/10742 – G. Poore Feb 06 '18 at 12:58