我试图在连字符处停止换行,例如对于\lstinline{sudo yum install -y epel-release && sudo yum install -y scipy python-matplotlib git autoconf automake screen gcc-c++ rubber texlive-appendix}
,我既不想也不想epel-release
被python-matlib
连字符连接。
我进行了以下尝试(感谢https://tex.stackexchange.com/a/200498和https://tex.stackexchange.com/a/119371):
\lstset{
basicstyle=\ttfamily\lst@ifdisplaystyle\scriptsize\fi,
columns=flexible,
breaklines=true,
literate=-{\nobreak-\nobreak}3, % <--- 10K penalty to break around - (e.g. python-matplotlib)
}
这似乎按预期工作,直到出现带有双连字符选项的命令,例如 yum --disablerepo=*
。这会在连字符周围随机插入一堆空格,看起来很糟糕。我添加了,\raggedright
因为basicstyle
我认为它们可能是正当理由,但这没有帮助。用 包裹整个段落flushleft
也没有用。
一个例子:
\documentclass{article}
\usepackage{listings}
\lstset{ % Set default for listings
basicstyle=\ttfamily\lst@ifdisplaystyle\scriptsize\fi,
columns=flexible,
breaklines=true,
literate=-{\nobreak-\nobreak}3, % <--- 10K penalty to break around - (e.g. python-matplotlib) https://tex.stackexchange.com/a/200498 https://tex.stackexchange.com/a/119371
}
\begin{document}
Additional software installation: \lstinline`sudo yum install -y epel-release && sudo yum install -y scipy python-matplotlib git autoconf automake screen gcc-c++ rubber texlive-appendix`\\
Then build:\\
\lstinline`control build --build-opt1 --build-opt1-option optionA --build-opt1-option optionB --build-opt2 --build-opt2-option optionX --build-opt2-option optionY`
\end{document}