\startenvironment persian-env
\usemodule[lang-pe]
\mainlanguage[pe]
% Font setup
\definefontfeature
[persian]
[mode=node,language=dflt,script=arab,
init=yes,medi=yes,fina=yes,isol=yes,
liga=yes,dlig=yes,rlig=yes,clig=yes,
mark=yes,mkmk=yes,kern=yes,curs=yes]
\starttypescript [serif] [persian]
\definefontsynonym [Persian-Regular] [name:XB Zar.ttf] [features=persian]
\definefontsynonym [Persian-Bold] [name:XB Zar Bd.ttf] [features=persian]
\definefontsynonym [Persian-Italic] [name:XB Zar It.ttf] [features=persian]
\definefontsynonym [Persian-BoldItalic] [name:XB Zar BdIt.ttf] [features=persian]
\stoptypescript
\starttypescript [sans] [persian]
\definefontsynonym [Persian-Regular-sans] [name:XM Traffic.ttf] [features=persian]
\definefontsynonym [Persian-Bold-sans] [name:XM Traffic Bd.ttf] [features=persian]
\definefontsynonym [Persian-Italic-sans] [name:XM Traffic It.ttf] [features=persian]
\definefontsynonym [Persian-BoldItalic-sans] [name:XM Traffic BdIt.ttf] [features=persian]
\stoptypescript
\starttypescript [mono] [persian]
\definefontsynonym [Persian-Regular-mono] [name:XB Roya.ttf] [features=persian]
\definefontsynonym [Persian-Bold-mono] [name:XB Roya Bd.ttf] [features=persian]
\definefontsynonym [Persian-Italic-mono] [name:XB Roya It.ttf] [features=persian]
\definefontsynonym [Persian-BoldItalic-mono] [name:XB Roya BdIt.ttf] [features=persian]
\stoptypescript
\starttypescript [serif][persian][name]
\usetypescript[serif][persian]
\definefontsynonym [Serif] [Persian-Regular] [features=persian]
\definefontsynonym [SerifBold] [Persian-Bold] [features=persian]
\definefontsynonym [SerifItalic] [Persian-Italic] [features=persian]
\definefontsynonym [SerifBoldItalic] [Persian-BoldItalic] [features=persian]
\stoptypescript
\starttypescript [sans][persian][name]
\usetypescript[sans][persian]
\definefontsynonym [Sans] [Persian-Regular-sans] [features=persian]
\definefontsynonym [SansBold] [Persian-Bold-sans] [features=persian]
\definefontsynonym [SansItalic] [Persian-Italic-sans] [features=persian]
\definefontsynonym [SansBoldItalic] [Persian-BoldItalic-sans] [features=persian]
\stoptypescript
\starttypescript [mono][persian][name]
\usetypescript[mono][persian]
\definefontsynonym [Mono] [Persian-Regular-mono] [features=persian]
\definefontsynonym [MonoBold] [Persian-Bold-mono] [features=persian]
\definefontsynonym [MonoItalic] [Persian-Italic-mono] [features=persian]
\definefontsynonym [MonoBoldItalic] [Persian-BoldItalic-mono] [features=persian]
\stoptypescript
\starttypescript [Persian]
\definetypeface[Persian][rm][serif][persian][default]
\definetypeface[Persian][rm][sans][persian][default]
\definetypeface[Persian][rm][mono][persian][default]
\stoptypescript
\def\PersianGlobalDir {\pagedir TRT\bodydir TRT\pardir TRT\textdir TRT}
\def\PersianParDir {\textdir TRT\pardir TRT}
\def\PersianTextDir {\textdir TRT}
\def\LatinParDir {\textdir TLT\pardir TLT}
\def\LatinTextDir {\textdir TLT}
\def\LatinGlobalDir {\pagedir TLT\bodydir TLT\pardir TLT\textdir TLT}
\definestartstop[persiandocument][commands={\usetypescript[Persian]%
\setupbodyfont[Persian,12pt]%
\PersianGlobalDir}]
\definestartstop
[persianpar]
[commands=\Persian\PersianParDir]
\define[1]\RT
{{\Persian\PersianTextDir#1}}
\define\setlatin
{\LatinGlobalDir%
\usetypescript[lm]%
\setupbodyfont[lm,18pt]}
\definestartstop
[latinpar]
[commands=\Persian\LatinParDir]
\define[1]\LT
{{\LatinTextDir#1}}
% \setuphead
% [chapter]
% [ page=yes,
% before=\hairline\blank,
% after=\nowhitespace\hairline,
% header=nomarking,
% textstyle=bold,
% numberstyle=bold,
% ]
\setupheads[separator=\LT{--}]
\setupheadertexts[]%We put here because we want to define headertexts next.
%\setupheadertexts[][pagenumber]
\setupsection [chapter][conversion=persiannumerals]
\setupsection [section][conversion=persiannumerals]
\setupsection [subsection][conversion=persiannumerals]
\setupsection [subsubsection][conversion=persiannumerals]
\setupfootnotes[conversion=persiannumerals]
\setupnumbering[conversion=persiannumerals]
\setupformulas[conversion=persiannumerals]
\setuppagenumbering[conversion=persiannumerals]
\setupcaptions[conversion=persiannumerals]
\setupwhitespace[none]
\setupdirections[bidi=global]
\stopenvironment
---------------------------------------------end--------------------