[texhax] Hacking longtable.sty

Vafa Khalighi vafak9 at gmail.com
Mon May 11 15:39:50 CEST 2009

Hello Today I wrote a hack for longtable.sty that it actually makes
longtable typeset RTL tables which means it can typeset columns from right
to left and each entry in the cell will be written from right to left. This
is done by assuming only \beginR, and \endR primitives. This is my code

\newif\if at RTLtab
\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}%
      #1{#2: }#3%
      \hbox to\hsize{\hfil\box\@tempboxa\hfil}%

\def\longtable{\if at RTL\global\@RTLtabtrue\fi%
     \ifnum\col at number>\@ne
  \if at twocolumn
    \LT at err{longtable not in 1-column mode}\@ehc
  \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
  \let\LT at mcol\multicolumn
  \let\\\LT at tabularcr\let\tabularnewline\\%
  \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
  \let\@endpbox\LT at endpbox
    \let\@classz\@tabclassz \let\@classiv\@tabclassiv
    \def\@startpbox{\vtop\LT at startpbox}%
    \let\LT at LL@FM at cr\@tabularcr
    \col at sep\tabcolsep
    \let\@startpbox\LT at startpbox\let\LT at LL@FM at cr\@arraycr
    \@height \arraystretch \@tempdima
    \@depth \arraystretch \dp \strutbox
    \@width \z@}%
    \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}%
  \expandafter\LT at nofcols\LT at bchunk&\LT at nofcols
  \LT at make@row
  \m at th\let\par\@empty
  \if at RTLtab\hbox\bgroup\beginR\vbox\bgroup\fi
  \LT at bchunk}

    \let\LT at entry\LT at entry@chop
    \xdef\LT at save@row{\LT at save@row}}%
  \LT at echunk
  \LT at start
  \LT at get@widths
  \if at filesw
    {\let\LT at entry\LT at entry@write\immediate\write\@auxout{%
        \csname LT@\romannumeral\c at LT@tables\endcsname
          {\LT at save@row}}}%
  \ifx\LT at save@row\LT@@save at row
    \LT at warn{Column \@width s have changed\MessageBreak
             in table \thetable}%
    \LT at final@warn
  \endgraf\penalty -\LT at end@pen
  \egroup\if at RTLtab\endR\egroup\fi
   \if at RTLtab\endR\fi \endgroup

Now this code makes longtable.sty typeset tables from right to left. But it
unfortunately does not make longtable to break table when a page is
finished. For eaxmple I have attached a tex file and its pdf output.

Can you please tell me how can I solve the issue?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://tug.org/pipermail/texhax/attachments/20090511/c2d5e271/attachment-0001.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.tex
Type: application/x-tex
Size: 3009 bytes
Desc: not available
Url : http://tug.org/pipermail/texhax/attachments/20090511/c2d5e271/attachment-0001.tex 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.pdf
Type: application/pdf
Size: 51023 bytes
Desc: not available
Url : http://tug.org/pipermail/texhax/attachments/20090511/c2d5e271/attachment-0001.pdf 

More information about the texhax mailing list