# Pythontex and the g-brief address field

I calculate some coordinates to include a cut out of a PDF (eStamps) via python. My code looks like this:

\documentclass[
ngerman,    % deutsch-neu
%russian,   % russisch
%english,   % english
11pt,       % Schriftgröße 11pt=Std
a4paper,    % DIN A4
oneside,    % Einseitig
utf8,       % Dateikodierung
]
{g-brief}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage{graphicx}
\usepackage{blindtext}  % dummytext
\usepackage{picins}
\usepackage[makestderr]{pythontex}

\begin{pycode}
import math

def gen_incl_cmd(zeilen, spalten, n, path):
xLftOff = 22.5
xRgtOff = 27.45
yTopOff = 14.1
yBtmOff = 19.0

xDINA4 = 210.0
yDINA4 = 297.0

xLftStamp = 2.75
xRgtStamp = 7.5
yTopStamp = 11
yBtmStamp = 21.5

xSpacing = (xDINA4 - xLftOff - xRgtOff) / spalten
ySpacing = (yDINA4 - yTopOff - yBtmOff) / zeilen

zeile  = math.floor( (n-1) / spalten )
spalte = (n-1) % spalten

if zeile > zeilen:
print('\\fbox{\\parbox[c]{1.7cm}{OUT OF\\\\STAMPS}}')
else:
top     = yTopOff + zeile  * ySpacing + yTopStamp
left    = xLftOff + spalte * xSpacing + xLftStamp

right   = xDINA4 - (left + xSpacing) + xRgtStamp
bottom  = yDINA4 - (top + ySpacing)  + yBtmStamp
print('\\includegraphics[trim={0}mm {1}mm {2}mm {3}mm, clip]{{{4}}}'.format(left, bottom, right, top, path))    # trim=left bottom right top
\end{pycode}

\newcommand{\ePostMarke}[4]{
\parpic[r]{
\pyc{gen_incl_cmd(#1, #2, #3, '#4')}
}
}

\Name           {name}
\Strasse        {street}
\Ort            {zip city}

\Unterschrift   {\vspace{-1.7cm}signiture}

\Postvermerk    {}      % Einschreiben, etc.
%\ePostMarke{8}{4}{5}{C:/Users/Lenny/Documents/LaTeX/Vorlagen/Briefe/TestPrint}
its street\\
zip and city\\
}
\Betreff        {subject}
\Datum          {\today}
\Gruss          {greets}{1cm}

\begin{document}
\begin{g-brief}
\blindtext

\ePostMarke{8}{4}{10}{C:/Users/Lenny/Documents/LaTeX/Vorlagen/Briefe/TestPrint}~\\
\ePostMarke{8}{4}{40}{C:/Users/Lenny/Documents/LaTeX/Vorlagen/Briefe/TestPrint}~\\

\pyc{gen_incl_cmd(8,4,10,'C:/Users/Lenny/Documents/LaTeX/Vorlagen/Briefe/TestPrint')}

\blindtext
\end{g-brief}
\end{document}


The code doesent work as long as the first line in \Adresse is not commented out. Even the eStamp includes in the text dont work.

But if \Adresse is free from \ePostMarke command every include works fine. Pythontex complains like this:

Prozess gestartet: "C:/Program Files/MiKTeX 2.9/miktex/bin/pythontex.bat" "D:\Downloads\tex\brief\BRIEF VORLAGE.tex"

This is PythonTeX 0.14

* PythonTeX warning
Unknown option ""

Traceback (most recent call last): File "C:\program files\miktex 2.9\scripts\pythontex\pythontex.py", line 62, in <module> pythontex.main() File "C:\program files\miktex 2.9\scripts\pythontex\pythontex2.py", line 2626, in main load_code_get_settings(data, temp_data) File "C:\program files\miktex 2.9\scripts\pythontex\pythontex2.py", line 475, in load_code_get_settings key, val = line.split('=', 1) ValueError: need more than 1 value to unpack

Prozess endete mit Fehler(n)


and my build chain is

"C:\Program Files\MiKTeX 2.9\miktex\bin\x64\pdflatex" ?ame" -parse-first-line -shell-escape -enable-write18 -synctex=1 -interaction=nonstopmode | "C:/Program Files/MiKTeX 2.9/miktex/bin/pythontex.bat" ?ame" | "C:\Program Files\MiKTeX 2.9\miktex\bin\x64\pdflatex" ?ame"  -parse-first-line -shell-escape -enable-write18 -synctex=1 -interaction=nonstopmode | txs:///view-pdf-internal --embedded


As you see I'm on Win7 x64, MiKTeX 2.9 (x64).

I am looking forward for you help.

This is due to the interaction between pythontex and g-brief. The g-brief environment is causing code to be written to the pythontex temp file after pythontex has already treated the document as complete. The error is due to pythontex trying to parse the code as options when it is actually code.
If you insert a \clearpage after the end of the g-brief environment, everything should work. I've opened an issue for this, so that the issue can be fixed in a future pythontex release.
• perfect \clearpage worked. thank you! – milkpirate Jul 7 '15 at 8:22