3

I'm using Xepersian package in Latex. I'm typing my whole text in "XBZar" font, and digits (numbers) in "Yas" font. My concern here is the chapter/section/subsection labels.

So, by default the whole chapter/section/subsection labels are in "XBZar" font (including the text and numbering, or anything you call them). I'd like to only and only change these labels numbering font to "Yas".

Here is an example of what I've currently achived, and what I want to get. enter image description here And here is a minimal example:

    \documentclass{book}
    \usepackage{caption}
    \usepackage{xepersian}

    \settextfont[Scale=1]{XB Zar}
    \setdigitfont[Scale=1]{Yas}
    \setlatintextfont[Scale=.98]{Times New Roman}

    \defpersianfont\Yas{Yas}
    \DeclareCaptionFormat{myformat}{{\Yas #1}#2#3}
    \captionsetup{format=myformat}

    \begin{document}

    \chapter{مقدمه (\lr{Preface})}
    \thispagestyle{empty}
    \section{فصل اول (\lr{First Section})}
    سلام، این یک عدد است $10.004$.
    \subsection{بخش اول}
    \flushleft
    \lr{So, I need the chapter/section/subsection numbering font to be "Yas" instead of "XBZar". I should stress that ONLY numbering not the whole label.}

    \end{document}
Ahama
  • 33

1 Answers1

1

You can modify the format of \thechapter , \thesection and \thesubsection to obtain the desired font for headings numbers with this trick

\let\oldthechapter\thechapter
\let\oldthesection\thesection
\let\oldthesubsection\thesubsection

\renewcommand{\thechapter}{\begingroup \Yas \oldthechapter \endgroup}
\renewcommand{\thesection}{\begingroup \Yas \oldthesection \endgroup}
\renewcommand{\thesubsection}{\begingroup \Yas \oldthesubsection \endgroup}

Code

\documentclass{book}
\usepackage{caption}
\usepackage{xepersian}

\settextfont[Scale=1]{XB Zar}
\setdigitfont[Scale=1]{Yas}
\setlatintextfont[Scale=.98]{Times New Roman}

\defpersianfont\Yas{Yas}
\DeclareCaptionFormat{myformat}{{\Yas #1}#2#3}
\captionsetup{format=myformat}

\let\oldthechapter\thechapter
\let\oldthesection\thesection
\let\oldthesubsection\thesubsection

\renewcommand{\thechapter}{\begingroup \Yas \oldthechapter \endgroup}
\renewcommand{\thesection}{\begingroup \Yas \oldthesection \endgroup}
\renewcommand{\thesubsection}{\begingroup \Yas \oldthesubsection \endgroup}

\begin{document}

\chapter{مقدمه (\lr{Preface})}
\thispagestyle{empty}
\section{فصل اول (\lr{First Section})}
سلام، این یک عدد است $10.004$.
\subsection{بخش اول}

\end{document}

Output

enter image description here

Salim Bou
  • 17,021
  • 2
  • 31
  • 76