使多行段落的缩进等于第一行的缩进

使多行段落的缩进等于第一行的缩进

我从第三方程序收到以下输入:

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

我想要生成一个看起来与下面显示的完全一样的 PDF:每个段落的缩进(SECTION 分隔符内的文本)遵循该段落第一个单词/行的缩进。

在此处输入图片描述

我自己并不制作文本,就像我说的那样,它是由另一个工具提供给我的;因此,除非我解析它并用嵌套枚举重写它,否则我不能使用枚举 - 但我试图将此作为最后的手段。

有人能告诉我做什么神奇的事情才能指示 Latex 根据第一行的缩进来缩进每个段落吗?

非常感谢。

答案1

在此处输入图片描述

\documentclass{article}

\begin{document}


\parindent0pt
\catcode`\ \active
\def\par{\endgraf\leftskip=0pt\relax}%
\obeylines
\def {\ifvmode\advance\leftskip5pt\relax\else\space\fi}%


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}

我认为它应该在 RTL 中起作用。

垂直模式检测到您位于段落之间,在该模式下根本不输出空格,它仅用于增加左跳跃(哦,您可能需要右跳跃)然后一旦段落开始并且您处于水平模式,空格就会扩展为\space正常空格。

然后在换行符(此处为段落末尾)\leftskip重置为 0,为下一组空格做好准备,以将其增加到下一段所需的值。

相关内容