# Justified text with predefined line breaks

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

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]
\begingroup\lccode~=\^^M
\lowercase{\endgroup\def~}{\mbox{}\linebreak}%
\catcode\^^M=\active#1}

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


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