Starting a line where the previous line finishes
Standard TeX has one way to measure the last line in a partial paragraph, it is a bit sneaky but there you go. At least it makes coding inside the document then nice and easy: normal line breaks with \\
and special ones with \magicom
. This allows even for some lines to be automatically broken.
\documentclass{article}
\makeatletter
\def\magicomadjust{0em} % a way to adjust if the spacing should be different
\newdimen\indent@amount
\def\magicom{\relax
\ifhmode $$%
\predisplaypenalty\@M \postdisplaypenalty\@M
\abovedisplayskip-\baselineskip \belowdisplayskip\z@
\abovedisplayshortskip\abovedisplayskip
\belowdisplayshortskip\belowdisplayskip
\global\indent@amount\predisplaysize
$$\count@\prevgraf \advance\count@-\thr@@
\prevgraf\count@
\global\advance\indent@amount-2em % correction for \predisplaysize indent
\global\advance\indent@amount\magicomadjust % correction for verse env, for example
\hspace*\indent@amount
\else\typeout{*Not in hmode*}\fi}
\makeatother
\begin{document}
%\begin{verse}
This is some\magicom
text I would\\
like to\magicom
format and it nicely allows for several lines written with automatic lines breaks as well, as we can see here.
How can I do this with\magicom
\LaTeX?
%\end{verse}
\end{document}
This then gives us:
If we uncomment the verse
environment above and use
\renewcommand\magicomadjust{-4em}
we get the following:
What does the code do?
- test if we are in horizontal mode (if not warning)
- start a display math formula (indeed :-)
- set various variables for math displays, so that this display doesn't really show up and mess up spacing (vertial skip is a negative baseline above and zero below, penalties are set so this isn't introducing a break, ...)
- then we store the
\predisplaysize
away (that is the width of the last line before the display + 2em) ... everything else was just done to get this variable set, i.e., doing the measurement for us - then we end the display (and it takes up one line (empty) and because of the settings above this is not visible
- after the display we have to reduce the value of
\prevgraf
by 3 as a display takes up 3 lines (nominally in TeX's counting). This can be needed in some case when a\parshape
is in effect - then we reduce the saved value by 2em and and we add
\magicomadjust
(which I used for theverse
example - and finally we use the resulting value to produce the desired indentation after the display
The tabbing
environment provides this functionality where you designate the tabs via \=
and skip to them using \>
:
\documentclass{article}
\begin{document}
\begin{tabbing}
This is some \= text I would \\
\> text I would \\
like to \= format \\
\> format \\
How can I do this with \= \LaTeX? \\
\> \LaTeX?
\end{tabbing}
\end{document}
For completeness, I've doubled the content so you can see the tabbing is at the appropriate horizontal location. More help on the use of tabbing
is available from TeX Blog.
I think it's simpler (and takes less markup) if you think of it as lowering the rest of the current line rather than making the next line start where the last one ended.
\documentclass{article}
{\obeylines%
\gdef\drop#1
{\smash{\lower\baselineskip\hbox{#1}}\par\vskip\baselineskip}}%
\begin{document}
\obeylines
This is some \drop text I would
like to \drop format
How can I do this with \drop \LaTeX?
\end{document}