# Is there a LaTeX package that lets me explicitely show indentation on paragraphs?

I'm looking for the following sort of effect in my document:

Or something like this:

Is there a package that lets me do this?

-
\begin{itemize}? –  Seamus Mar 15 '11 at 22:48
\lstset{showtabs=true,tab=\rightarrowfill} from package listings is close. –  Andrey Vihrov Mar 15 '11 at 23:26

The below code makes tabs active and increments a counter every time one is encountered. At the beginning of a paragraph, a paragraph hook is added that removes the box that is inserted by an indentation, checks the depth of the indentation, sets \leftskip to the depth times \parindent, and then adds a arrow of the appropriate width to the left.

\documentclass{article}
\usepackage{everyhook}
\usepackage{lipsum}
\newcount\indentdepth
\newdimen\savedleftskip
\catcode\^^I\active
\newenvironment{tabs}{%
\savedleftskip=\leftskip
\catcode\^^I\active
\def^^I{%
\ifhmode
\par
\fi
}%
\PushPreHook{par}{%
{\setbox0\lastbox}% kill the indent
\ifnum\indentdepth>0
\leftskip\dimexpr\savedleftskip+\parindent*\indentdepth\relax
\llap{\hbox to\leftskip{\rightarrowfill}}%
\fi
}%
\def\par{%
\endgraf
\indentdepth=0
\leftskip=\savedleftskip
}%
\indentdepth=0
}{%
\par
\PopPreHook{par}%
}
\catcode^^I10
\begin{document}
\begin{tabs}
No indent on the text here.
One indent.
Two indent.
More.
Even More.
Blah.
Back to one indent.

Back to no indent.
\lipsum[1]
\lipsum[2]
\end{tabs}
\end{document}


Note that there is a blank line before Back to no indent. The reason for this is that unless TeX pays attention to the end of lines (e.g., by using \obeylines), there's no way to distinguish end of line from a space. Any of the indented material can be distinguished because the tab character causes the paragraph to end.

If you copy and paste this code, it's important that you change the 8 space indentation in the use of the tabs environment into actual "hard" tabs.

Here's a second way to do it that looks like your second example. Here, a newline starts a new line in the output. Any line that is taller than a \strut will not have the appropriate rule drawn in front of it.

\documentclass{article}
\usepackage{everyhook}
\newdimen\tabwidth
\newcount\indentdepth
\tabwidth=\parindent
\catcode\^^I\active
\newenvironment{tabs}{%
\catcode\^^I\active
\def\par{\endgraf\indentdepth=0}%
\PushPreHook{par}{%
\ifnum\indentdepth>0
\hbox to\dimexpr\tabwidth*\indentdepth{%
\hfill\vrule height\ht\strutbox depth\dp\strutbox\ %
}%
\fi
}%
\parindent=0pt
\obeylines
\indentdepth=0
}{%
\PopPreHook{par}%
}
\catcode\^^I10
\begin{document}
\begin{tabs}
No indent on the text here.
One indent.
Two indent.
More
Even More.
Blah.
Back to one indent.
Back to no indent.
\end{tabs}
\end{document}


Again, be sure to add the tabs back in.

-
Thanks, this is excellent! –  Mana Mar 16 '11 at 12:58