Sign up ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Environments are MiKTeX 2.9, XeLaTeX, PythonTeX 0.11 beta, and Python 3.3. I am pretty new to LaTeX and Python/PythonTeX and am struggling with the following piece of code.

%!TEX TS-program = xelatex
%!TEX encoding = UTF-8

\newcommand{\powww}[2]{\begin{pycode}print(#1**#2) \end{pycode}}

\pow{2}{5}      % success
\poww{2}{6}     % success
\powww{2}{7}    % fail

I get an error on \powww and can not understand why. Any help appreciated.

Extraneous input `print(2**7) \end {pycode}^^I% fail' between \begin{pycode}[
<key=value>] and line end
\FV@Error ...ncyVerb Error:^^J\space \space #1^^J}

l.28 \powww{2}{7}^^I% fail

The ultimate goal is to pass sets of 2 unicode strings as parameters from the XeLaTeX document via PythonTeX to Python, but I prefer to "start simple and then expand step by step".

share|improve this question

migrated from Apr 11 '13 at 7:15

This question came from our site for professional and enthusiast programmers.

1 Answer 1

PythonTeX environments, like the pycode environment, cannot be used inline. There must be a linebreak after the \begin{pycode}, and the \end{pycode} must be on a line by itself as well. Also, PythonTeX environments cannot be used inside LaTeX commands. This limitation is due to the way LaTeX deals with verbatim (literal) text in environments (it's related to TeX's catcodes).

If you want to create custom commands, \py and \pyc are the way to go. If you want to create a command that involves more complex code, then you should probably define a function in a pycode environment, and call that function within \py or \pyc.

If you have additional questions, you might ask them on

share|improve this answer
thanks. Before creating this question I also tried \powww...\pycode ... with code all on separate line,s which failed as well. But that is then due to not being able to use pycode within latex cmds. – user2263306 Apr 10 '13 at 12:45

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.