如何处理非常长的 lstinline 短语,例如长类名?

如何处理非常长的 lstinline 短语,例如长类名?

根据这个问题:

如何处理不包含空格的很长的行?

我的问题是,我的\lstinline-phrases 不包含任何特殊字符,如“-”。在我的 lstlinlines 中,有非常长的类名,如ThisIsAVeryLongExampleClassNameAndItHasNoLineBreak。这些类名导致的问题是框过满。

有谁知道如何设置条件换行符的方法。(就像\-在普通文本中一样)。

答案1

或者,让事情完全自动化(就你的情况而言):

\documentclass{minimal}
\usepackage{listings}
\begin{document}
\lstinline[
  literate={A}{A}{1\discretionary{}{}{}}
           {B}{B}{1\discretionary{}{}{}}
           {C}{C}{1\discretionary{}{}{}}
           {D}{D}{1\discretionary{}{}{}}
           {E}{E}{1\discretionary{}{}{}}
           {F}{F}{1\discretionary{}{}{}}
           {G}{G}{1\discretionary{}{}{}}
           {H}{H}{1\discretionary{}{}{}}
           {I}{I}{1\discretionary{}{}{}}
           {J}{J}{1\discretionary{}{}{}}
           {K}{K}{1\discretionary{}{}{}}
           {L}{L}{1\discretionary{}{}{}}
           {M}{M}{1\discretionary{}{}{}}
           {N}{N}{1\discretionary{}{}{}}
           {O}{O}{1\discretionary{}{}{}}
           {P}{P}{1\discretionary{}{}{}}
           {Q}{Q}{1\discretionary{}{}{}}
           {R}{R}{1\discretionary{}{}{}}
           {S}{S}{1\discretionary{}{}{}}
           {T}{T}{1\discretionary{}{}{}}
           {U}{U}{1\discretionary{}{}{}}
           {V}{V}{1\discretionary{}{}{}}
           {W}{W}{1\discretionary{}{}{}}
           {X}{X}{1\discretionary{}{}{}}
           {Y}{Y}{1\discretionary{}{}{}}
           {Z}{Z}{1\discretionary{}{}{}}
!ThisIsAVeryLongExampleClassNameAndItHasNoLineBreakThisIsAVeryLongExampleClassNameAndItHasNoLineBreakThisIsAVeryLongExampleClassNameAndItHasNoLineBreakThisIsAVeryLongExampleClassNameAndItHasNoLineBreakThisIsAVeryLongExampleClassNameAndItHasNoLineBreak!

\结束{文档}

显然,这应该以一种风格来表达……

(要到达-行尾,请使用\discretionary{-}{}{}. 26 次 :-)

答案2

您所引用的问题中的巧妙技巧可用于定义条件换行符:

\documentclass{minimal}
\usepackage{listings}
\begin{document}
Bla bla blabla blabla bla bla blabla bla blabla bla blabla
bla blabla bla blablablabla bla
\lstinline[literate={\\\-}{}{0\discretionary{-}{}{}}]!ThisIsAVeryLong\-Example\-ClassNameAndItHasNoLineBreak!
bla blabla blabla blabla bla
\end{document}

PS 我猜问题中\\的第二个参数是错误的?无论如何,上面的方法对我有用。\discretionary

答案3

今晚我按照以下两个步骤很幸运:

  1. 明确打破名称:\lstinline{ThisIsAVeryLongExampleClassName}\lstinline{AndItHasNoLineBreak}
  2. 确保您前面的内容lstsetbreaklines=true(或者只是breaklines实际上)。

相关内容