summaryrefslogtreecommitdiff
path: root/macros/luatex/latex/luabidi
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2019-10-29 03:00:39 +0000
committerNorbert Preining <norbert@preining.info>2019-10-29 03:00:39 +0000
commit97f5151099967e6c823d640a90d87bca92c44035 (patch)
tree685caa49488599f87d0caa4e972833b2263d8567 /macros/luatex/latex/luabidi
parent25a647b97ef526aefcc75269dd19c46dbe3ae4c1 (diff)
CTAN sync 201910290300
Diffstat (limited to 'macros/luatex/latex/luabidi')
-rw-r--r--macros/luatex/latex/luabidi/doc/luabidi-test-arabmaths.tex (renamed from macros/luatex/latex/luabidi/doc/test.tex)0
-rw-r--r--macros/luatex/latex/luabidi/doc/luabidi.pdfbin0 -> 91872 bytes
-rw-r--r--macros/luatex/latex/luabidi/doc/luabidi.tex237
-rw-r--r--macros/luatex/latex/luabidi/tex/arabmaths.tex2
-rw-r--r--macros/luatex/latex/luabidi/tex/autofootnoterule.tex116
-rw-r--r--macros/luatex/latex/luabidi/tex/luabidi-arabmaths.def11
-rw-r--r--macros/luatex/latex/luabidi/tex/luabidi-autofootnoterule.def72
-rw-r--r--macros/luatex/latex/luabidi/tex/luabidi-footnotes.def76
-rw-r--r--macros/luatex/latex/luabidi/tex/luabidi.sty52
-rw-r--r--macros/luatex/latex/luabidi/tex/textwidthfootnoterule.tex2
10 files changed, 434 insertions, 134 deletions
diff --git a/macros/luatex/latex/luabidi/doc/test.tex b/macros/luatex/latex/luabidi/doc/luabidi-test-arabmaths.tex
index 1b51109ad4..1b51109ad4 100644
--- a/macros/luatex/latex/luabidi/doc/test.tex
+++ b/macros/luatex/latex/luabidi/doc/luabidi-test-arabmaths.tex
diff --git a/macros/luatex/latex/luabidi/doc/luabidi.pdf b/macros/luatex/latex/luabidi/doc/luabidi.pdf
new file mode 100644
index 0000000000..8e31b11622
--- /dev/null
+++ b/macros/luatex/latex/luabidi/doc/luabidi.pdf
Binary files differ
diff --git a/macros/luatex/latex/luabidi/doc/luabidi.tex b/macros/luatex/latex/luabidi/doc/luabidi.tex
new file mode 100644
index 0000000000..3dc17fe720
--- /dev/null
+++ b/macros/luatex/latex/luabidi/doc/luabidi.tex
@@ -0,0 +1,237 @@
+% !TeX spellcheck = en_US
+% !TeX TS-program = lualatex
+\documentclass[11pt]{ltxdoc}
+\usepackage{color}
+\usepackage{xspace,fancyvrb,booktabs}
+\usepackage[neverdecrease]{paralist}
+\definecolor{myblue}{rgb}{0.02,0.04,0.48}
+\definecolor{lightblue}{rgb}{0.61,.8,.8}
+\definecolor{myred}{rgb}{0.65,0.04,0.07}
+\usepackage[
+unicode=true,
+bookmarks=true,
+colorlinks=true,
+linkcolor=myblue,
+urlcolor=myblue,
+citecolor=myblue,
+hyperindex=false,
+hyperfootnotes=false,
+pdftitle={luabidi: Bidirectional typesetting in LuaLaTeX},
+pdfauthor={V Khalighi, A Reutenauer, J Spitzmüller},
+pdfkeywords={luatex, lualatex, multilingual, bidi}
+]{hyperref}
+\usepackage{metalogo}
+%\let\XeTeX\undefined
+%\let\XeLaTeX\undefined
+\usepackage{polyglossia}
+\usepackage{luabidi}
+
+\setmainlanguage{english}
+\usepackage[protrusion]{microtype}
+\newcommand*\Cmd[1]{\cmd{#1}\DescribeMacro{#1}\xspace}
+\newcommand*{\cscmd}[1]{\texttt{\textbackslash #1}}
+\newcommand*\pkg[1]{\textsf{\color{myblue}#1}}
+\newcommand*\file[1]{\texttt{\color{myblue}#1}}
+\newcommand*\TR[1]{\textcolor{myred}{#1}}
+\newcommand*\TX[1]{\hyperref[#1]{\textcolor{myred}{#1}}}
+\newcommand*\TB[1]{\textcolor{myblue}{\bf #1}}
+\newcommand*\TA[1]{\textsc{\color{myblue}#1}}
+\newcommand*\link[1]{\href{#1}{#1}}
+\def\eg{\textit{e.g.,}\xspace}
+\def\ie{\textit{i.e.,}\xspace}
+\def\ca{\textit{ca.}\@\xspace}
+\def\Eg{\textit{E.g.,}\xspace}
+\def\Ie{\textit{I.e.,}\xspace}
+\def\etc{\@ifnextchar.{\textit{etc}}{\textit{etc.}\@\xspace}}
+
+%% Sidenotes << copied from fontspec.dtx
+\newcommand\new[1]{%
+ \edef\thisversion{#1}%
+ \ifhmode\unskip~\fi{\ifx\thisversion\fileversion\color{blue}\else\color[gray]{0.5}\fi
+ $\leftarrow$}%
+ \marginpar{\centering
+ \small\ifx\thisversion\fileversion\color{blue}\else\color[gray]{0.5}\fi
+ \textsf{#1}}}
+\newcommand\displaycmd[2]{%
+ \\\DescribeMacro{#2}\centerline{\cmd{#1}}}
+\renewenvironment{itemize}{\begin{compactitem}[\char"2023]}%[{\fontspec{DejaVu Sans}\char"25BB}]}%
+ {\end{compactitem}}
+
+\def\condbreak#1{%
+ \vskip 0pt plus #1\pagebreak[3]\vskip 0pt plus -#1\relax}
+
+\newcommand*\lbd{\pkg{luabidi}}
+\newcommand*\Lbd{\pkg{Luabidi}}
+
+%% fontspec declarations:
+\setmainfont{Linux Libertine O}
+\setsansfont{Linux Biolinum O}
+\setmonofont[Scale=MatchLowercase]{DejaVu Sans Mono}
+
+\linespread{1.05}
+\frenchspacing
+\EnableCrossrefs
+\CodelineIndex
+\RecordChanges
+% COMMENT THE NEXT LINE TO INCLUDE THE CODE
+\AtBeginDocument{\OnlyDescription}
+
+
+\begin{document}
+\hyphenation{Kha-li-ghi Reu-ten-auer}
+\GetFileInfo{luabidi.sty}
+
+\title{\lbd\\\color{myblue}Bidirectional typesetting in \LuaLaTeX}
+
+\date{\color{myblue}\filedate \qquad \fileversion\\
+ \footnotesize (\textsc{pdf} file generated on \today)}
+
+\author{\TA{Vafa Khalighi} \and \TA{Arthur Reutenauer}\thanks{%
+ Current maintainer. Please submit bug reports and feature requests to \protect\url{https://github.com/bidi-tex/luabidi/issues}.}
+ \and \TA{Jürgen Spitzmüller}}
+
+\maketitle
+
+\DeleteShortVerb{\|}
+\MakeShortVerb{\¦}
+
+\tableofcontents
+
+\condbreak{2\baselineskip}
+\section{Objectives}
+\Lbd\ is an attempt to provide bidirectional writing support for the \LuaTeX\ engine in the same vein as the \pkg{bidi} package\footnote{%
+See \url{https://ctan.org/pkg/bidi}.} enables bidirectional writing with \XeTeX. The most prominent user of this package is \pkg{polyglossia}\footnote{%
+See \url{https://ctan.org/pkg/polyglossia}.} which uses \lbd\ with RTL languages and \LuaTeX\ output (as opposed to \pkg{bidi} with \XeTeX). Note, however, that \lbd\ is much more limited than \textsf{bidi}. Currently, only a very basic
+subset of the latter's features is supported.
+
+\section{Package Options}
+
+\begin{description}
+ \item[\TB{arabmaths}] By default, \lbd\ generates left-to-right maths. If you would like to have right-to-left maths, use this option.
+ \item[\TB{textwidthfootnoterule}] expands the footnote rule to the whole text width.
+ \item[\TB{autofootnoterule}] sets the footnote rule right or left aligned, depending on the direction of the first footnote
+ that follows the rule (\ie that comes on the current page).
+\end{description}
+
+\section{User Commands}
+
+\subsection{Main Text Direction}
+
+By default, the main directionality of the document is left-to-right. To change it to right-to-left, use the switch
+
+\begin{quote}
+ \Cmd\setRTLmain
+\end{quote}
+%
+This is advisable if your document consists mainly of right-to-left text.
+
+\subsection{Paragraph Text Direction}
+
+To change directionality for paragraphs, you can use the following switches:
+\begin{description}
+ \item[\cmd{\setRTL}]\DescribeMacro{\setRTL} (alias: \Cmd{\setRL}, \Cmd{\unsetLTR}) changes paragraph direction to right-to-left.
+ \item[\cmd{\setLTR}]\DescribeMacro{\setLTR} (alias: \Cmd{\setLR}, \Cmd{\unsetRTL}) changes paragraph direction to left-to-right.
+\end{description}
+%
+\condbreak{2\baselineskip}
+Alternatively,\DescribeMacro{RTL}\DescribeMacro{LTR} you can also use the environments
+
+\begin{quote}
+ \begin{verbatim}
+ \begin{RTL}
+ ...
+ \end{RTL}
+ \end{verbatim}
+\end{quote}
+%
+or
+
+\begin{quote}
+ \begin{verbatim}
+ \begin{LTR}
+ ...
+ \end{LTR}
+ \end{verbatim}
+\end{quote}
+
+\subsection{Inline Text Direction}
+
+To change directionality for text chunks inside paragraphs, use
+\begin{description}
+ \item[\cmd\RLE\{...\}]\DescribeMacro{\RLE} (alias: \Cmd\RL) changes the directionality locally to right-to-left.
+ \item[\cmd\LRE\{...\}]\DescribeMacro{\LRE} (alias: \Cmd\LR) changes the directionality locally to left-to-right.
+\end{description}
+
+\subsection{Footnotes}
+
+\subsubsection{Horizontal Footnote Position}
+
+\Lbd\ provides two additional footnote commands in addition to standard \cmd{\footnote}:
+\Cmd{\RTLfootnote}\new{v0.5} and \Cmd{\LTRfootnote}\new{v0.5}.
+The standard \cmd{\footnote} command thereby places the footnote always on the side that is currently the origin of direction:
+on the left side of the page in LTR paragraphs and on the right in RTL paragraphs.
+
+\cmd{\LTRfootnote}, in contrast, always places the footnote on the left side, notwithstanding the current
+directionality. \cmd{\RTLfootnote} always places it on the right side. Like \cmd{\footnote}, \cmd{\RTLfootnote}
+and \cmd{\LTRfootnote} have an optional argument to customize the number.
+
+
+\subsubsection{Footnote Rule Length and Position}
+
+By default, the placement of the footnote rule depends on the main text directionality:
+
+\begin{itemize}
+ \item In default mode (\ie if \cmd{\setRTLmain} is not used), the footnote rule is always set left-aligned (as usual in LTR documents).
+ \item If the main direction is RTL (\ie if \cmd{\setRTLmain} is used), the footnote rule is always set right-aligned (as usual in RTL documents)
+\end{itemize}
+%
+However, with the switch \Cmd{\leftfootnoterule}\new{v0.5}, all subsequent footnote rules are always placed on the left.
+Likewise, \Cmd{\rightfootnoterule}\new{v0.5} causes all subsequent footnote rules to be always placed on the right.
+
+The switch \Cmd{\autofootnoterule}\new{v0.5} and the corresponding package option advise \lbd\ to automatically determine the rule position,
+depending on the directionality of the first footnote on the page. Note that this automatic can fail with footnotes at page boundaries
+that differ in directionality from the first footnote on the page. You can work around such cases by switching to \cmd{\rightfootnoterule}
+or \cmd{\leftfootnoterule} on these pages.
+
+If you want a footnote rule that spans the whole text width, you can use the switch \Cmd{\textwidth\-footnoterule}\new{v0.5}
+or the respective package option.
+
+The length of left and right footnote rules can be adjusted via
+
+\begin{quote}
+ ¦\setlength\footenoterulewidth{⟨length⟩}¦\DescribeMacro{\footenoterulewidth}
+\end{quote}
+%
+The predefined ¦⟨length⟩¦ is ¦0.4\columnwidth¦.
+
+
+
+\section{Commands for Package Authors}
+
+The following tests are provided to be used in packages:
+
+\begin{description}
+ \item[\cscmd{if@RTL}]\DescribeMacro{\if@RTL} determines whether the current paragraph direction is right-to-left.
+ \item[\cscmd{if@RTLmain}]\DescribeMacro{\if@RTLmain} determines whether the main direction is right-to-left.
+\end{description}
+%
+The following macros are provided:
+\begin{description}
+ \item[\cscmd{@ensure@RTL\{...\}}]\DescribeMacro{\@ensure@RTL} Ensure that the argument is typeset RTL.
+ \item[\cscmd{@ensure@LTR\{...\}}]\DescribeMacro{\@ensure@LTR} Ensure that the argument is typeset LTR.
+ \item[\cscmd{@ensure@dir\{...\}}]\DescribeMacro{\@ensure@dir} (alias: \cmd{\@ensure@maindir\{...\}}\DescribeMacro{\@ensure@maindir}) If used in RTL mode, the argument is put inside \cmd{\RLE}, if used in LTR mode, the argument is output as is.
+ \item[\cscmd{hboxR\{...\}}]\DescribeMacro{\hboxR}\new{v0.5} Puts its argument in a RTL \cmd{\hbox}.
+\end{description}
+
+\section{Revision Log}
+
+\begin{description}
+ \item[v. 0.5 (2019/10/27)] Add \cmd{\RTLfootnote}, \cmd{\LTRfootnote}, and \cmd{\hboxR}; fix \texttt{autofootnoterule} option; add \cmd{\autofootnoterule},
+ \cmd{\leftfootnoterule}, \cmd{\rightfootnoterule} and \cmd{\textwidthfootnoterule}; add manual.
+ \item[v. 0.4 (2019/08/24)] Fix \cmd{\@ensure@RTL}.
+ \item[v. 0.3 (2019/07/10)] Fix compatibility with recent \LuaTeX\ (this version was never released to CTAN).
+ \item[v. 0.2 (2013/05/27)] Fix additional files.
+ \item[v. 0.1 (2009/04/01)] Initial release.
+\end{description}
+
+\end{document}
diff --git a/macros/luatex/latex/luabidi/tex/arabmaths.tex b/macros/luatex/latex/luabidi/tex/arabmaths.tex
deleted file mode 100644
index e125dce795..0000000000
--- a/macros/luatex/latex/luabidi/tex/arabmaths.tex
+++ /dev/null
@@ -1,2 +0,0 @@
-\mathdir TRT
-\def\@eqnnum{{\normalfont \normalcolor \textdir TLT ({\textdir TRT\theequation})}}
diff --git a/macros/luatex/latex/luabidi/tex/autofootnoterule.tex b/macros/luatex/latex/luabidi/tex/autofootnoterule.tex
deleted file mode 100644
index f770694652..0000000000
--- a/macros/luatex/latex/luabidi/tex/autofootnoterule.tex
+++ /dev/null
@@ -1,116 +0,0 @@
-\ifx \CatEscape\undefined
- \chardef\CatEscape=0
- \chardef\CatOpen=1
- \chardef\CatClose=2
- \chardef\CatIgnore=9
- \chardef\CatLetter=11
- \chardef\CatOther=12
- \chardef\CatActive=13 % is defined in Plain already
-
- \chardef\CatUsCode=\catcode`\_
-\fi
-
-\catcode`\_=\CatLetter % top level macro file
-
-
-\def\l@fn{%
- \hbox to \columnwidth
- {\pagedir TLT\vbox{\kern -3\p@
- \hrule width .4\columnwidth \kern2.6\p@}\hfil}}
-\def\r@fn{%
- \hrule width .4\columnwidth\kern 2.6\p@}
-
-
-\def\@makefnmark{\hbox{$^{\hbox{\scriptsize\@thefnmark}}\m@th$}}
-
-
-\def\leftfootnoterule{\global\def\footnoterule{\l@fn}}
-\def\rightfootnoterule{\global\def\footnoterule{\r@fn}}
-\leftfootnoterule
-
-%%% \beginprog
-\newread\old_foot_file
-\newwrite\foot_file
-\def\foot_file_name{\jobname.fot\relax}
-\def\init_footnote{%
- \openin\old_foot_file\foot_file_name
- \ifeof\old_foot_file \closein\old_foot_file
- \else \closein\old_foot_file
- \read_foot_file
- \fi
- \immediate\openout\foot_file\foot_file_name
- \immediate\write\foot_file{\relax}%
- \global\let\init_footnote\relax
- }
-
-\newcount\foot_name_no % for generating footnote mark names
-
-
-
-
-
-\newcount\autofootnote
-\def\fnpp_next_footnote{%
- \init_footnote
- \global\advance\foot_name_no\@ne
- \global\advance\c@footnote\@ne
- \edef\do_write{%
- \immediate\write\foot_file{%
- \string\advance\autofootnote\@ne
- \string\expandafter\xdef
- \string\csname\space f@\number\foot_name_no \endcsname{%
- \string\number\autofootnote
- }%
- }%
- }%
- \do_write
- \global\autofootnote 0\csname f@\number\foot_name_no \endcsname \relax
- }
-
-\def\read_foot_file{%
- \begingroup
- \catcode`\@\CatLetter \catcode`\^^M\CatIgnore
- \input \foot_file_name
- \endgroup
- }
-
-\let\fnpp_orig_outputpage=\@outputpage
-\def\@outputpage{%
- \ifx \init_footnote\relax
- \immediate\write\foot_file{\autofootnote\z@}%
- \fi
- \fnpp_orig_outputpage
- }
-
-\let\FnppOrigFootnote=\footnote % save original bindings
-\let\FnppOrigFootnotemark=\footnotemark
-
-\def\footnote{%
- \@ifnextchar[% % ] (Emacs)
- \@xfootnote
- {\fnpp_next_footnote \ifnum\autofootnote=1\rightfootnoterule\fi \@xfootnote[\the\c@footnote] %
-}%
- }
-\def\footnotemark{%
- \@ifnextchar[% % ] (Emacs)
- \@xfootnotemark
- {\fnpp_next_footnote \ifnum\autofootnote=1\rightfootnoterule\fi \@xfootnotemark[\the\c@footnote]}%
- }
-
-
-
-
-\def\footnotemarkLR{%
- \@ifnextchar[% % ] (Emacs)
- \@xfootnotemark
- {\fnpp_next_footnote \ifnum\autofootnote=1\leftfootnoterule\fi\@xfootnotemark[\the\c@footnote]}%
- }
-
-
-\def\Footnote#1{%
-\begingroup
-\footnotemarkLR%
-\renewcommand{\thefootnote}{\@arabic\c@footnote}%
-\pardir TLT \textdir TLT\footnotetext{#1}%
-\endgroup
-}
diff --git a/macros/luatex/latex/luabidi/tex/luabidi-arabmaths.def b/macros/luatex/latex/luabidi/tex/luabidi-arabmaths.def
new file mode 100644
index 0000000000..8e2eaf3028
--- /dev/null
+++ b/macros/luatex/latex/luabidi/tex/luabidi-arabmaths.def
@@ -0,0 +1,11 @@
+%% This file is luabidi-arabmaths.def
+%% 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.
+
+\mathdir TRT
+\def\@eqnnum{{\normalfont \normalcolor \textdir TLT ({\textdir TRT\theequation})}}
diff --git a/macros/luatex/latex/luabidi/tex/luabidi-autofootnoterule.def b/macros/luatex/latex/luabidi/tex/luabidi-autofootnoterule.def
new file mode 100644
index 0000000000..a9f0cbe21f
--- /dev/null
+++ b/macros/luatex/latex/luabidi/tex/luabidi-autofootnoterule.def
@@ -0,0 +1,72 @@
+%% This file is luabidi-autofootnoterule.def
+%% 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.
+
+
+%
+% Determine first footnote on current page
+%
+
+\RequirePackage{perpage}
+\newcounter{pagefnt}
+\setcounter{pagefnt}{0}
+\MakePerPage[0]{pagefnt}
+
+
+%
+% Footnote redefinitions
+%
+
+% Save original definitions
+\let\FnppOrigFootnote=\footnote
+\let\FnppOrigFootnotemark=\footnotemark
+
+% Default: left-aligned rule
+\leftfootnoterule
+
+% \footnote
+\def\footnote{%
+ \@ifnextchar[% % ] (Editor)
+ \@xfootnote
+ {\stepcounter\@mpfn\stepcounter{pagefnt}%
+ \ifnum\value{pagefnt}=0%
+ \if@RTL%
+ \rightfootnoterule%
+ \else%
+ \leftfootnoterule%
+ \fi%
+ \fi%
+ \@xfootnote[\the\c@footnote]%
+ }%
+}
+
+% \RTLfootnote
+\def\footnotemarkRL{%
+ \@ifnextchar[% % ] (Editor)
+ \@xfootnotemark
+ {\stepcounter\@mpfn\stepcounter{pagefnt}%
+ \ifnum\value{pagefnt}=0%
+ \rightfootnoterule%
+ \fi%
+ \@xfootnotemark[\the\c@footnote]%
+ }%
+}
+
+% \LTRfootnote
+\def\footnotemarkLR{%
+ \@ifnextchar[% % ] (Editor)
+ \@xfootnotemark
+ {\stepcounter\@mpfn\stepcounter{pagefnt}%
+ \ifnum\value{pagefnt}=0%
+ \leftfootnoterule%
+ \fi%
+ \@xfootnotemark[\the\c@footnote]%
+ }%
+}
+
+% Finis
diff --git a/macros/luatex/latex/luabidi/tex/luabidi-footnotes.def b/macros/luatex/latex/luabidi/tex/luabidi-footnotes.def
new file mode 100644
index 0000000000..db185e2578
--- /dev/null
+++ b/macros/luatex/latex/luabidi/tex/luabidi-footnotes.def
@@ -0,0 +1,76 @@
+%% This file is luabidi-footnotes.def
+%% 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.
+
+%
+% Footnotes
+%
+
+% These are defined in polyglossia. Provide simple fallbacks
+\providecommand*\localnumeral{\@ifstar\@@localnumeral\@localnumeral}
+
+\providecommand*\@localnumeral[1]{#1}
+\providecommand*\@@localnumeral[1]{%
+ \protect\@arabic\csuse{c@#1}%
+}
+
+\let\footnotemarkLR\footnotemark
+\let\footnotemarkRL\footnotemark
+
+\providecommand\LTRfootnote[2][]{%
+ \begingroup
+ \ifx#1\\\\\footnotemarkLR
+ \renewcommand{\thefootnote}{\localnumeral*{footnote}}%
+ \else%
+ \footnotemarkLR[#1]%
+ \renewcommand{\thefootnote}{\localnumeral{#1}}%
+ \fi
+ \pardir TLT \textdir TLT\footnotetext{#2}%
+ \endgroup
+}
+
+\providecommand\RTLfootnote[2][]{%
+ \begingroup
+ \ifx#1\\\\\footnotemarkRL%
+ \renewcommand{\thefootnote}{\localnumeral*{footnote}}%
+ \else%
+ \footnotemarkRL[#1]%
+ \renewcommand{\thefootnote}{\localnumeral{#1}}%
+ \fi
+ \pardir TRT \textdir TRT\footnotetext{#2}%
+ \endgroup
+}
+
+% backwards compatibility
+\def\Footnote#1{\LTRfootnote{#1}}
+
+%
+% Footnote rules
+%
+
+% adjustable rule length
+\newlength\footnoterulewidth
+\setlength\footnoterulewidth{.4\columnwidth}
+
+% The left, right and full width rules
+\def\luabidi@left@fn{%
+ \hbox to \columnwidth
+ {\pagedir TLT\textdir TLT\vbox{\kern -3\p@
+ \hrule\@width\footnoterulewidth\kern2.6\p@}\hfil}}
+\def\luabidi@right@fn{%
+ \pagedir TRT\textdir TRT\hrule\@width\footnoterulewidth\kern2.6\p@}
+\def\luabidi@textwidth@fn{%
+ \kern-3\p@\hrule\@width\textwidth\kern2.6\p@}
+
+% switches for the rule position
+\def\leftfootnoterule{\global\def\footnoterule{\luabidi@left@fn}}
+\def\rightfootnoterule{\global\def\footnoterule{\luabidi@right@fn}}
+\def\textwidthfootnoterule{\global\def\footnoterule{\luabidi@textwidth@fn}}
+\def\autofootnoterule{\luabidi@autofootnoteruletrue}
+
+% Finis
diff --git a/macros/luatex/latex/luabidi/tex/luabidi.sty b/macros/luatex/latex/luabidi/tex/luabidi.sty
index abc1d2a936..4277a1f173 100644
--- a/macros/luatex/latex/luabidi/tex/luabidi.sty
+++ b/macros/luatex/latex/luabidi/tex/luabidi.sty
@@ -1,4 +1,5 @@
%% 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
%%
@@ -6,11 +7,30 @@
%% 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/08/24 v0.4
+\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
-\def\setRTLmain{\pagedir TRT \bodydir TRT \pardir TRT \textdir TRT}
+\@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}
@@ -25,9 +45,6 @@
\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
-\@RTLmainfalse
-\DeclareOption{arabmaths}{\input{arabmaths}}
-\DeclareOption{textwidthfootnoterule}{\input{textwidthfootnoterule}}
\let\n@xt=\
\DeclareRobustCommand*\LRE{\protect\pLRE}
\def\pLRE{\protect\afterassignment\moreLRE \let\n@xt= }
@@ -39,18 +56,25 @@
\def\moreRLE{\bracetext \aftergroup\unsetRTL \setRTL\@RTLtrue}
\let\LR=\LRE
\let\RL=\RLE
+\def\hboxR#1{\hbox{\RL{#1}}}
-\def\Footnote#1{%
-\begingroup
-\footnotemark
-\renewcommand{\thefootnote}{\@arabic\c@footnote}%
-\pardir TLT \textdir TLT\footnotetext{#1}%
-\endgroup
-}
+%
+% Footnotes
+%
-\DeclareOption{autofootnoterule}{\input{autofootnoterule}}
+\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
+}
-\ProcessOptions
\endinput
diff --git a/macros/luatex/latex/luabidi/tex/textwidthfootnoterule.tex b/macros/luatex/latex/luabidi/tex/textwidthfootnoterule.tex
deleted file mode 100644
index 7fc71e0cef..0000000000
--- a/macros/luatex/latex/luabidi/tex/textwidthfootnoterule.tex
+++ /dev/null
@@ -1,2 +0,0 @@
-\def\footnoterule{\kern-3\p@
- \hrule \@width \textwidth \kern 2.6\p@}