0

Using PythonTex 0.18 i cannot change the header or footer. I followed the solution in using-pythontex-py-with-fancyhdr but it still doesnt work.

MWE:

\documentclass[11pt]{article}
\usepackage{fancyhdr}

\pagestyle{fancy}
\fancyhf{}

\usepackage{pythontex}

\begin{document}

\rfoot{Right}

\begin{pycode}
print("\\lfoot{Left}")

\end{pycode}

\end{document}
1
  • Welcome to TeX.SE!
    – Mensch
    Nov 9, 2021 at 14:31

1 Answer 1

0

The problem seems to be that the LaTeX code generated by Python is inside a TeX group. Fancyhdr now does local changes by default, so these will not take effect. However you can make them global with the following trick (\globaldefs=1). The extra pair of braces in the code is to prevent the \globaldefs to affect other pycode.

\documentclass[11pt]{article}
\usepackage{fancyhdr}

\pagestyle{fancy}
\fancyhf{}

\usepackage{pythontex}

\begin{document}
Some text.
\rfoot{Right}

\begin{pycode}
print("{\\globaldefs=1\\lfoot{Left}}")

\end{pycode}

\end{document}
1
  • Wow, thanks! It works! :-)
    – dangu
    Nov 10, 2021 at 8:28

You must log in to answer this question.

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