From 2f667f4d777c2ce38eb648f49ae5fde2c644dcfc Mon Sep 17 00:00:00 2001
From: Karl Berry <karl@freefriends.org>
Date: Wed, 30 Sep 2015 21:17:05 +0000
Subject: reledmac (30sep15)

git-svn-id: svn://tug.org/texlive/trunk@38505 c570f23f-e606-0410-a88d-b1316a301751
---
 Master/texmf-dist/tex/latex/reledmac/reledpar.sty | 358 +++++++++++++++++-----
 1 file changed, 278 insertions(+), 80 deletions(-)

(limited to 'Master/texmf-dist/tex/latex/reledmac/reledpar.sty')

diff --git a/Master/texmf-dist/tex/latex/reledmac/reledpar.sty b/Master/texmf-dist/tex/latex/reledmac/reledpar.sty
index c3d837be570..c14c9498cf6 100644
--- a/Master/texmf-dist/tex/latex/reledmac/reledpar.sty
+++ b/Master/texmf-dist/tex/latex/reledmac/reledpar.sty
@@ -27,12 +27,34 @@
 
 
 \NeedsTeXFormat{LaTeX2e}
-\ProvidesPackage{reledpar}[2015/09/05 v2.3.0 reledmac extension for parallel texts]%
+\ProvidesPackage{reledpar}[2015/09/29 v2.4.0 reledmac extension for parallel texts]%
 
 \RequirePackage{xspace}%
 \RequirePackage{xkeyval}
+\def\@par@this@sync@option{}%
 \newif\ifshiftedpstarts
-\DeclareOptionX{shiftedpstarts}{\shiftedpstartstrue}
+\DeclareOptionX{shiftedpstarts}{%
+ \shiftedpstartstrue%
+ \apptocmd{\@par@this@sync@option}{shifted}{}{}%
+}%
+\newif\ifadvancedshiftedpstarts
+\DeclareOptionX{advancedshiftedpstarts}{%
+  \advancedshiftedpstartstrue%
+  \shiftedpstartstrue%
+  \apptocmd{\@par@this@sync@option}{advancedshifted}{}{}%
+}%
+\newif\ifnomaxlines%
+\DeclareOptionX{nomaxlines}{%
+  \nomaxlinestrue%
+  \apptocmd{\@par@this@sync@option}{nomax}{}{}%
+}%
+\newif\ifnosyncpstarts%
+\DeclareOptionX{nosyncpstarts}{%
+  \shiftedpstartstrue%
+  \nomaxlinestrue%
+  \nosyncpstartstrue%
+  \apptocmd{\@par@this@sync@option}{nosync}{}{}%
+}%
 \DeclareOptionX{parledgroup}{\parledgrouptrue}
 \DeclareOptionX{widthliketwocolumns}{\widthliketwocolumnstrue}%
 \newif\ifsameparallelpagenumber
@@ -46,6 +68,7 @@
 \newdimen\Rcolwidth
   \Rcolwidth=0.45\textwidth
 \newcommand{\reledpar@error}[2]{\PackageError{reledpar}{#1}{#2}}
+\newcommand{\reledpar@warning}[1]{\PackageWarning{reledpar}{#1}}%
 \newcommand*{\led@err@TooManyPstarts}{%
   \reledpar@error{Too many \string\pstart\space without printing.
                 Some text will be lost}{\@ehc}}
@@ -76,6 +99,9 @@
 \newcommand{\led@error@fail@patch@@outputpage}{%
   \reledpar@error{Fail to patch \string\@outputpage\space command.}{\@ehc}%
 }%
+\newcommand*{\led@warn@ChangeSyncOption}[1]{%
+  \reledpar@warning{You have changed synchronization's options since last run. We have not read line-list file #1. Please run LaTeX again.}%
+}%
 \newcount\section@numR
   \section@numR=\z@
   \pst@rtedLfalse
@@ -323,6 +349,17 @@
     \list@clear{\linesinpar@listR}%
     \list@clear{\linesonpage@listR}
 }
+\newcommand{\@par@sync@option}[1]{%
+  \IfStrEq{#1}{\@par@this@sync@option}%
+    {}%
+    {\ifledRcol%
+       \led@warn@ChangeSyncOption{\jobname.\extensionchars\the\section@num}%
+     \else%
+       \led@warn@ChangeSyncOption{\jobname.\extensionchars\the\section@num}%
+     \fi%
+     \endinput%
+    }%
+}%
 \newcommand{\@nl@regR}{%
   \ifx\l@dchset@num\relax \else
     \advance\absline@numR \@ne
@@ -465,6 +502,26 @@
   \ifbypstart@R\global\line@numR=0\fi
   \xright@appenditem{#1}\to\linesinpar@listR}
 
+\newcommand{\@pstart}[3]{%
+  \ifcsdef{minpage@pstart@#1}%
+    {\ifnumgreater{#2}{\csuse{minpage@pstart@#1}}%
+      {\csnumgdef{minpage@pstart@#1}{#2}}%
+      {}%
+    }%
+    {\csnumgdef{minpage@pstart@#1}{#2}}
+  \csnumgdef{afterlines@pstart@#1L}{#3}%
+  }%
+
+\newcommand{\@pstartR}[3]{%
+  \numdef{\@tmp}{#2-1}%Because we have not to know in which page the pstart starts, but in which pair of facing page
+  \ifcsdef{minpage@pstart@#1}%
+    {\ifnumgreater{\@tmp}{\csuse{minpage@pstart@#1}}%
+      {\csnumgdef{minpage@pstart@#1}{\@tmp}}%
+      {}%
+    }%
+    {\csnumgdef{minpage@pstart@#1}{\@tmp}}
+   \csnumgdef{afterlines@pstart@#1R}{#3}%
+}%
 \renewcommand*{\@lopL}[1]{%
   \xright@appenditem{#1}\to\linesonpage@listL}
 \renewcommand*{\@lopR}[1]{%
@@ -480,6 +537,9 @@
      \global\first@linenum@out@Rfalse
      \immediate\openout\linenum@outR=#1
      \immediate\write\linenum@outR{\string\line@list@version{\this@line@list@version}}%
+     \ifl@dpaging%
+       \immediate\write\linenum@outR{\string\@par@sync@option{\@par@this@sync@option}}%
+     \fi%
   \else
      \if@minipage%
        \leavevmode%
@@ -806,38 +866,41 @@
   \letcs{\ifnumberpstart}{numberpstart@L\the\l@dpscL}%
   \advance\countLline \@ne%
   \ifvbox\namebox{l@dLcolrawbox\the\l@dpscL}%
-  {\vbadness=10000%
-   \splittopskip=\z@%
-   \do@lineLhook%
-   \l@demptyd@ta%
-   \global\setbox\one@line=\vsplit\namebox{l@dLcolrawbox\the\l@dpscL}%
+    {\vbadness=10000%
+     \splittopskip=\z@%
+     \do@lineLhook%
+     \l@demptyd@ta%
+     \global\setbox\one@line=\vsplit\namebox{l@dLcolrawbox\the\l@dpscL}%
                            to\baselineskip}%
-  \IfStrEq{\splitfirstmarks\parledgroup@}{begin}{\parledgroup@notes@startL}{}%
-  \unvbox\one@line \global\setbox\one@line=\lastbox%
-  \getline@numL%
-  \ifnum\@lock>\@ne%
-    \inserthangingsymboltrue%
-  \else%
-    \inserthangingsymbolfalse%
-  \fi%
-  \setbox\l@dleftbox%
-  \hb@xt@ \Lcolwidth{%
-    \ifl@dhidenumber%
-      \global\l@dhidenumberfalse%
-      \f@x@l@cks%
+    \IfStrEq{\splitfirstmarks\parledgroup@}{begin}{\parledgroup@notes@startL}{}%
+    \unvbox\one@line \global\setbox\one@line=\lastbox%
+    \@writepageofparL%
+    \getline@numL%
+    \ifnum\@lock>\@ne%
+      \inserthangingsymboltrue%
     \else%
-      \affixline@num%
+      \inserthangingsymbolfalse%
     \fi%
-    \xifinlist{\the\l@dpscL}{\eled@sections@@}%
-      {\add@inserts\affixside@note}%
-      {\print@lineL}}%
-  \add@penaltiesL%
-  \global\advance\@donereallinesL\@ne%
-  \global\advance\@donetotallinesL\@ne%
-\else%
-  \setbox\l@dleftbox \hb@xt@ \Lcolwidth{\hspace*{\Lcolwidth}}%
-  \global\advance\@donetotallinesL\@ne%
-\fi}
+    \setbox\l@dleftbox%
+    \hb@xt@ \Lcolwidth{%
+      \ifl@dhidenumber%
+        \global\l@dhidenumberfalse%
+        \f@x@l@cks%
+      \else%
+        \affixline@num%
+      \fi%
+      \xifinlist{\the\l@dpscL}{\eled@sections@@}%
+        {\add@inserts\affixside@note}%
+        {\print@lineL}%
+      }%
+    \add@penaltiesL%
+    \global\advance\@donereallinesL\@ne%
+    \global\advance\@donetotallinesL\@ne%
+  \else%
+    \setbox\l@dleftbox \hb@xt@ \Lcolwidth{\hspace*{\Lcolwidth}}%
+    \global\advance\@donetotallinesL\@ne%
+  \fi%
+}%
 
 \def\print@lineL{%
     \affixpstart@numL%
@@ -899,40 +962,41 @@
   \ledRcol@true%
   \advance\countRline \@ne%
   \ifvbox\namebox{l@dRcolrawbox\the\l@dpscR}%
-  {\vbadness=10000%
-   \splittopskip=\z@%
-   \do@lineRhook%
-   \l@demptyd@ta%
-   \global\setbox\one@lineR=\vsplit\namebox{l@dRcolrawbox\the\l@dpscR}%
+    {\vbadness=10000%
+     \splittopskip=\z@%
+     \do@lineRhook%
+     \l@demptyd@ta%
+     \global\setbox\one@lineR=\vsplit\namebox{l@dRcolrawbox\the\l@dpscR}%
                            to\baselineskip}%
-  \IfStrEq{\splitfirstmarks\parledgroup@}{begin}{\parledgroup@notes@startR}{}%
-  \unvbox\one@lineR \global\setbox\one@lineR=\lastbox%
-  \getline@numR%
-  \ifnum\@lockR>\@ne%
-    \inserthangingsymbolRtrue%
-  \else%
-    \inserthangingsymbolRfalse%
-  \fi%
-  \setbox\l@drightbox%
-  \hb@xt@ \Rcolwidth{%
-    \ifl@dhidenumber%
-      \global\l@dhidenumberfalse%
-      \f@x@l@cksR%
+    \IfStrEq{\splitfirstmarks\parledgroup@}{begin}{\parledgroup@notes@startR}{}%
+    \unvbox\one@lineR \global\setbox\one@lineR=\lastbox%
+    \@writepageofparR%
+    \getline@numR%
+    \ifnum\@lockR>\@ne%
+      \inserthangingsymbolRtrue%
     \else%
-      \affixline@numR%
+      \inserthangingsymbolRfalse%
     \fi%
-    \xifinlist{\the\l@dpscR}{\eled@sectionsR@@}%
-     {\add@insertsR\affixside@noteR}%
-     {\print@lineR}%
-  }%
-  \add@penaltiesR%
-  \global\advance\@donereallinesR\@ne%
-  \global\advance\@donetotallinesR\@ne%
-\else%
-  \setbox\l@drightbox \hb@xt@ \Rcolwidth{\hspace*{\Rcolwidth}}%
-  \global\advance\@donetotallinesR\@ne%
-\fi%
-\ledRcol@false%
+    \setbox\l@drightbox%
+    \hb@xt@ \Rcolwidth{%
+      \ifl@dhidenumber%
+        \global\l@dhidenumberfalse%
+        \f@x@l@cksR%
+      \else%
+        \affixline@numR%
+      \fi%
+     \xifinlist{\the\l@dpscR}{\eled@sectionsR@@}%
+       {\add@insertsR\affixside@noteR}%
+       {\print@lineR}%
+    }%
+    \add@penaltiesR%
+    \global\advance\@donereallinesR\@ne%
+    \global\advance\@donetotallinesR\@ne%
+  \else%
+    \setbox\l@drightbox \hb@xt@ \Rcolwidth{\hspace*{\Rcolwidth}}%
+    \global\advance\@donetotallinesR\@ne%
+  \fi%
+  \ledRcol@false%
 }
 
 \def\print@lineR{%
@@ -1672,6 +1736,22 @@
   \next
   \global\@donereallinesR \z@}
 
+\newcommand*{\@writepageofparL}[0]{%
+  \ifnum\@donereallinesL=\z@%
+    \edef\next{%
+      \write\linenum@out{\string\@pstart{\the\l@dpscL}{\the\c@page}{\the\numpagelinesL}}%
+    }%
+    \next%
+  \fi%
+}%
+\newcommand*{\@writepageofparR}[0]{%
+  \ifnum\@donereallinesR=\z@%
+    \edef\next{%
+      \write\linenum@outR{\string\@pstartR{\the\l@dpscR}{\the\c@page}{\the\numpagelinesR}}%
+    }%
+  \next%
+  \fi%
+}%
 \newsavebox{\@eledsectionL}%
 \newsavebox{\@eledsectionR}%
 \newcommand*{\Columns}{%
@@ -1937,10 +2017,11 @@
 \newcount\numpagelinesR
 \newcount\l@dminpagelines
 
-\newcommand*{\Pages}{%
+\newcommandx*{\Pages}[1][1,usedefault]{%
   \ifl@dpairing%
     \led@err@Pages@InsideEnv%
   \fi%
+  \ifstrequal{#1}{mainmatter}{\Pages@mainmattertrue}{\Pages@mainmatterfalse}%
   \eledsection@correcting@skip=-2\baselineskip% line correcting for section titles.
   \parledgroup@notespacing@set@correction%
   \typeout{}%
@@ -2008,16 +2089,30 @@
                         \parledgroup@correction@notespacing{L}%
                         \hb@xt@ \hsize{\ledstrutL\unhbox\l@dleftbox}%
                       \else%
-                        \dimen0=\pagetotal%
-                        \advance\dimen0 by \baselineskip%
-                        \global\pagetotal=\dimen0%
+                        \unless\ifadvancedshiftedpstarts%
+                          \dimen0=\pagetotal%
+                          \advance\dimen0 by \baselineskip%
+                          \global\pagetotal=\dimen0%
+                        \else%
+                          \ifnomaxlines%
+                            \numdef{\@tmp}{\the\l@dpscL+1}%
+                            \ifcsdef{minpage@pstart@\@tmp}{%
+                              \ifnumless{\the\c@page}{\csuse{minpage@pstart@\@tmp}}%
+                              {\dimen0=\pagetotal%
+                               \advance\dimen0 by \baselineskip%
+                               \global\pagetotal=\dimen0%
+                               }%
+                              {}%
+                            }{}%
+                          \fi%
+                        \fi%
                       \fi%
               \else%
                       \parledgroup@correction@notespacing{L}%
                       \hb@xt@ \hsize{\ledstrutL\unhbox\l@dleftbox}%
               \fi%
               \get@nextboxL%
-    \global\l@dskipversenumberfalse%
+              \global\l@dskipversenumberfalse%
                   \ifprint@last@after@pendL%
                      \csuse{after@pendL@\the\l@dpscL}%
                      \global\csundef{after@pendL@\the\l@dpscL}%
@@ -2051,16 +2146,30 @@
                         \parledgroup@correction@notespacing{R}%
                         \hb@xt@ \hsize{\ledstrutR\unhbox\l@drightbox}%
                       \else%
-                        \dimen0=\pagetotal%
-                        \advance\dimen0 by \baselineskip%
-                        \global\pagetotal=\dimen0%
+                        \unless\ifadvancedshiftedpstarts%
+                          \dimen0=\pagetotal%
+                          \advance\dimen0 by \baselineskip%
+                          \global\pagetotal=\dimen0%
+                        \else%
+                          \ifnomaxlines%
+                            \numdef{\@tmp}{\the\l@dpscR+1}%
+                            \ifcsdef{minpage@pstart@\@tmp}{%
+                              \ifnumless{\the\c@page}{\csuse{minpage@pstart@\@tmp}}%
+                              {\dimen0=\pagetotal%
+                               \advance\dimen0 by \baselineskip%
+                               \global\pagetotal=\dimen0%
+                               }%
+                              {}%
+                            }{}%
+                          \fi%
+                        \fi%
                       \fi%
               \else%
                       \parledgroup@correction@notespacing{R}%
                       \hb@xt@ \hsize{\ledstrutR\unhbox\l@drightbox}%
               \fi%
               \get@nextboxR%
-     \global\l@dskipversenumberRfalse%
+              \global\l@dskipversenumberRfalse%
                   \ifprint@last@after@pendR%
                      \csuse{after@pendR@\the\l@dpscR}%
                      \global\csundef{after@pendR@\the\l@dpscR}%
@@ -2119,8 +2228,8 @@
   }%
   \dolistloop{\@series}%
 }%
-\newcommand*{\ledstrutL}{\strut}
-\newcommand*{\ledstrutR}{\strut}
+\newcommand*{\ledstrutL}{}
+\newcommand*{\ledstrutR}{}
 
 \providecommand{\cleartoevenpage}[1][\@empty]{%
   \clearpage
@@ -2130,6 +2239,7 @@
   \ifdim\pagetotal<\topskip%  on an empty page
   \else
     \clearpage
+    \Pages@mainmatter%
   \fi
   \ifodd\c@page%
     \ifprevpgnotnumbered%
@@ -2214,8 +2324,11 @@
   \ifdim\pagetotal<\ledthegoal
     \ifnum\numpagelinesL<\l@dminpagelines
     \else
-      \l@dsamepagefalse
-      \l@dpagefullfalse
+      \ifnomaxlines%
+      \else%
+        \l@dsamepagefalse%
+        \l@dpagefullfalse%
+      \fi%
     \fi
   \else
     \l@dsamepagefalse
@@ -2235,8 +2348,11 @@
   \ifdim\pagetotal<\ledthegoal
     \ifnum\numpagelinesR<\l@dminpagelines
     \else
-      \l@dsamepagefalse
-      \l@dpagefullfalse
+      \ifnomaxlines%
+      \else%
+        \l@dsamepagefalse%
+        \l@dpagefullfalse%
+      \fi%
     \fi
   \else
     \l@dsamepagefalse
@@ -2309,12 +2425,49 @@
 \newif\ifwrittenlinesL
 \newif\ifwrittenlinesR
 
+\newif\if@getnextbox%
 \newcommand*{\get@nextboxL}{%
   \ifvbox\namebox{l@dLcolrawbox\the\l@dpscL}% box is not empty
   \else%                                      box is empty
+    \@getnextboxtrue%Should be local, but be cautious
     \ifnum\usenamecount{l@dmaxlinesinpar\the\l@dpscL}>\@donetotallinesL
-      \parledgroup@notes@endL
-    \else
+      \parledgroup@notes@endL%
+      \unless\ifnosyncpstarts%
+        \@getnextboxfalse%
+        \ifnomaxlines%
+          \ifdim\pagetotal<\ledthegoal%
+            \numdef{\@tmp}{\l@dpscL+1}%
+            \ifcsdef{afterlines@pstart@\@tmp R}{%
+              \ifnumless{\numpagelinesL}{\csuse{afterlines@pstart@\@tmp R}}%
+                 {}%
+                 {\ifcsdef{minpage@pstart@\@tmp}%
+                   {\ifnumless{\the\c@page}{\csuse{minpage@pstart@\@tmp}}%
+                     {\ifnum\numpagelinesL=\l@dminpagelines%
+                          \@getnextboxtrue%
+                      \fi%
+                     }%
+                     {\@getnextboxtrue}}%
+                   {\@getnextboxtrue}%
+                 }%
+              }%
+              {}%
+          \fi%
+        \fi%
+      \fi%
+    \else%
+       \ifnomaxlines%
+         \numdef{\@tmp}{\the\l@dpscL+1}%
+         \ifcsdef{minpage@pstart@\@tmp}{%
+           \ifnumless{\the\c@page}{\csuse{minpage@pstart@\@tmp}}%
+             {\ifdimgreater{\pagetotal}{\ledthegoal}%
+                {\@getnextboxtrue}%
+                {\@getnextboxfalse}%
+             }%
+             {\@getnextboxtrue}%
+         }{}%
+       \fi%
+    \fi%
+    \if@getnextbox%
       \ifnum\usenamecount{l@dmaxlinesinpar\the\l@dpscL}=\@donetotallinesL
         \parledgroup@notes@endL
       \fi
@@ -2347,9 +2500,45 @@
 \newcommand*{\get@nextboxR}{%
   \ifvbox\namebox{l@dRcolrawbox\the\l@dpscR}% box is not empty
   \else%                                      box is empty
+    \@getnextboxtrue%
     \ifnum\usenamecount{l@dmaxlinesinpar\the\l@dpscR}>\@donetotallinesR
       \parledgroup@notes@endR
-    \else
+      \unless\ifnosyncpstarts%
+        \@getnextboxfalse%
+        \ifnomaxlines%
+          \ifdim\pagetotal<\ledthegoal%
+            \numdef{\@tmp}{\l@dpscR+1}%
+            \ifcsdef{afterlines@pstart@\@tmp L}{%
+              \ifnumless{\numpagelinesL}{\csuse{afterlines@pstart@\@tmp L}}%
+                 {}%
+                 {\ifcsdef{minpage@pstart@\@tmp}%
+                   {\ifnumless{\the\c@page}{\csuse{minpage@pstart@\@tmp}}%
+                     {\ifnum\numpagelinesR=\l@dminpagelines%
+                          \@getnextboxtrue%
+                      \fi%
+                     }%
+                     {\@getnextboxtrue}}%
+                   {\@getnextboxtrue}%
+                 }%%
+              }%
+              {}%
+          \fi%
+        \fi%
+      \fi%
+    \else%
+       \ifnomaxlines%
+         \numdef{\@tmp}{\the\l@dpscR+1}%
+         \ifcsdef{minpage@pstart@\@tmp}{%
+           \ifnumless{\the\c@page}{\csuse{minpage@pstart@\@tmp}}%
+             {\ifdimgreater{\pagetotal}{\ledthegoal}%
+                {\@getnextboxtrue}%
+                {\@getnextboxfalse}%
+             }%
+             {\@getnextboxtrue}%
+         }{}
+       \fi%
+    \fi%
+    \if@getnextbox%
       \ifnum\usenamecount{l@dmaxlinesinpar\the\l@dpscR}=\@donetotallinesR
         \parledgroup@notes@endR
       \fi
@@ -2441,6 +2630,15 @@
 }
 \newcounter{par@page}%
 \setcounter{par@page}{1}%
+\newif\ifPages@mainmatter
+\newcommand{\Pages@mainmatter}{%
+    \ifPages@mainmatter%
+      \pagenumbering{arabic}%
+      \addtocounter{page}{1}%
+      \addtocounter{par@page}{-1}%
+      \patchcmd{\thepage}{page}{par@page}{}{}%
+    \fi%
+}
 \pretocmd{\chapter}{%
   \ifl@dprintingpages%
     \vbox{}%
-- 
cgit v1.2.3

