summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/lualatex/simurgh/simurgh-bidi.sty
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/lualatex/simurgh/simurgh-bidi.sty')
-rw-r--r--Master/texmf-dist/tex/lualatex/simurgh/simurgh-bidi.sty105
1 files changed, 105 insertions, 0 deletions
diff --git a/Master/texmf-dist/tex/lualatex/simurgh/simurgh-bidi.sty b/Master/texmf-dist/tex/lualatex/simurgh/simurgh-bidi.sty
new file mode 100644
index 00000000000..925dc440e43
--- /dev/null
+++ b/Master/texmf-dist/tex/lualatex/simurgh/simurgh-bidi.sty
@@ -0,0 +1,105 @@
+\NeedsTeXFormat{LaTeX2e}
+\ProvidesPackage{simurgh-bidi}[2013/12/01 v0.01a bidirectional typesetting]
+\directlua { tex.enableprimitives('simurgh@',{'pagedir','bodydir','pardir','textdir','mathdir','boxdir'}) }
+\newif\if@RTLmain
+\newif\if@RTL
+\newif\if@Latin
+\@RTLmainfalse
+\AtBeginDocument{%
+ \if@RTLmain\else
+ \if@RTL\@RTLmaintrue%
+ \else\@RTLmainfalse%
+ \fi%
+ \fi%
+}
+\let\simurgh@n@xt=\
+\simurgh@newrobustcmd*{\textLRE}{\protect\simurgh@ptextLRE}%
+\def\simurgh@ptextLRE{\protect\afterassignment\simurgh@moretextLRE \let\simurgh@n@xt= }
+\simurgh@newrobustcmd*{\textRLE}{\protect\simurgh@ptextRLE}
+\def\simurgh@ptextRLE{\protect\afterassignment\simurgh@moretextRLE \let\simurgh@n@xt= }
+\def\simurgh@bracetext{\ifcat\simurgh@n@xt{\else\ifcat\simurgh@n@xt}\fi
+ \simurgh@error{missing left brace has been substituted}{}\fi \bgroup}
+\def\simurgh@moretextLRE{\simurgh@bracetext \@RTLfalse\simurgh@textdir TLT}
+\def\simurgh@moretextRLE{\simurgh@bracetext \@RTLtrue\simurgh@textdir TRT}
+
+\simurgh@newrobustcmd*{\textLatin}[1]{\textLRE{\@Latintrue\latinmainfont #1}}
+\simurgh@newrobustcmd*{\textParsi}[1]{\textRLE{\@Latinfalse\parsimainfont #1}}
+
+
+
+\protected\def\hboxR{\hbox\bgroup
+ \everyhbox{%
+ \aftergroup\egroup
+ \everyhbox{}%
+ \@RTLtrue%
+ }\hbox dir TRT}
+\protected\def\hboxL{\hbox\bgroup
+ \everyhbox{%
+ \aftergroup\egroup
+ \everyhbox{}%
+ \@RTLfalse%
+ }\hbox dir TLT}
+\protected\def\vboxR{\vbox\bgroup
+ \everyvbox{%
+ \aftergroup\egroup
+ \everyvbox{}%
+ \@RTLtrue%
+ }\vbox dir TRT}
+\protected\def\vboxL{\vbox\bgroup
+ \everyvbox{%
+ \aftergroup\egroup
+ \everyvbox{}%
+ \@RTLfalse%
+ }\vbox dir TLT}
+\protected\def\vtopR{\vtop\bgroup
+ \everyvbox{%
+ \aftergroup\egroup
+ \everyvbox{}%
+ \@RTLtrue%
+ }\vtop dir TRT}
+\protected\def\vtopL{\vtop\bgroup
+ \everyvbox{%
+ \aftergroup\egroup
+ \everyvbox{}%
+ \@RTLfalse%
+ }\vtop dir TLT}
+
+
+
+ \def\LTRpar{\par\@RTLfalse\@RTL@footnotefalse\simurgh@pardir TLT \simurgh@textdir TLT \hsize\linewidth\parshape\z@}
+\def\endLTRpar{\par}
+\def\RTLpar{\par\@RTLtrue\@RTL@footnotetrue\simurgh@pardir TRT \simurgh@textdir TRT \hsize\linewidth\parshape\z@}
+\let\endRTLpar\endLTRpar
+\def\setRTLpar{\@RTLtrue\@RTL@footnotetrue\simurgh@pardir TRT \simurgh@textdir TRT}
+\def\setLTRpar{\@RTLfalse\@RTL@footnotefalse\simurgh@pardir TLT \simurgh@textdir TLT}
+\let\unsetRTLpar\setLTRpar
+\let\unsetLTRpar\setRTLpar
+
+
+\def\latinpar{\LTRpar\LatinAlphs\@Latintrue\@RTL@footnotefalse\reset@latinfont}
+\let\endlatinpar\endLTRpar
+\def\parsipar{\RTLpar\ParsiAlphs\@RTL@footnotetrue\reset@parsifont}
+\let\endparsipar\endRTLpar
+
+\def\setRTLmath{\simurgh@mathdir TRT}
+\def\setLTRmath{\simurgh@mathdir TLT}
+\let\unsetRTLmath\setLTRmath
+\let\unsetLTRmath\setRTLmath
+
+\def\ensureRTLtext#1{\if@RTL#1\else\textRLE{#1}\fi}
+\def\ensureLTRtext#1{\if@RTL\textLRE{#1}\else#1\fi}
+\def\simurgh@par@RTL{RTL}
+\def\simurgh@par@LTR{LTR}
+\def\savepardir{\if@RTL\gdef\saved@par@dir{RTL}\else\gdef\saved@par@dir{LTR}\fi}
+\def\resetpardir{\ifx\saved@par@dir\simurgh@par@RTL\setRTLpar\else\ifx\saved@par@dir\simurgh@par@LTR\setLTRpar\else\relax\fi\fi}
+
+
+\def\ensureparsitext#1{\if@Latin\textParsi{#1}\else #1 \fi}
+\def\ensurelatintext#1{\if@Latin #1 \else\textLatin{#1}\fi}
+
+\long\def\ensuresboxdir#1#2{\if@RTL\setbox#1\hbox dir TRT{%
+ \color@setgroup#2\color@endgroup}\else%
+\setbox#1\hbox dir TLT{%
+ \color@setgroup#2\color@endgroup}\fi}
+
+\endinput \ No newline at end of file