Latex: Using Minted package - how do I make it wrap the text (linebreaks=true)

27,302

Solution 1

Unfortunately, there’s no solution within minted at the moment or for the foreseeable future, sorry. Implementing the breaklines feature is quite difficult. Using listings instead may be your best solution here.

Minted now has a breaklines option.

Solution 2

Minted 2.0 (just released) does line breaking if you give it the breaklines option:

\documentclass[10pt]{article}  
\usepackage{fancyvrb}  
\usepackage{minted}  

\begin{document}
\begin{minted}[%
 breaklines,
 mathescape,
 linenos,
 numbersep=5pt,
 frame=single,
 numbersep=5pt,
 xleftmargin=0pt,
 ]{python}
class Run(BaseModel):
 "''
 Run: unique Tool and multiple Inputs
 Status:
  Running => jobs are pending or runing and not all jobs have been completed
  Paused => workers querying for 'Running' Runs won't get this Run until we change status again
  Done => all jobs have completed and have a result_status = 'Done'
  Incomplete => No results (inputs) have been associated with the Run
 "'' 
 name = models.CharField(max_length = 150,
  unique=True)
 tool = models.ForeignKey('Tool')
 tags = models.ManyToManyField(RunTag, related_name=''model_set'')
\end{minted}
\end{document}

There are also various related options to control how the presence of a line break is indicated in the output. See section 6.3 in the minted documentation.

Solution 3

You should have a look at texments as it is for using the Pygments highlighter in LaTeX. http://www.ctan.org/tex-archive/macros/latex/contrib/texments/

Share:
27,302
Paddie
Author by

Paddie

Updated on July 28, 2020

Comments

  • Paddie
    Paddie almost 4 years

    Im using the Pygments for a lot of things, and I'd like to also use this in my latex report. I found the package Minted which interacts with Pygments, but some of the comments and some of the code overflows the right margin. I have used lstlistings' breaklines=true in the past, but I don't see a way to get that functionality using the Minted package, any ideas?

    
    \documentclass[10pt]{article}  
    \usepackage{fancyvrb}  
    \usepackage{minted}  
    
    \begin{document}
    \begin{minted}[mathescape,
     linenos,
     numbersep=5pt,
     frame=single,
     numbersep=5pt,
     xleftmargin=0,
     ]{python}
    class Run(BaseModel):
     """
     Run: unique Tool and multiple Inputs
     Status:
      Running => jobs are pending or runing and not all jobs have been completed
      Paused => workers querying for 'Running' Runs won't get this Run until we change status again
      Done => all jobs have completed and have a result_status = 'Done'
      Incomplete => No results (inputs) have been associated with the Run
     """ 
     name = models.CharField(max_length = 150,
      unique=True)
     tool = models.ForeignKey('Tool')
     tags = models.ManyToManyField(RunTag, related_name="model_set")
    \end{minted}
    \end{document}
    
  • Paddie
    Paddie over 14 years
    I've taken a look at it, but it didn't solve my problem, simply did the same. I may just have to do this all by hand then..
  • Paddie
    Paddie over 14 years
    Thank you for the clear answer Konrad. In spite of this, I was so satisfied with the results minted produced, that I wasn't too bothered by having to double-check the output.
  • eckes
    eckes over 13 years
    do you currently have any activities in implementing a breaklines feature in minted?
  • Manuel Rauber
    Manuel Rauber almost 11 years
    I just want to repeat @eckes question
  • Konrad Rudolph
    Konrad Rudolph almost 11 years
    @Raubi I’m no longer the maintainer of minted since I lacked both the time and the LaTeX skills for it. It’s currently being developed by Geoffrey Poore. He does intent to implement this feature, but I don’t know a timeline. There is a solution, however, but it requires some fiddling.
  • Admin
    Admin about 9 years
    breaklines is implemented now.
  • Tyler Crompton
    Tyler Crompton over 8 years
    It doesn't appear to work in conjunction with the obeytabs option.
  • David 天宇 Wong
    David 天宇 Wong over 8 years
    breaklines is great, but it doesn't break words