# Making the indentation of a multi-line paragraph equal to the indentation of the first line

I have the following input that I receive from a third-party program:

START OF SECTION
This is a long sentence; really long that when rendered by PDFLatex it becomes a paragraph that spans a number of lines. Unfortunately, except the first line, all remaining lines will start from the very left of the document, but I want them to start from the indentation position of the first word of the paragraph.
START OF SECTION
This is a long sentence; really long that when rendered by PDFLatex it becomes a paragraph that spans a number of lines. Unfortunately, except the first line, all remaining lines will start from the very left of the document, but I want them to start from the indentation position of the first word of the paragraph.
START OF SECTION
This is a long sentence; really long that when rendered by PDFLatex it becomes a paragraph that spans a number of lines. Unfortunately, except the first line, all remaining lines will start from the very left of the document, but I want them to start from the indentation position of the first word of the paragraph.
END OF SECTION
END OF SECTION
END OF SECTION


I want to generate a PDF that looks exactly like is shown below: The indentation of each paragraph (the text inside the SECTION delimiters) follows the indentation of the first word/line of that paragraph.

I do not produce the text myself, like I said it is fed to me by another tool; so I cannot use enumeration unless I parse it and rewrite it with nested enumeration -- but I am trying to leave this as the very last resort.

Can anybody tell me the magic thing to do in order to instruct Latex to indent every paragraph according to its first line's indentation?

Many thanks.

\documentclass{article}

\begin{document}

\parindent0pt
\catcode\ \active
\def\par{\endgraf\leftskip=0pt\relax}%
\obeylines

START OF SECTION
This is a long sentence; really long that when rendered by PDFLatex it becomes a paragraph that spans a number of lines. Unfortunately, except the first line, all remaining lines will start from the very left of the document, but I want them to start from the indentation position of the first word of the paragraph.
START OF SECTION
This is a long sentence; really long that when rendered by PDFLatex it becomes a paragraph that spans a number of lines. Unfortunately, except the first line, all remaining lines will start from the very left of the document, but I want them to start from the indentation position of the first word of the paragraph.
START OF SECTION
This is a long sentence; really long that when rendered by PDFLatex it becomes a paragraph that spans a number of lines. Unfortunately, except the first line, all remaining lines will start from the very left of the document, but I want them to start from the indentation position of the first word of the paragraph.
END OF SECTION
END OF SECTION
END OF SECTION
\end{document}


It should work (I think) in RTL.

Vertical mode detects that you are between paragraphs, in that mode the space is not output at all, it is just used to increase the leftskip (oh, you may need rightskip) then once the paragraph starts and you are in horizontal mode a space expands to \space which is a normal space.

Then at the linebreak (end of paragraph here) \leftskip` is reset to 0 ready for the next set of spaces to increase it to the value needed for the next paragraph.

• Awesome, works like a charm :-) Many thanks. Oct 13, 2020 at 21:20
• Could you please explain to me the work of the vertical mode conditional? I need to apply the same formatting for input that is Non-English and RTL, and this otherwise flawless solution is not directly applicable there. Oct 13, 2020 at 21:33
• I'll add some notes. @AmineMarref Oct 13, 2020 at 21:39
• Superb, thank you for the concise explanation :-) Oct 13, 2020 at 22:05