Latex:使用 Minted 包 - 如何让它包裹文本(linebreaks=true)

发布于 2024-08-18 00:00:16 字数 1007 浏览 8 评论 0原文

我使用 Pygments 来做很多事情,我也想在我的乳胶报告中使用它。我发现了与 Pygments 交互的包 Minted ,但是一些注释和一些代码溢出了右边距。我过去曾使用过 lstlistings 的 breaklines=true,但我没有找到使用 Minted 包获得该功能的方法,有什么想法吗?


\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}

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}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

多像笑话 2024-08-25 00:00:16

不幸的是,目前或在可预见的将来,minted 内没有解决方案,抱歉。实现断线功能相当困难。使用 listings 可能是您最好的解决方案。

Minted 现在有一个 breaklines 选项。

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.

帝王念 2024-08-25 00:00:16

如果您给 Minted 2.0(刚刚发布)提供 breaklines 选项,它就会进行换行:

\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}

还有各种相关选项来控制如何在输出中指示换行符的存在。请参阅 minted 文档中的第 6.3 节。

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.

楠木可依 2024-08-25 00:00:16

你应该看看texments,因为它是在 LaTeX 中使用 Pygments 荧光笔的。
http://www.ctan.org/tex-archive/macros /latex/contrib/texments/

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/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文