[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
\global\@RTLtabfalse
\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}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


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?

Thanks
-------------- 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