带预定义换行符的对齐文本

带预定义换行符的对齐文本

我想在某个版本中设置换行符后的文本,并希望它对齐。我想我应该使用\obeylines,但不知道如何使行对齐。

答案1

需要对实际文本和所需的分页参数进行更多测试,但这应该是一个起点。

\documentclass{article}

\newenvironment{originalbreaks}[1]
 {\par\addvspace{\topsep}%
  \begingroup\lccode`~=`\^^M
  \lowercase{\endgroup\def~}{\mbox{}\linebreak}%
  \hbadness10000 % turn off warnings
  \catcode`\^^M=\active#1}
 {\unskip\unpenalty\par\addvspace{\topsep}}

\begin{document}

Some text with normal justification.
Some text with normal justification.
Some text with normal justification.
Some text with normal justification.
Some text with normal justification.
Some text with normal justification.

\begin{originalbreaks}
Some text where we want to preserve the original
breaks, even if this leads to very bad
typesetting.
\end{originalbreaks}

Some text with normal justification.
Some text with normal justification.
Some text with normal justification.
Some text with normal justification.
Some text with normal justification.
Some text with normal justification.

\end{document}

在此处输入图片描述

这个想法类似于\obeyspaces,但我没有将行尾字符设置为\par,而是将其改为\mbox{}\linebreak。注意\mbox{},因此输入中的空行将在输出中留下一个空行;这可以通过在\par%需要段落分隔符的位置明确使用 来避免。

最后删除一个空格(如果它潜入其中),\unpenalty并将删除尾随的\linebreak\hbadness10000是为了避免出现有关盒子未满的无关消息(您知道会有)。环境中的第一个标记被吸收作为参数,以避免之后的行尾\begin{originalbreaks}被变成\mbox{}\linebreak

相关内容