[XeTeX] Hacking tabular packages for RTL typesetting (to the author of bidi.sty)

وفا خلیقی، Vafa Khalighi vafa at live.com.au
Mon May 11 15:53:32 CEST 2009



Hello, today I did several hacks for different tabular packages in LATeX that makes them to typeset tables from right to left, there is a problem with longtable.sty that it does not break tables. I thought you might find the codes useful. I would be very happy if someone could give me a hint to fix longtable.sty issue.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\@ifpackageloaded{stabular}{%
\def\@stabular{\if at RTL\global\@RTLtabtrue\fi
   \leavevmode \bgroup \if at RTLtab\beginR \fi
   \let\@acol\@tabacol

   \let\@classz\@tabclassz

   \let\@classiv\@tabclassiv \let\\\@tabularcr\@stabarray}
\def\endstabular{\crcr\egroup\if at RTLtab\egroup\endR\egroup\fi
                 \egroup \if at RTLtab\endR\fi\egroup
                 \global\@RTLtabfalse}

\expandafter \let \csname endstabular*\endcsname = \endstabular
\def\@sarray[#1]#2{%

  \bgroup

  \setbox\@arstrutbox\hbox{%

    \vrule \@height\arraystretch\ht\strutbox

           \@depth\arraystretch \dp\strutbox

           \@width\z@}%

  \@mkpream{#2}%

  \edef\@preamble{%

    \ialign \noexpand\@halignto

      \bgroup \@arstrut \@preamble \tabskip\z at skip \cr}%

  \let\@startpbox\@@startpbox \let\@endpbox\@@endpbox

  \let\tabularnewline\\%

%    \let\par\@empty

    \let\@sharp##%

    \set at typeset@protect

    \lineskip\z at skip\baselineskip\z at skip
  \if at RTLtab\hbox\bgroup\beginR\vbox\bgroup\fi

    \@preamble}
}{}

\@ifpackageloaded{longtable}{%
\def\LT at makecaption#1#2#3{%
  \LT at mcol\LT at cols c{\hbox to\z@{\hss\parbox[t]\LTcapwidth{%
    \sbox\@tempboxa{\if at RTL\beginR\fi#1{#2: }#3\if at RTL\endR\fi}%
    \ifdim\wd\@tempboxa>\hsize
      #1{#2: }#3%
    \else
      \hbox to\hsize{\hfil\box\@tempboxa\hfil}%
    \fi
    \endgraf\vskip\baselineskip}%
  \hss}}}

\def\longtable{\if at RTL\global\@RTLtabtrue\fi%
  \par
  \ifx\multicols\@undefined
  \else
     \ifnum\col at number>\@ne
       \@twocolumntrue
     \fi
  \fi
  \if at twocolumn
    \LT at err{longtable not in 1-column mode}\@ehc
  \fi
  \begingroup \if at RTLtab\beginR \fi
  \@ifnextchar[\LT at array{\LT at array[x]}}

\def\LT at array[#1]#2{%
  \refstepcounter{table}\stepcounter{LT at tables}%
  \if l#1%
    \LTleft\z@ \LTright\fill
  \else\if r#1%
    \LTleft\fill \LTright\z@
  \else\if c#1%
    \LTleft\fill \LTright\fill
  \fi\fi\fi
  \let\LT at mcol\multicolumn
  \let\LT@@tabarray\@tabarray
  \let\LT@@hl\hline
  \def\@tabarray{%
    \let\hline\LT@@hl
    \LT@@tabarray}%
  \let\\\LT at tabularcr\let\tabularnewline\\%
  \def\newpage{\noalign{\break}}%
  \def\pagebreak{\noalign{\ifnum`}=0\fi\@testopt{\LT at no@pgbk-}4}%
  \def\nopagebreak{\noalign{\ifnum`}=0\fi\@testopt\LT at no@pgbk4}%
  \let\hline\LT at hline \let\kill\LT at kill\let\caption\LT at caption
  \@tempdima\ht\strutbox
  \let\@endpbox\LT at endpbox
  \ifx\extrarowheight\@undefined
    \let\@acol\@tabacol
    \let\@classz\@tabclassz \let\@classiv\@tabclassiv
    \def\@startpbox{\vtop\LT at startpbox}%
    \let\@@startpbox\@startpbox
    \let\@@endpbox\@endpbox
    \let\LT at LL@FM at cr\@tabularcr
  \else
    \advance\@tempdima\extrarowheight
    \col at sep\tabcolsep
    \let\@startpbox\LT at startpbox\let\LT at LL@FM at cr\@arraycr
  \fi
  \setbox\@arstrutbox\hbox{\vrule
    \@height \arraystretch \@tempdima
    \@depth \arraystretch \dp \strutbox
    \@width \z@}%
  \let\@sharp##\let\protect\relax
   \begingroup
    \@mkpream{#2}%
    \xdef\LT at bchunk{%
       \global\advance\c at LT@chunks\@ne
       \global\LT at rows\z@\setbox\z@\vbox\bgroup
       \LT at setprevdepth
       \tabskip\LTleft \noexpand\halign to\hsize\bgroup
      \tabskip\z@ \@arstrut \@preamble \tabskip\LTright \cr}%
  \endgroup
  \expandafter\LT at nofcols\LT at bchunk&\LT at nofcols
  \LT at make@row
  \m at th\let\par\@empty
  \everycr{}\lineskip\z@\baselineskip\z@
  \if at RTLtab\hbox\bgroup\beginR\vbox\bgroup\fi
  \LT at bchunk}


\def\endlongtable{%
  \crcr
  \noalign{%
    \let\LT at entry\LT at entry@chop
    \xdef\LT at save@row{\LT at save@row}}%
  \LT at echunk
  \LT at start
  \unvbox\z@
  \LT at get@widths
  \if at filesw
    {\let\LT at entry\LT at entry@write\immediate\write\@auxout{%
      \gdef\expandafter\noexpand
        \csname LT@\romannumeral\c at LT@tables\endcsname
          {\LT at save@row}}}%
  \fi
  \ifx\LT at save@row\LT@@save at row
  \else
    \LT at warn{Column \@width s have changed\MessageBreak
             in table \thetable}%
    \LT at final@warn
  \fi
  \endgraf\penalty -\LT at end@pen
  \egroup\if at RTLtab\endR\egroup\fi
   \if at RTLtab\endR\fi \endgroup
  \global\@mparbottom\z@
  \pagegoal\vsize
  \endgraf\penalty\z@\addvspace\LTpost
  \ifvoid\footins\else\insert\footins{}\fi
   \global\@RTLtabfalse}
}{}

\@ifpackageloaded{tabls}{%

\def\endtabular{\endarray $\if at RTLtab\endR\fi\egroup
                 \global\@RTLtabfalse}

\expandafter\let\csname endtabular*\endcsname=\endtabular

\def\endarray{\ifvmode\csname crcr\endcsname % just do \crcr if \\ given
  \else \\[\z@ \global\advance\@arstdepth-\@otarlinesep]% 
  \fi\egroup\if at RTLtab\egroup\endR\egroup\fi\@unrecurse\egroup}

\def\@array[#1]#2{%  remember global variables to allow recursion:
 \edef\@unrecurse{\global\@skip at bove\the\@skip at bove
     \global\@arstheight\the\@arstheight\global\@arstdepth\the\@arstdepth}%
%  Make the strut on the first line be shorter by the linesep outside
 \let\@otarlinesep\@tarlinesep \global\@skip at bove-\@otarlinesep
%  This setup works for both tabular and array because of this test:
 \ifx\@classz\@arrayclassz \let\@tarlinesep\arraylinesep
 \else \let\@tarlinesep\tablinesep \fi
 \divide\@tarlinesep\tw@ % half sep is applied to height & depth
 \let\@seesize\relax \let\@rememsize\relax \@mkpream{#2}%
 \@tempdima\arraystretch\ht\strutbox \@tempdimb\arraystretch\dp\strutbox
 \ifdim\@tarlinesep>\z@ % (need \protect for \multicolumn)
   \def\@rememsize{\protect\@r at m@msize}\let\@seesize\@s@@size
   \advance\@tempdima-\@tarlinesep \advance\@tempdimb-\@tarlinesep
 \fi \setbox\@arstrutbox\hbox{% set up smaller strut
    \vrule \@height\@tempdima \@depth\@tempdimb \@width\z@}%
 \let\protect\noexpand
 \edef\@preamble{\ialign \noexpand\@halignto \bgroup
 \unhcopy\@arstrutbox \@preamble \tabskip\z at skip &\@sharp \cr}%
% I have added an extra column (&\@sharp) to take the smart strut.
 \let\@startpbox\@@startpbox \let\@endpbox\@@endpbox
 \if#1t\vtop \else \if#1b\vbox \else \vcenter \fi\fi
 \bgroup \let\par\@empty
 \global\@arstheight\ht\@arstrutbox \global\@arstdepth\dp\@arstrutbox
 \advance\extrarulesep.5\arrayrulewidth
 \let\@sharp##\let\protect\relax \lineskip\z at skip \baselineskip\z at skip
 \if at RTLtab\hbox\bgroup\beginR\vbox\bgroup\fi
 \@preamble}
}{}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

And I have attached the tex file and pdf output of an example of longtable.sty, so you can see the issue clearly.

_________________________________________________________________
Want to stay on top of your life online? Find out how with Windows Live!
http://windowslive.ninemsn.com.au/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://tug.org/pipermail/xetex/attachments/20090512/4e2fd194/attachment-0001.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.tex
Type: application/x-tex
Size: 3010 bytes
Desc: not available
Url : http://tug.org/pipermail/xetex/attachments/20090512/4e2fd194/attachment-0001.tex 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.pdf
Type: application/pdf
Size: 51024 bytes
Desc: not available
Url : http://tug.org/pipermail/xetex/attachments/20090512/4e2fd194/attachment-0001.pdf 


More information about the XeTeX mailing list