summaryrefslogtreecommitdiff
path: root/macros/luatex/latex/luabidi/tex/luabidi.sty
blob: 4277a1f1738338e525259ef9e2bc51dfe5bacdad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
%% This file is luabidi.sty
%% This is part of the luabidi package
%%
%% Copyright © 2009 Vafa Khalighi, 2013--2019 Arthur Reutenauer, 2019 Jürgen Spitzmüller
%%
%%%% It may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3c
%% of this license or (at your option) any later version.
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{luabidi}[2019/10/27 v0.5
	Bidirectional typesetting in LuaTeX]

\RequirePackage{etoolbox}

%
% Package options
%

\DeclareOption{arabmaths}{\input{luabidi-arabmaths.def}}
\newif\ifluabidi@autofootnoterule
\DeclareOption{autofootnoterule}{\luabidi@autofootnoteruletrue}
\newif\ifluabidi@textwidthfootnoterule
\DeclareOption{textwidthfootnoterule}{\luabidi@textwidthfootnoteruletrue}
\ProcessOptions

%
% General command and switches
%

\newif\if@RTL
\newif\if@RTLmain
\@RTLmainfalse
\def\setRTLmain{\@RTLmaintrue\pagedir TRT \bodydir TRT \pardir TRT \textdir TRT}
\def\setRTL{\@RTLtrue\pardir TRT \textdir TRT}
\let\setRL=\setRTL
\def\setLTR{\@RTLfalse\pardir TLT \textdir TLT}
\let\setLR=\setLTR
\let\unsetRTL=\setLTR
\let\unsetLTR=\setRTL
\def\RTL{\@RTLtrue\trivlist \pardir TRT \textdir TRT\item\relax}
\def\endRTL{\@RTLfalse\endtrivlist}
\def\LTR{\trivlist \pardir TLT \textdir TLT\item\relax}
\def\endLTR{\endtrivlist}
\def\@ensure@RTL#1{\if@RTL#1\else\RLE{#1}\fi}
\def\@ensure@LTR#1{\if@RTL\LRE{#1}\else{#1}\fi}
\def\@ensure@dir#1{\if@RTL\RLE{#1}\else{#1}\fi}
\let\@ensure@maindir=\@ensuredir
\let\n@xt=\
\DeclareRobustCommand*\LRE{\protect\pLRE}
\def\pLRE{\protect\afterassignment\moreLRE \let\n@xt= }
\DeclareRobustCommand*\RLE{\protect\pRLE}
\def\pRLE{\protect\afterassignment\moreRLE \let\n@xt= }
\def\bracetext{\ifcat\n@xt{\else\ifcat\n@xt}\fi
  \errmessage{Missing left brace has been substituted}\fi \bgroup}
\def\moreLRE{\bracetext \aftergroup\unsetLTR \setLTR\@RTLfalse}
\def\moreRLE{\bracetext \aftergroup\unsetRTL \setRTL\@RTLtrue}
\let\LR=\LRE
\let\RL=\RLE
\def\hboxR#1{\hbox{\RL{#1}}}

%
% Footnotes
%

\input{luabidi-footnotes.def}

\ifluabidi@textwidthfootnoterule
   \textwidthfootnoterule
\fi

% This needs to be loaded late because of the switch
\AtEndPreamble{%
  \makeatletter
     \ifluabidi@autofootnoterule
         \input{luabidi-autofootnoterule.def}
     \fi
  \makeatother
}

\endinput