%% This is file `quran-transfa.def',
%%
%% Copyright © 2015-2025
%% Seiied-Mohammad-Javad Razavian <javadr@gmail.com>
%%
%% This work 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.
%%
%% This work has the LPPL maintenance status `maintained'.
%%
%% This work is “author-maintained” (as per LPPL maintenance status).
%%
%% The Current Maintainer of this work is Seiied-Mohammad-Javad Razavian.
%%
%% To one who has devoted his life to Quran
%%
\let\qt@doqt@orig\qt@doqt%
\let\ToggleBasmalah@orig\ToggleBasmalah%
%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\basmalahfa{به نام خداوند رحمتگر مهربان\qt@par\space}%
\bidi@newrobustcmd\ToggleBasmalahfa{%
  \ifx\basmalahfa\relax%
    \def\basmalahfa{به نام خداوند رحمتگر مهربان\qt@par\space}%
  \else%
    \let\basmalahfa\relax%
  \fi%
}%
\def\Basmalahfa{%
        \begingroup%
        \let\par\relax%
        \def\qt@no##1{\relax}%
        \quranayahfa[1][1][1]%
        \endgroup%
}%
%%%%%%%%%%%%%%%%%%%%%%%%%%
\DeclareDocumentCommand\qt@dofa{ o o }{%
    \addtocounter{qt@count}{1}%
    \def\@qtexp{}%
    \loop%
        \global\xdef\@qtexp{\@qtexp\csname qurantrans@fa@\roman{qt@count}\endcsname\ifnum\value{qt@count}=\qt@max\else\space\fi%
        \ifnum\value{qt@count}<\qt@max\relax\qt@par\fi}%
        \ifnum\value{qt@count}<\qt@max\relax%
        \addtocounter{qt@count}{1}%
    \repeat%
    \IfNoValueTF{#1}%
    {\@qtexp\qt@par}%true
    {\qt@WordCount=0\relax\c@qt@start=\numexpr#1-1\relax%
    \readlist*\qt@words{\@qtexp}%
        \IfNoValueTF{#2}%
        {\c@qt@end=\numexpr\qt@wordslen+1\relax}{\c@qt@end=\numexpr#2+1\relax}%
        \foreachitem\qt@word\in\qt@words{%
            \ifnum\qt@wordcnt>\c@qt@start\ifnum\qt@wordcnt<\c@qt@end\qt@word\ifnum\qt@wordcnt=\numexpr\c@qt@end-1\relax\else\xspace\fi\fi\fi%
        }%
        \qt@showitems{\ifdefined\arabicfont\arabicfont\fi\showitems\qt@words}%
    \qt@par}%false
}%
%%%%%%%%%%%%%%%%%%%%%%%%%%
\DeclareDocumentCommand{\qurantextfa}{ s O{\qt@default} o t{+} }{%
    \IfBooleanTF{#4}{\def\qt@showitems##1{\footnote{##1}}}{\def\qt@showitems##1{\relax}}%
    \let\qt@doqt\qt@dofa%
    \IfBooleanTF{#1}%
    {\IfBooleanTF{#4}{\qurantext*[#2][#3]+}{\qurantext*[#2][#3]}}%
    {\IfBooleanTF{#4}{\qurantext[#2][#3]+}{\qurantext[#2][#3]}}%
    \let\qt@doqt\qt@doqt@orig%
    \def\qt@showitems##1{\relax}%
}%
%%%%%%%%%%%%%%%%%%%%%%%%%%
\DeclareDocumentCommand\quransurahfa{ s O{\qt@surah@default} }{%
    \let\qt@doqt\qt@dofa%
    \IfBooleanTF{#1}%
    {\quransurah*[#2]}%
    {\quransurah[#2]}%
    \let\qt@doqt\qt@doqt@orig%
}%
%%%%%%%%%%%%%%%%%%%%%%%%%%
\DeclareDocumentCommand{\quranayahfa}{ s o o o t{+} }{%
    \let\qt@doqt\qt@dofa%
    \let\ToggleBasmalah\ToggleBasmalahfa%
    \IfBooleanTF{#1}%
    {\IfBooleanTF{#5}{\quranayah*[#2][#3][#4]+}{\quranayah*[#2][#3][#4]}}%
    {\IfBooleanTF{#5}{\quranayah[#2][#3][#4]+}{\quranayah[#2][#3][#4]}}%
    \let\qt@doqt\qt@doqt@orig%
    \let\ToggleBasmalah\ToggleBasmalah@orig%
}%
%%%%%%%%%%%%%%%%%%%%%%%%%%
\DeclareDocumentCommand{\quranjuzfa}{ s o }{%
    \let\qt@doqt\qt@dofa%
    \IfBooleanTF{#1}%
    {\quranjuz*[#2]}%
    {\quranjuz[#2]}%
    \let\qt@doqt\qt@doqt@orig%
}%
%%%%%%%%%%%%%%%%%%%%%%%%%%
\DeclareDocumentCommand{\quranpagefa}{ s o }{%
    \let\qt@doqt\qt@dofa%
    \IfBooleanTF{#1}%
    {\quranpage*[#2]}%
    {\quranpage[#2]}%
    \let\qt@doqt\qt@doqt@orig%
}%
%%%%%%%%%%%%%%%%%%%%%%%%%%
\DeclareDocumentCommand{\quranquarterfa}{ s o }{%
    \let\qt@doqt\qt@dofa%
    \IfBooleanTF{#1}%
    {\quranquarter*[#2]}%
    {\quranquarter[#2]}%
    \let\qt@doqt\qt@doqt@orig%
}%
%%%%%%%%%%%%%%%%%%%%%%%%%%
\DeclareDocumentCommand{\quranrukufa}{ s o }{%
    \let\qt@doqt\qt@dofa%
    \IfBooleanTF{#1}%
    {\quranruku*[#2]}%
    {\quranruku[#2]}%
    \let\qt@doqt\qt@doqt@orig%
}%
%%%%%%%%%%%%%%%%%%%%%%%%%%
\DeclareDocumentCommand{\quranhizbfa}{ s o }{%
    \let\qt@doqt\qt@dofa%
    \IfBooleanTF{#1}%
    {\quranhizb*[#2]}%
    {\quranhizb[#2]}%
    \let\qt@doqt\qt@doqt@orig%
}%
%%%%%%%%%%%%%%%%%%%%%%%%%%
\DeclareDocumentCommand{\quranmanzilfa}{ s o }{%
    \let\qt@doqt\qt@dofa%
    \IfBooleanTF{#1}%
    {\quranmanzil*[#2]}%
    {\quranmanzil[#2]}%
    \let\qt@doqt\qt@doqt@orig%
}%
%%%%%%%%%%%%%%%%%%%%%%%%%%
