长行列表中的换行符

长行列表中的换行符

这是列表中的换行符

我的 MWE 用很长的一行演示了这个问题:

\documentclass{report}
\usepackage{listings}
\lstdefinelanguage{text}{}
\lstnewenvironment{mylang}{\lstset{language=text,breaklines=true,breakatwhitespace=false,extendedchars=true,basicstyle=\footnotesize\ttfamily,}}{}
\begin{document}
\begin{mylang}
demo demo demo demo demo demo demo demo demo demo demo demo demo demo demo demo demo demo demo

demodemodemodemodemodemodemodemodemodemodemodemodemodemodemodemodemodemodemodemodemodemodemo 
\end{mylang}
\end{document}

答案1

listings仅在“其他”类型的字符后添加断点。您告诉它将例如添加o到列表中,但这会破坏关键字的解析:

\documentclass[a5paper]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{listings,xcolor}
\lstset{keywords=demo,keywordstyle=\color{red},breaklines}
\begin{document}
\begin{lstlisting}
    demo
    demodemodemodemodemodemodemodemodemodemodemodemodemodemodemodemodemodemodemodemodemodemodemo
\end{lstlisting}


\begin{lstlisting}[alsoother=o]
    demo
    demodemodemodemodemodemodemodemodemodemodemodemodemodemodemodemodemodemodemodemodemodemodemo
\end{lstlisting}

\end{document}

相关内容