% unipersian-fonts.def % % UniPersian: Persian language support for LaTeX. % % Copyright (C) 2026 Amer Amikhteh % % This file is part of the UniPersian package. % % This work is free software: you may redistribute it and/or modify % it under the terms of the LaTeX Project Public License as published % by the LaTeX Project, either version 1.3c of the License, or % (at your option) any later version. % % This work is distributed in the hope that it will be useful, % but WITHOUT ANY WARRANTY; without even the implied warranty of % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. % % The full license text is available at: % https://www.latex-project.org/lppl/ % % This work is "maintained" by Amer Amikhteh. % % The current maintainer of this work is Amer Amikhteh. \ProvidesFile{unipersian-fonts.def} [2026/09/08 v0.1.0 Common definitions for fonts in XeTeX and LuaTeX] \makeatletter \providecommand{\persianmainlanguage}{persian} % -------------------------------------- % Main Persian and Latin fonts % -------------------------------------- \NewDocumentCommand{\settextfont}{O{} m}{% \ifXeTeX \babelfont[persian]{rm}% [Mapping=farsidigits,#1]{#2}% \babelfont[persian]{sf}% [Mapping=farsidigits,#1]{#2} \else \babelfont[persian]{rm}[#1]{#2}% \babelfont[persian]{sf}[#1]{#2}% \fi } \NewDocumentCommand{\setlatintextfont}{O{} m}{% \babelfont[english]{rm}[#1]{#2}% \babelfont[english]{sf}[#1]{#2} } % ------------------------------------------ % Default fonts % ------------------------------------------ \ifnum\bbl@bidimode>\@ne % هر bidi غیر از default \IfFontExistsTF{HM XNiloofar}{\settextfont{HM XNiloofar}} {\IfFontExistsTF{Vazirmatn}{\settextfont[ItalicFont={Vazirmatn}]{Vazirmatn}} {\IfFontExistsTF{Amiri}{\settextfont{Amiri}} {\IfFontExistsTF{FreeSerif}{\settextfont{FreeSerif}} {\IfFontExistsTF{Tahoma}{\settextfont{Tahoma}} {\typeout{Warning: No suitable Persian font found!} }}}}} \fi % -------------------------------------- % Persian sans and monospaced fonts % -------------------------------------- \NewDocumentCommand{\setpersiansansfont}{O{} m}{% \ifXeTeX \babelfont[persian]{sf}% [Mapping=farsidigits,#1]{#2}% \else \babelfont[persian]{sf}[#1]{#2}% \fi } \providecommand\persianttdefault{} \NewDocumentCommand{\setpersianmonofont}{O{} m}{% \babelfont[persian]{tt}[#1]{#2}% \begingroup \selectlanguage{persian}% \ttfamily \xdef\persianttdefault{\f@family}% \endgroup } \providecommand\persianttdefault{} \DeclareRobustCommand\persianttfamily{% \not@math@alphabet\persianttfamily\mathpersiantt \fontfamily\persianttdefault \selectfont } \DeclareTextFontCommand{\textpersiantt}{\persianttfamily} % -------------------------------------- % Latin sans and monospaced fonts % -------------------------------------- \NewDocumentCommand{\setlatinsansfont}{O{} m}{% \babelfont[english]{sf}[#1]{#2}% } \providecommand\latinttdefault{} \providecommand\latinttfamily{} \NewDocumentCommand{\setlatinmonofont}{O{} m}{% \babelfont[english]{tt}[#1]{#2}% \begingroup \selectlanguage{english}% \ttfamily \xdef\latinttdefault{\f@family}% \endgroup } \DeclareRobustCommand\latinttfamily{% \not@math@alphabet\latinttfamily\mathtt \fontfamily\latinttdefault \selectfont % \babeladjust{bidi.mapdigits=off} \ifLuaTeX\setattribute\bbl@attr@locale 0\fi } \DeclareTextFontCommand{\textlatintt}{\latinttfamily} % -------------------------------------- % User-defined Persian fonts % -------------------------------------- \DeclareDocumentCommand \defpersianfont { m o m } { \newfontfamily#1{#3}[Script=Arabic,Renderer=Harfbuzz,#2] } \DeclareDocumentCommand \deflatinfont { m o m } { \newfontfamily#1{#3}[Script=Latin,#2] } \makeatother \endinput