4

I want to set a text following the line breaks in a certain edition, and I want it to be justified. I suppose I should use \obeylines, but don't know how to get the lines justified.

  • I think that adding \linebreak at the desired places is easier. – egreg Jan 12 '16 at 13:31
5

Some more testing with actual text and the desired pagination parameters would be needed, but this should be a starting point.

\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}

enter image description here

The idea is similar to \obeyspaces, but instead of making the end-of-line character equivalent to \par, I make it into \mbox{}\linebreak. Note \mbox{}, so an empty line in input will leave a blank line in output; this can be avoided by using explicitly \par% where a paragraph break is wanted.

At the end a space is removed (if it sneaked in) and \unpenalty will remove the trailing \linebreak. The \hbadness10000 bit is for avoiding irrelevant messages about underfull boxes (you know there will be). The first token in the environment is absorbed as an argument in order to avoid the end-of-line after \begin{originalbreaks} to be turned into \mbox{}\linebreak.

  • @DavidCarlisle Yes, flawless! – egreg Jan 12 '16 at 20:42
  • Thanks! could I bother you to add some comments to the code? in particular, I don't understand what the ~ and the #1 are about. – Toothrot Jan 12 '16 at 22:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.