I try make a document with use PythonTeX like this :

\documentclass[a4paper, 12pt]{article}

But i get .pdf like this : no breaklines How to make a breaklines the result from PythonTeX like this :



Update 2019-10-17: PythonTeX has had automatic line breaking just like minted for a while now. In both cases the line breaking is implemented in fvextra, which extends fancyvrb. Wrapping a long number can now be accomplished using something like \fvset{breaklines, breakafter=0123456789} (general fancyvrb/fvextra setting), \setpythontexfv{breaklines, breakafter=0123456789} (restrict to PythonTeX), or \begin{pyconsole}[][breaklines, breakafter=0123456789] (restrict to current environment).

PythonTeX currently doesn't support automatic line breaking. I've recently been adding automatic line breaking at spaces to the development version of minted, and will be adding that to PythonTeX soon. But that won't do what you want, because you want to wrap something that doesn't contain spaces.

For now, one solution is to modify pythontex2.py (or pythontex3.py, depending on which Python version you are using). Replace line 2523 in the most recent version with

processed = highlight('\n'.join([textwrap.fill(x) for x in console_content.splitlines(True)]), lexer, formatter)

I will look into adding this sort of wrapping as a built-in feature in the future.

  • ok , breaklines is success,
    – Hirwanto
    Nov 21 '14 at 3:24
  • Hello Mr. Poore, is the mentioned linebreaking feature already implemented? My situation is simillar as OP; I am lloking for linebreaks within pyblock environment. Oct 17 '19 at 6:53
  • 1
    @TomášKruliš Yes, PythonTeX has line breaking now. I've updated the answer.
    – G. Poore
    Oct 17 '19 at 12:22
  • @G.Poore Thank you very much Mr. Poore. Please, allow me now to thank you for your wonderfull work to allow running python in LaTeX. For me, it helps so much and had opened an entire new world of possibilities. Thank you Oct 17 '19 at 13:52
  • 1
    @grwlf breaklines only allows breaks after spaces by default. breakafter allows breaks after whatever additional characters are specified. It's useful when there are few or no spaces, so the default behavior doesn't produce good results.
    – G. Poore
    Jan 10 at 3:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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