diff options
author | Karl Berry <karl@freefriends.org> | 2008-07-12 18:30:08 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2008-07-12 18:30:08 +0000 |
commit | d5bd2061a0757def2c259852e8b45958b1a5183d (patch) | |
tree | abae9af20fe628c6a63b3ae941d4feb874f52d85 /Master/texmf-dist/tex/xelatex | |
parent | 9bca6550cfe2de5380ebe394480ccb24126f2863 (diff) |
bidi update (11jul08)
git-svn-id: svn://tug.org/texlive/trunk@9486 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/xelatex')
-rw-r--r-- | Master/texmf-dist/tex/xelatex/bidi/bidi.sty | 384 |
1 files changed, 236 insertions, 148 deletions
diff --git a/Master/texmf-dist/tex/xelatex/bidi/bidi.sty b/Master/texmf-dist/tex/xelatex/bidi/bidi.sty index 7ac709c9eaf..2ffa7b5c828 100644 --- a/Master/texmf-dist/tex/xelatex/bidi/bidi.sty +++ b/Master/texmf-dist/tex/xelatex/bidi/bidi.sty @@ -7,15 +7,18 @@ %% bidi.dtx (with options: `package') %% %% ____________________________ +%% %% The bidi package -%% (C) 2007 François Charette +%% (C) 2007-2008 François Charette %% License information appended %% -%% -%% \section{Implementation} \NeedsTeXFormat{LaTeX2e} \ProvidesPackage{bidi} - [2007/04/30 v0.2.2 Bidirectional typesetting in XeLaTeX] + [2008/07/07 v0.3 Bidirectional typesetting in XeLaTeX] +\newif\if@rlmain +\@rlmainfalse +\DeclareOption{rldocument}{\@rlmaintrue} +\ProcessOptions %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \ifx\TeXXeTstate\undefined\else% \TeXXeTstate=1 @@ -28,6 +31,13 @@ engine}% \fi \newif\if@rl +\AtBeginDocument{% Here we set the main document direction + \if@rlmain\else + \if@rl\@rlmaintrue% + \else\@rlmainfalse% + \fi% + \fi% +} \let\n@xt=\ \def\LR{\protect\pLR}% \def\pLR{\protect\afterassignment\moreLR \let\n@xt= } @@ -46,16 +56,27 @@ \let\everypar=\n@everypar \def\@ensure@RL#1{\if@rl#1\else\RL{#1}\fi} \def\@ensure@LR#1{\if@rl\LR{#1}\else#1\fi} +\def\@ensure@dir#1{\if@rl\RL{#1}\else{#1}\fi} +\def\@ensure@maindir#1{\if@rlmain\RL{#1}\else{#1}\fi} +\def\@@RL{RL} +\def\@@LR{LR} +\def\save@dir{\if@rl\gdef\saved@@dir{RL}\else\gdef\saved@@dir{LR}\fi} +\def\reset@dir{\ifx\saved@@dir\@@RL\setRL\else\ifx\saved@@dir\@@LR\setLR\else\relax\fi\fi} \let\@@TeX\TeX -\def\TeX{\LR{\@@TeX}} +\def\TeX{\@ensure@LR{\@@TeX}} \let\@@LaTeX\LaTeX -\def\LaTeX{\LR{\@@LaTeX}} +\def\LaTeX{\@ensure@LR{\@@LaTeX}} \let\@@LaTeXe\LaTeXe -\def\LaTeXe{\LR{\@@LaTeXe}} +\def\LaTeXe{\@ensure@LR{\@@LaTeXe}} \@ifpackageloaded{xltxtra}{ \let\@@XeTeX\XeTeX -\def\XeTeX{\LR{\@@XeTeX}} +\def\XeTeX{\@ensure@LR{\@@XeTeX}} +\let\@@XeLaTeX\XeLaTeX +\def\XeLaTeX{\@ensure@LR{\@@XeLaTeX}} }{} +\@ifundefined{text}{}{% +\let\t@xt=\text +\def\text#1{\t@xt{\@ensure@dir{#1}}}} \def\list#1#2{% \ifnum \@listdepth >5\relax \@toodeep @@ -82,7 +103,6 @@ \fi \parshape \@ne \@totalleftmargin \linewidth \ignorespaces} -%% \def\@dottedtocline#1#2#3#4#5{% \ifnum #1>\c@tocdepth \else \vskip \z@ \@plus.2\p@ @@ -103,7 +123,6 @@ \hb@xt@\@pnumwidth{\hfil\normalfont \normalcolor \beginL#5\endL}% \par}% \fi} -%% \def\raggedright{% \let\\\@centercr \leftskip\z@skip\rightskip\@flushglue @@ -119,15 +138,51 @@ \if@compatibility \let\undertext=\underline \fi +\let\lr@outputdblcol\@outputdblcol +\renewcommand{\@outputdblcol}{% + \if@rlmain% + \rl@outputdblcol% + \else% + \lr@outputdblcol% + \fi% +} +\newcommand{\rl@outputdblcol}{% + \if@firstcolumn + \global \@firstcolumnfalse + \global \setbox\@leftcolumn \box\@outputbox + \else + \global \@firstcolumntrue + \setbox\@outputbox \vbox {\hb@xt@\textwidth {% + \hskip\columnwidth% + \hfil\vrule\@width\columnseprule\hfil + \hb@xt@\columnwidth {% + \box\@leftcolumn \hss}% + \hb@xt@\columnwidth {% + \hskip-\textwidth% + \box\@outputbox \hss}% + \hskip\columnsep% + \hskip\columnwidth}}% + \@combinedblfloats + \@outputpage + \begingroup + \@dblfloatplacement + \@startdblcolumn + \@whilesw\if@fcolmade \fi + {\@outputpage + \@startdblcolumn}% + \endgroup + \fi} + \newif\if@rl@footnote -\if@rl\@rl@footnotetrue\else\@rl@footnotefalse\fi +\if@rlmain\@rl@footnotetrue\else\@rl@footnotefalse\fi \let\@@footnoterule=\footnoterule \def\LRfootnoterule{\@@footnoterule} +%%bug?-->this causes new par to be set, hence hack with vskip :-{ \def\RLfootnoterule{\vskip -\baselineskip\hb@xt@\hsize{\hss\vbox{\@@footnoterule}}} \def\setfootnoteRL{\@rl@footnotetrue} \def\unsetfootnoteRL{\@rl@footnotefalse} \def\setfootnoteLR{\unsetfootnoteRL} -\def\footnoterule{\if@rl@footnote\RLfootnoterule\else\LRfootnoterule\fi} +\def\footnoterule{\if@rlmain\RLfootnoterule\else\LRfootnoterule\fi} \def\setRL{\@rltrue\@rl@footnotetrue} \def\unsetRL{\@rlfalse\@rl@footnotefalse} \def\setLR{\unsetRL} @@ -145,6 +200,7 @@ \@makefntext{% \rule\z@\footnotesep\ignorespaces#1\@finalstrut\strutbox}% \color@endgroup}}% +%%... also in minipages \long\def\@mpfootnotetext#1{% \global\setbox\@mpfootins\vbox{% \if@rl@footnote\@rltrue\else\@rlfalse\fi @@ -159,6 +215,128 @@ \rule\z@\footnotesep\ignorespaces#1\@finalstrut\strutbox}% \color@endgroup }} +\@ifundefined{KOMAClassName}{% +\@ifclassloaded{memoir}{% +\long\def\@makecaption#1#2{\let\@memtempa\relax + \ifdim\prevdepth>-99\p@ \vskip\abovecaptionskip + \else \def\@memtempa{\vbox to\topskip{}}\fi + \let\@contfnote\footnote \renewcommand{\footnote}[2][]{} + \let\@contfmark\footnotemark \renewcommand{\footnotemark}[1][]{} + \sbox\@tempboxa{\@contnfont #1\@contdelim \@conttfont #2} + \let\footnote\@contfnote + \let\footnotemark\@contfmark + \ifdim\wd\@tempboxa<\linewidth \centering \fi + \if@contcw + \centering + \parbox{\@contcwidth}{% + \ifdim\wd\@tempboxa<\@contcwidth \centering \fi + \fi + \if@conthang + \sbox\@tempboxa{\@contnfont #1\@contdelim} + \@contpre% + \@ensure@dir{\@contcstyle\hangindent=\wd\@tempboxa + \noindent\box\@tempboxa\@memtempa \@conttfont #2}\par + \else + \if@contindent + \@contpre% + \@ensure@dir{\@contnfont #1\@contdelim}\@memtempa + \@ensure@dir{\@contcstyle\hangindent=\@contindw + \hangafter=\@ne\@conttfont #2}\par% <- v1.4 + \else + \@contpre% + \@ensure@dir{\@contnfont #1\@contdelim}\@memtempa + \@ensure@dir{\ifdim\wd\@tempboxa<\linewidth + \@contcshortstyle\else \@contcstyle\fi% <- v1.4 + \@conttfont #2}\par + \fi + \fi + \@contpost + \if@contcw + \par + } % end of the \parbox + \fi + \vskip\belowcaptionskip} +}% else we redefine \@makecaption for the standard classes +{\@ifundefined{@makecaption}{% +}{\long\def\@makecaption#1#2{% + \vskip\abovecaptionskip + \sbox\@tempboxa{\@ensure@dir{#1: #2}}% + \ifdim \wd\@tempboxa >\hsize + \@ensure@dir{#1: #2}\par + \else + \global \@minipagefalse + \hb@xt@\hsize{\hfil\box\@tempboxa\hfil}% + \fi + \vskip\belowcaptionskip}% + }% + }% +}% ELSE KOMASCRIPT +{\@ifclassloaded{scrlttr2}{}% do nothing for letter class +{\renewcommand{\@@makecaption}[3]{% + \cap@margin + \ifonelinecaptions + \@tempcnta=\value{mpfootnote}\@tempcntb=\value{footnote}% + \let\scr@tmp@footnotetext=\@footnotetext + \let\@footnotetext=\@gobble + \sbox\@tempboxa{% + {\capfont\strut\ignorespaces + #1{{\caplabelfont#2\captionformat}}% + #3\unskip\strut}% + }% + \let\@footnotetext=\scr@tmp@footnotetext + \let\scr@tmp@footnotetext=\undefined + \setcounter{footnote}{\@tempcntb}% + \setcounter{mpfootnote}{\@tempcnta}% + \else + \sbox\@tempboxa{\hspace*{2\cap@width}}% + \fi + \begingroup% + \setlength{\@tempdima}{\cap@width}% + \ifdim \wd\@tempboxa >\@tempdima + \hb@xt@\hsize{% + \setbox\@tempboxa\vbox{\hsize=\cap@width + \ifdofullc@p + \@ensure@dir{\capfont\@hangfrom{\scr@smashdp{\strut\ignorespaces + #1{{\caplabelfont#2\captionformat}}}}% + {#3\unskip\strut\par}}% + \else% + \ifdim\cap@indent<\z@ + \@ensure@dir{\capfont\strut\ignorespaces + #1{{\caplabelfont #2\captionformat\par}}% + \noindent\hspace*{-\cap@indent}#3\unskip\strut\par}% + \else% + \if@capbreak + \@ensure@dir{\capfont\strut\ignorespaces + #1{{\caplabelfont #2\captionformat\par}}% + \noindent\@hangfrom{\hspace*{\cap@indent}}{#3\par}}% + \else + \@ensure@dir{\capfont\@hangfrom{\scr@smashdp\strut\hspace*{\cap@indent}}% + {\hspace{-\cap@indent}\scr@smashdp{\ignorespaces#1% + {{\caplabelfont#2\captionformat}}}#3\unskip\strut\par}}% + \fi + \fi + \fi + }% + \setlength{\@tempdima}{\ht\@tempboxa}% + \addtolength{\@tempdima}{\dp\@tempboxa}% + \addtolength{\@tempdima}{-\ht\strutbox}% + \ht\@tempboxa\ht\strutbox + \dp\@tempboxa\@tempdima + \strut\cap@left + \box\@tempboxa + \cap@right\strut +}% + \else + \global \@minipagefalse + \sbox\@tempboxa{% + \@ensure@dir{\capfont\scr@smashdp{\strut\ignorespaces + #1{{\caplabelfont#2\captionformat}}}% + #3}% + }% + \hb@xt@\hsize{\strut\cap@left\box\@tempboxa\cap@right\strut}% + \fi + \endgroup} +}}% \ifx\@textcolor\@undefined\else% \AtBeginDocument{% \def\@textcolor#1#2#3{% @@ -172,144 +350,54 @@ }% }% \fi -%%% -\def\abjad#1{% -\ifnum#1>1999 \PackageWarning{bidi}{Illegal value (#1) for abjad numeral} {#1} -\else - \ifnum#1<\z@\space\PackageWarning{bidi}{Illegal value (#1) for abjad numeral}% - \else - \ifnum#1<10\expandafter\abj@num@i\number#1% - \else - \ifnum#1<100\expandafter\abj@num@ii\number#1% - \else - \ifnum#1<\@m\expandafter\abj@num@iii\number#1% - \else - \ifnum#1<\@M\expandafter\abj@num@iv\number#1%since #1<2000, we must have 1000 - \fi - \fi - \fi - \fi - \fi -\fi -} - -\def\abjadmaghribi#1{% -\ifnum#1>1999 \PackageWarning{bidi}{Illegal value (#1) for abjad numeral} {#1} -\else - \ifnum#1<\z@\space\PackageWarning{bidi}{Illegal value (#1) for abjad numeral}% - \else - \ifnum#1<10\expandafter\abj@num@i\number#1% - \else - \ifnum#1<100\expandafter\abj@maghribi@num@ii\number#1% - \else - \ifnum#1<\@m\expandafter\abj@maghribi@num@iii\number#1% - \else - \ifnum#1<\@M\expandafter\abj@maghribi@num@iv\number#1% - \fi - \fi - \fi - \fi - \fi -\fi -} - -\def\hebrewnumeral#1{% -\ifnum#1>9999 \PackageWarning{bidi}{Illegal value (#1) for Hebrew numeral} {#1} -\else - \ifnum#1<\z@\space\PackageWarning{bidi}{Illegal value (#1) for Hebrew numeral}% - \else - \ifnum#1<10\expandafter\heb@num@i\number#1% - \else - \ifnum#1<100\expandafter\heb@num@ii\number#1% - \else - \ifnum#1<\@m\expandafter\heb@num@iii\number#1% - \else - \ifnum#1<\@M\expandafter\heb@num@iv\number#1% - \fi - \fi - \fi - \fi - \fi -\fi -} - -\def\abjadsyriac#1{% -\ifnum#1>499 \PackageWarning{bidi}{Illegal value (#1) for Syriac abjad numeral} {#1} -\else - \ifnum#1<\z@\space\PackageWarning{bidi}{Illegal value (#1) for Syriac abjad numeral}% - \else - \ifnum#1<10\expandafter\abj@syr@num@i\number#1% - \else - \ifnum#1<100\expandafter\abj@syr@num@ii\number#1% - \else - \expandafter\abj@syr@num@iii\number#1% - \fi - \fi - \fi -\fi +\newif\if@tab@rl +\if@rlmain\@tab@rltrue\else\@tab@rlfalse\fi +\@ifpackageloaded{array}% +{\PackageWarningNoLine{bidi}{% + You are using the package array (or the memoir class). ^^J + Unfortunately right-to-left tabular environments are not ^^J + yet supported with the array package.} +\let\@uthor=\author +\def\author#1{\@uthor{\@ensure@dir{#1}}} +}% +{% ELSE DEFAULT LATEX MACROS +\def\@tabular{% + \if@rl\global\@tab@rltrue\fi + \leavevmode \hbox \bgroup \if@tab@rl\beginR\fi + $\let\@acol\@tabacol + \let\@classz\@tabclassz + \let\@classiv\@tabclassiv \let\\\@tabularcr\@tabarray} +\def\endtabular{\crcr\egroup\if@tab@rl\egroup\endR\egroup\fi + \egroup $\if@tab@rl\endR\fi \egroup}% +\def\@array[#1]#2{\setbox\@arstrutbox=\hbox{\vrule + height\arraystretch \ht\strutbox + depth\arraystretch \dp\strutbox + width\z@}\@mkpream{#2}\edef\@preamble{% +\halign \noexpand\@halignto +\bgroup \tabskip\z@ \@arstrut \@preamble \tabskip\z@ \cr}% +\let\@startpbox\@@startpbox \let\@endpbox\@@endpbox +\if #1t\vtop \else \if#1b\vbox \else \vcenter \fi\fi +\bgroup \let\par\relax +\let\@sharp##\let\protect\relax \lineskip\z@\baselineskip\z@ +\if@tab@rl\hbox\bgroup\beginR\vbox\bgroup\fi +\@preamble} } -\def\abjad@zero{} -\def\hebnum@zero{} -\def\syriac@zero{} -\def\abj@num@i#1{% - \ifcase#1\or\char"0627 \or\char"0628 \or\char"062C \char"200D\or\char"062F % - \or\char"0647 \or\char"0648 \or\char"0632 \or\char"062D \or\char"0637 \fi - \ifnum#1=\z@\abjad@zero\fi} -\def\abj@num@ii#1{% - \ifcase#1\or\char"064A \or\char"0643 \or\char"0644 \or\char"0645 \or\char"0646 % - \or\char"0633 \or\char"0639 \or\char"0641 \or\char"0635 \fi - \ifnum#1=\z@\fi\abj@num@i} -\def\abj@num@iii#1{% - \ifcase#1\or\char"0642 \or\char"0631 \or\char"0634 \or\char"062A \or\char"062B % - \or\char"062E \or\char"0630 \or\char"0636 \or\char"0638 \fi - \ifnum#1=\z@\fi\abj@num@ii} -\def\abj@num@iv#1{% - \ifcase#1\or\char"063A \fi - \ifnum#1=\z@\fi\abj@num@iii} - -\def\abj@maghribi@num@ii#1{% - \ifcase#1\or\char"064A \or\char"0643 \or\char"0644 \or\char"0645 \or\char"0646 % - \or\char"0635 \or\char"0639 \or\char"0641 \or\char"0636 \fi - \ifnum#1=\z@\abjad@zero\fi\abj@num@i} -\def\abj@maghribi@num@iii#1{% - \ifcase#1\or\char"0642 \or\char"0631 \or\char"0633 \or\char"062A \or\char"062B % - \or\char"062E \or\char"0630 \or\char"0638 \or\char"063A \fi - \ifnum#1=\z@\fi\abj@maghribi@num@ii} -\def\abj@maghribi@num@iv#1{% - \ifcase#1\or\char"0634 \fi - \ifnum#1=\z@\fi\abj@maghribi@num@iii} - -\def\heb@num@i#1{% - \ifcase#1\or\char"05D0 \or\char"05D1 \or\char"05D2 \or\char"05D3 \or\char"05D4 % - \or\char"05D5 \or\char"05D6 \or\char"05D7 \or\char"05D8 \fi - \ifnum#1=\z@\hebnum@zero\fi} -\def\heb@num@ii#1{% - \ifcase#1\or\char"05D9 \or\char"05DB \or\char"05DC \or\char"05DE \or\char"05E0 % - \or\char"05E1 \or\char"05E2 \or\char"05E4 \or\char"05E6 \fi - \ifnum#1=\z@\fi\heb@num@i} -\def\heb@num@iii#1{% - \ifcase#1\or\char"05E7 \or\char"05E8 \or\char"05E9 \or\char"05EA \or\char"05DA % - \or\char"05DD \or\char"05DF \or\char"05E3 \or\char"05E5 \fi - \ifnum#1=\z@\fi\heb@num@ii} -\def\heb@num@iv#1{% - \ifcase#1\or\char"05D0\char"05F3 \or\char"05D1\char"05F3 \or\char"05D2\char"05F3 % - \or\char"05D3\char"05F3 \or\char"05D4\char"05F3 \or\char"05D5\char"05F3 % - \or\char"05D6\char"05F3 \or\char"05D7\char"05F3 \or\char"05D8\char"05F3 \fi - \ifnum#1=\z@\fi\heb@num@iii} - -\def\abj@syr@num@i#1{% - \ifcase#1\or\char"0710 \or\char"0712 \or\char"0713 \or\char"0715 % - \or\char"0717 \or\char"0718 \or\char"0719 \or\char"071A \or\char"071B\fi - \ifnum#1=\z@\syriac@zero\fi} -\def\abj@syr@num@ii#1{% - \ifcase#1\or\char"071D \or\char"071F \or\char"0720 \or\char"0721 \or\char"0722 % - \or\char"0723 \or\char"0725 \or\char"0726 \or\char"0728 \fi - \ifnum#1=\z@\fi\abj@syr@num@i} -\def\abj@syr@num@iii#1{% - \ifcase#1\or\char"0729 \or\char"072A \or\char"072B \or\char"072C \fi - \ifnum#1=\z@\fi\abj@syr@num@ii} +\def\@open@paren{\if@rlmain)\else(\fi} +\def\@close@paren{\if@rlmain(\else)\fi} +\def\tagform@#1{\maketag@@@{\@open@paren\ignorespaces#1\unskip\@@italiccorr\@close@paren}} +%% Make these Unicode chars active and define them so that they work +%% in conformance to the Unicode bidi algorithm! +%% \catcode"200E=\active +%% \catcode"200F=\active +%% \def{\setLR} +%% \def{\setRL} +%% 202A -> {\@ensure@LR\bgroup} ? or \LR +%% 202B -> {\@ensure@RL\bgroup} ? or \RL +%% 202C -> {\egroup} ? or \if@rl\@rlfalse\else\@rltrue\fi ? +%% 202D -> {?} %LRO +%% 202E -> {?} %RLO %% -%% Copyright (C) 2007 by François Charette <firmicus at gmx dot net> +%% Copyright (C) 2007-2008 by François Charette <firmicus at gmx dot net> %% %% Distributable under the LaTeX Project Public License, %% version 1.3c or higher (your choice). The latest version of |