[texhax] A macro programming question

Paul Isambert zappathustra at free.fr
Mon Sep 12 08:37:46 CEST 2011


Le 12/09/2011 08:05, Vafa Khalighi a écrit :
> > I am trying to figure out how I can make longtable typeset RTL tabulars but
I
started with something much simpler to understand what I should do. The
bigtabular package is defined as:
> >
> > %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
> > \newskip\Tabularleftskip  \Tabularleftskip\@flushglue
> > \newskip\Tabularrightskip \Tabularrightskip\@flushglue
> > \newbox\Tabularbox
> > \newcount\Tabularcount
> > \newcount\Tabularcolumns
> > \def\@Tabclassz{\global\advance\Tabularcount\@ne\@tabclassz}
> > \let\@latexclassiii\@classiii
> > \def\@Tabclassiii{\global\advance\Tabularcount\@ne\@latexclassiii}
> > \def\@Tabularcr{{\ifnum0=`}\fi\@ifstar{\@xTabularcr}{\@xTabularcr}}
> > \def\@xTabularcr{\@ifnextchar[{\@argTabularcr}{\ifnum0=`{\fi}\cr
> >   \noalign{\pagebreak[1]}}}
> >
> > \def\@argTabularcr[#1]{\ifnum0=`{\fi}\ifdim #1>\z@
> >    \unskip\@xargarraycr{#1}\else \@yargarraycr{#1}\fi
> >  \noalign{\pagebreak[1]}}
> > \let\@latexhline\hline
> > \let\@latextabarray\@tabarray
> > \def\@tabarray{\let\hline\@latexhline\@latextabarray}
> > \def\Tabularhline{\multispan{\Tabularcolumns}{\unskip\leaders\hrule
> >     height\arrayrulewidth\hfill}\cr
> >   \noalign{\vskip-\arrayrulewidth\pagebreak[2]}%
> >   \multispan{\Tabularcolumns}{\unskip\leaders\hrule
> >     height\arrayrulewidth\hfill}\cr}
> >
> > \def\Tabular#1{\trivlist\item[]\noindent
> >   \setbox\Tabularbox\vbox\bgroup
> >     \let\@acol\@tabacol
> >     \let\@classz\@Tabclassz
> >     \let\@classiii\@Tabclassiii
> >     \let\@classiv\@tabclassiv
> >     \let\\\@Tabularcr
> >     \setbox\@arstrutbox=\hbox{\vrule
> >         height\arraystretch \ht\strutbox
> >         depth\arraystretch  \dp\strutbox
> >         width\z@}%
> >     \global\Tabularcount\z@
> >     \@mkpream{#1}%
> >     \Tabularcolumns\Tabularcount
> >     \let\hline\Tabularhline
> >     \let\@classiii\@latexclassiii
> >     \tabskip\Tabularleftskip
> >     \edef\@preamble{\halign to\linewidth\bgroup
> >       \tabskip\z@ \@arstrut \@preamble
> >       \tabskip\Tabularrightskip \cr}%
> >     \let\@starpbox\@@startpbox
> >     \let\@endpbox\@@endpbox
> >     \let\@sharp##\let\protect\relax
> >     \lineskip\z@\baselineskip\z@
> >     \@preamble}
> >
> > \def\endTabular{\crcr\egroup\egroup\unvbox\Tabularbox\endtrivlist}
> > %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
> >
> > To make it typeset tabular right to left, I thought of changing \Tabular and
\endTabular as follow:
> >
> > \def\Tabular#1{\trivlist\item[]\noindent
> >   \setbox\Tabularbox\vbox\bgroup
> >     \let\@acol\@tabacol
> >     \let\@classz\@Tabclassz
> >     \let\@classiii\@Tabclassiii
> >     \let\@classiv\@tabclassiv
> >     \let\\\@Tabularcr
> >     \setbox\@arstrutbox=\hbox{\vrule
> >         height\arraystretch \ht\strutbox
> >         depth\arraystretch  \dp\strutbox
> >         width\z@}%
> >     \global\Tabularcount\z@
> >     \@mkpream{#1}%
> >     \Tabularcolumns\Tabularcount
> >     \let\hline\Tabularhline
> >     \let\@classiii\@latexclassiii
> >     \tabskip\Tabularleftskip
> >     \edef\@preamble{\halign to\linewidth\bgroup
> >       \tabskip\z@ \@arstrut \@preamble
> >       \tabskip\Tabularrightskip \cr}%
> >     \let\@starpbox\@@startpbox
> >     \let\@endpbox\@@endpbox
> >     \let\@sharp##\let\protect\relax
> >     \lineskip\z@\baselineskip\z@
> >    \hbox\bgroup\beginR\vbox\bgroup \@preamble}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% This is my first change
> >
> >
\def\endTabular{\crcr\egroup\egroup\endR\egroup\egroup\unvbox\Tabularbox\endtrivlist}
> > %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
> >
> > but it no longer works (tabular appears on one page and no pagebreak
happens).
What should I do to fix this?


When \Tabularbox is unboxed, it normally releases the horizontal boxes making up
the lines of the tabular; in your case, it releases the first hbox you've added,
in which the lines of the tabular are still taken as a whole (hence no
possibility to break).

I don't know much about RTL typesetting, but to me the solution is simply to add
\beginR just after

    \setbox\Tabularbox\vbox\bgroup

and \endR between the two \egroup's in the original \endTabular.

Best,
Paul


More information about the texhax mailing list