# \setindent hack and alignment between parallel paragraphs with reledmac

Based on David Carlisle's answer here, I've defined a macro that stores the length of the last line of the current paragraph. But when using it with reledmac and -par, it messes up the alignment parallel paragraphs. Does anyone understand why?

\documentclass{article}
\usepackage{reledmac}
\usepackage{reledpar}
\usepackage{lipsum}

\makeatletter
\def\setindent{%
{\abovedisplayshortskip\z@\abovedisplayskip\z@
\belowdisplayshortskip\z@\belowdisplayskip\z@
$$\global\dimen\@ne\predisplaysize \xdef\tmp{% \predisplaysize\the\predisplaysize \prevgraf\the\prevgraf\relax}%$$\vskip\dimexpr-\parskip-\baselineskip\relax}\tmp
}
\dimen\@ne=\parindent

\begin{document}
\begin{pages}
\begin{Leftside}
\beginnumbering
\pstart
\lipsum*[1]
\pend

\pstart
\lipsum*[2]
\pend

\pstart
\lipsum*[3]
\pend

\pstart
\lipsum*[4]
\pend
\endnumbering
\end{Leftside}

\begin{Rightside}
\beginnumbering
\pstart
\lipsum*[5]\setindent
\pend

\pstart
\lipsum*[6]\setindent
\pend

\pstart
\makeatletter
\noindent\hskip\dimen\@ne
\lipsum*[7]\setindent
\pend

\pstart
\makeatletter
\noindent\hskip\dimen\@ne
\lipsum*[8]
\pend
\endnumbering
\end{Rightside}
\end{pages}
\Pages
\end{document}

• Not sure what problem you see, you set the indent three times but don't use the first one, the two that you do use seem to work OK, see places marked with !!!! here – David Carlisle Mar 3 '16 at 21:34
• sorry, but what is the need ? what setindent should do ? – Maïeul Mar 3 '16 at 21:37
• @DavidCarlisle, the problem is that the paragraphs are not aligned/synced with the corresponding pars on page 2, which they are if the 3 \setindent are commented out. – Toothrot Mar 3 '16 at 21:38
• @Maïeul, allow the next paragraph to begin where the previous ended (horizontally). – Toothrot Mar 3 '16 at 21:39
• @Lawrence ok. strange need, but why not. The problem is that pstart / pend structure of reledmac/reledpar Does not contain any \vskip. It brokes all the way reledmac works. – Maïeul Mar 3 '16 at 21:41

\pstart…\pend must contain only normal text. Not mathematical display, and not \vskip. Any entry like this perturbate the way reledmac/reledpar split lines, and so the alignment.

# Principle of my solution

We will use a \setindent but OUTSIDE of the \pstart…\pend. To do that, we use the fact that in parallel typesetting, reledpar stores the \pstart…\pend content in numbered vbox. So we will copy the content of the box, and using some TeX' hacks on box mechanism, get the last line of the vbox. And then, using new code provide by David Carlisle, get the natural width of the lastline.

# Other inhancement

As explained by chat, you should not use \maketaletter without a corresponding \makeatother. And if you use many time command with @ in the name, you should wrap it in an other command. I have created a \myindent command.

# So, final code

\documentclass{article}
\usepackage{reledmac}
\usepackage{reledpar}
\usepackage{lipsum}

\makeatletter
% My new setindent
\def\setindent{%
\ifledRcol
\setbox0=\expandafter\copy\csname l@dRcolrawbox\the\l@dnumpstartsR\endcsname%On rightside, copy the content of last \pstart…\pend pair
\else
\setbox0=\expandafter\copy\csname l@dLcolrawbox\the\l@dnumpstartsL\endcsname%On leftside, copy the content of last \pstart…\pend pair
\fi
\expandafter\newdimen\csname l@\the\l@dnumpstartsR\endcsname%
\setbox0=\vbox{%
\parindent=0pt%
\setbox1=\vsplit0 to\baselineskip%Get only the last line in vbox0
\unvbox0%Unvbox it
\setbox0=\lastbox%Get the last line on the form of hbox
\setbox0=\hbox{\unhbox0\unpenalty\unskip\unskip}
\global\dimen\@ne=\wd0%
}%We do it in a setbox in order to print nothing
}
% Avoid to use command with @ in the main text
\newcommand{\myindent}{\noindent\hskip\dimen\@ne}% I don't understand why we need such correction of 20pt !!! But it is not linked to reledmac,  as a test of your \setindent outside of any reledmac context can prove
\makeatletter
\begin{document}
\begin{pages}

\begin{Leftside}
\beginnumbering
\pstart
\lipsum*[1]
\pend

\pstart
\lipsum*[2]
\pend

\pstart
\lipsum*[3]
\pend

\pstart
\lipsum*[4]
\pend
\endnumbering
\end{Leftside}

\begin{Rightside}
\beginnumbering
\pstart
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur?
\pend
\setindent
\pstart
\myindent\lipsum*[6]%
\pend
\setindent
\pstart
\myindent
\lipsum*[7]%
\pend
\setindent
\pstart
\myindent\lipsum*[8]
\pend
\setindent
\endnumbering
\end{Rightside}
\end{pages}
\Pages

\end{document}


# A variant

\newcommand{\myindent}{\noindent\hskip\dimen\@ne}


Do

\newcommand{\myindent}{\noindent\ \hskip\dimen\@ne}


It will add a space, as required after a final dot.

• the 20pt is 2em (in the font current at the end of the para) \predisplaysize is 2em larger than the last line of the para, which is not the most obvious definition that you might imagine but that's the way it is, however if I understand your code correctly you don't need to use \predisplaysize at all, you have the last line of the para in a box so you can just measure it (taking in to account \parfillskip). – David Carlisle Mar 4 '16 at 0:19
• I have the last line in a box, indeed, but including the \parfillskip. So it width is everytime equals to \hsize. – Maïeul Mar 4 '16 at 9:35
• just an other question : this 2em is fixed, or defined in a TeX length? – Maïeul Mar 4 '16 at 9:38
• fixed in tex-the-program – David Carlisle Mar 4 '16 at 10:00
• @Lawrence : I have update the code using the comment of David. It is smarter ;-) – Maïeul Mar 4 '16 at 10:16