我使用此命令输入 less: \begin{parse lines}[\noindent]{#1\\}
。其效果是保留换行符。默认的 LaTeX 行为是单个换行符折叠为无,两个或多个换行符变为单个换行符。parse lines
覆盖该行为,以便源中的每个换行符都会在输出中创建一个额外的换行符。
但这意味着我不能使用诸如\raggedright
、\theorem
和\begin{align}
; LaTeX 错误之类的东西,当它们与 结合时parse lines
。这是为什么?有没有一种替代方法parse lines
可以尊重多行换行并保持自动换行,但允许我使用这些命令?
答案1
阅读 OP 和其他人之间的评论,似乎 OP 想要的东西可能会得到满足\obeylines
。因此,也许这样...
它允许\raggedright
并通过限定范围来使用\obeylines
类似的数学环境。align
我把它封装在一个环境中obey
,该环境以可选参数的形式表示退出时要回跳的行数,这在转换到 displaystyle 数学环境时可能会需要。
这是 MWE
\documentclass{article}
\usepackage{amsmath}
\newenvironment{obey}[1][0]{\obeylines\xdef\bsmult{#1}}{\par\vspace{-\bsmult\baselineskip}}
\edef\svparindent{\the\parindent}
\begin{document}
\begin{obey}[1]
JUSTIFIED: And here, is more. And here, is more. And here, is more. And here, is more. And here, is more. And here, is more. And here, is more. And here, is more. And here, is more. And here, is more.
this
is a
test.
And here, is more. And here, is more. And here, is more. And here, is more. And here, is more. And here, is more. And here, is more. And here, is more. And here, is more. And here, is more.
\end{obey}
\begin{align}
y &= mx + b\\
e &= mc^2
\end{align}
\begin{obey}
RAGGED:this continues the test.
\raggedright\parindent\svparindent\relax
And here, is more. And here, is more. And here, is more. And here, is more. And here, is more. And here, is more. And here, is more. And here, is more. And here, is more. And here, is more.
\end{obey}
This is the next text outside of \texttt{obey} mode.
\end{document}