summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/hvarabic/latex/hvarabic.sty
blob: 381a15009f25b4f95a79a0700a97fada4418d42b (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
%% This is file `hvarabic.sty',
%%
%% Copyright (C) 2021
%% Herbert Voss  <hvoss@tug.org>
%%
%% 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.
%% The latest version of this license is in
%%    http://www.latex-project.org/lppl.txt
%% and version 1.3c or later is part of all distributions of LaTeX
%% version 2005/12/01 or later.
%
% -------------------------------------
\ProvidesPackage{hvarabic}[2021/06/01 v. 0.01a define macros for RTL typesetting (hv)]
%
\RequirePackage{iftex}
\iftutex
\else
  \ExplSyntaxOn
  \msg_new:nnn {unitconv} {need-lualatex}
  {
    The~ hvarabic~ package~ requires~ LuaLaTeX or XeLaTeX.\\\\
    You~ must~ change~ your~ typesetting~ engine~ to,~
    "lualatex/xelatex" instead~ of~ "latex", or ~"pdflatex".
  }
  \msg_fatal:nn {unitconv} {need-lualatex/xelatex}
  \ExpSyntaxOff
  \endinput
\fi

\RequirePackage{xkeyval,fontspec}

\newif\ifhv@RTLfootnoterule \hv@RTLfootnoterulefalse
\DeclareOptionX{RTLfootnoterule}[true]{\@nameuse{hv@RTLfootnoterule#1}}
%
\ProcessOptionsX\relax

\providefontface\RTLfont
    [Script=Arabic,        % to get correct arabic shaping
     Scale=1.2]{Scheherazade}         % whatever Arabic font you like
\newfontfamily\hvALM{ALM Fixed}[Scale=0.85]
\newcommand\textRTL[1]{\bgroup\textdir TRT\RTLfont #1\egroup}% Arabic inside LTR
\newcommand\nLTR[1]{\bgroup\textdir TLT #1\egroup}% for digits inside Arabic text
\newcommand\RTLfootnote[1]{\footnote{\textRTL{#1}}}% Arabic footnotes

\ifhv@RTLfootnoterule
  \newenvironment{RTL}
     % Arabic paragraph
           {\setRTLfootnoterule\textdir TRT\pardir TRT\RTLfont}
           {\setLTRfootnoterule}
\else
  \newenvironment{RTL}
     % Arabic paragraph
           {\textdir TRT\pardir TRT\RTLfont}
           {}
\fi
\def\setLTRfootnoterule{\let\LTRfootnoterule\footnoterule}
\def\setRTLfootnoterule{%
  \global\let\LTRfootnoterule=\footnoterule
  \gdef\footnoterule{\noindent\parbox{\textwidth}{\hfill\vbox{\LTRfootnoterule}}}}

\def\setRTL{\par\textdir TRT\pardir TRT}
\def\setLTR{\par\textdir TLT\pardir TLT}
\endinput