2

I am trying to write an article in LaTeX using TeXstudio and XeLaTeX, because I am writing in Arabic. I have a problem with numbering the equation. It appears like this:

enter image description here

The numbering of the equation appears as )1( instead of (1).

The preamble of the file is:

\documentclass[b5paper,12pt]{article}
\usepackage{amsmath} 
\usepackage{graphicx}
\usepackage{polyglossia}
\usepackage[LFE,LAE]{fontenc}
\usepackage{titlesec}
\usepackage{fmtcount}
\usepackage[margin=0.75in]{geometry}
\usepackage{fontspec}
\usepackage{fancyhdr}
\usepackage{hyperref}
\usepackage{hypcap}



\usepackage[backend=biber,bibencoding=utf8,style=ieee]{biblatex}
\providecommand{\keywords}[1]{\textbf{\textit{الكلمات المفتاحية: }} #1}
%Language settings for polyglossia
\setmainlanguage{arabic}
\setotherlanguage{english}
\setmainfont{Simplified Arabic}
\newfontfamily\arabicfont[Script = Arabic]{Simplified Arabic} 

\let\arabicfonttt\ttfamily
\setkeys{arabic}{numerals=maghrib,locale=mashriq,calendar=gregorian}
\renewcommand{\thesection}{\arabic{section}~}
\renewcommand{\thesubsection}{\thesection-~\arabic{subsection}~}
\renewcommand{\thesubsubsection}{\thesubsection-~\arabic{subsubsection}~}

\titleformat{\section}{\normalfont\normalsize\bfseries}{\thesection-~}{0.5em}{\normalfont\normalsize\bfseries}
\titleformat{\subsection}{\normalfont\normalsize\bfseries}{\thesubsection-~}{0.5em}{\normalfont\normalsize\bfseries}

\titleformat{\subsubsection}{\normalfont\normalsize\bfseries}{\thesubsubsection-~}{0.5em}{\normalfont\normalsize\bfseries}

\DeclareDocumentCommand{\printbib}{o}{\printbibheading
    \begin{english}
        \providecommand*{\MakeUppercase}[1]{#1}
        \printbibliography[heading=none]
\end{english}}

And the equation is:

\begin{equation}
\label{equation:psnr}
PSNR=10\log_{10}{\frac{MAX^{2}}{\frac{1}{mn}\sum_{i=0}^{m-1}\sum_{j=0}^{n-1}\left[I(i,j)-K(i,j)\right]^{2}}}
\end{equation}

I tried amsmath and mathtools with no success, I tried adding \csname @Latintrue\endcsname after the \thenewfontfamily but again to no sucess

2
  • 3
    It'd be great if you could remove the parts of the code that aren't relevant to your question (e.g. biblatex, b5paper, titleformats, etc.) and then merge both code blocks into a single, compilable MWE.
    – steve
    May 14 '20 at 19:11
  • 1
    Please tell us which TeX engine you employ and its vintage. When was it last updated?
    – Mico
    May 14 '20 at 19:37
4

The basic problem here was that amsmath was trying to set your equation tags in the default language, Arabic. Mixing Latin characters with Arabic script confused the bidirectional algorithm.

If your Arabic font does not support parentheses in Arabic script, the only error you will get is a silent warning message buried in your log file. This is an extremely bad design decision going back decades, and you can at least see the warning message in the console, about ( and ) missing from your Arabic font, with the default left-to-right font substituted, by adding the command \tracinglostchars=2.

There are several fixes.

Load a Better Arabic Font

Khaled Hosny’s Amiri sets up parentheses to work correctly in Arabic. Here, I load Hosny’s Libertinus family as the matching text and math fonts. This brings in unicode-math and loads Libertinus Math as your OpenType math font. If you do not want to load unicode-math but do want your fonts to match, you could instead load \usepackage{libertine} and \usepackage[libertine]{newtxmath}.

\documentclass[b5paper,12pt]{article}
\usepackage{mathtools} 
\usepackage{graphicx}
\usepackage{polyglossia}
\usepackage{libertinus} % Or perhaps \usepackage[libertine]{newtxmath}
\usepackage{titlesec}
\usepackage{fmtcount}
\usepackage[margin=0.75in]{geometry}
\usepackage{fancyhdr}
\usepackage{hyperref}
\usepackage{hypcap}

\tracinglostchars=2 % Warn when a character is missing!

\usepackage[backend=biber,bibencoding=utf8,style=ieee]{biblatex}
\providecommand{\keywords}[1]{\textbf{\textit{الكلمات المفتاحية: }} #1}
%Language settings for polyglossia
\setmainlanguage{arabic}
\setotherlanguage{english}

\defaultfontfeatures{Scale=MatchLowercase}
\newfontfamily\arabicfont[Script = Arabic]{Amiri}
\newfontfamily\arabicfontsf[Script = Arabic]{Noto Sans Arabic}

\setkeys{arabic}{numerals=maghrib,locale=mashriq,calendar=gregorian}
\renewcommand{\thesection}{\arabic{section}~}
\renewcommand{\thesubsection}{\thesection-~\arabic{subsection}~}
\renewcommand{\thesubsubsection}{\thesubsection-~\arabic{subsubsection}~}

\titleformat{\section}{\normalfont\normalsize\bfseries}{\thesection-~}{0.5em}{\normalfont\normalsize\bfseries}
\titleformat{\subsection}{\normalfont\normalsize\bfseries}{\thesubsection-~}{0.5em}{\normalfont\normalsize\bfseries}

\titleformat{\subsubsection}{\normalfont\normalsize\bfseries}{\thesubsubsection-~}{0.5em}{\normalfont\normalsize\bfseries}

\DeclareDocumentCommand{\printbib}{o}{\printbibheading
    \begin{english}
        \providecommand*{\MakeUppercase}[1]{#1}
        \printbibliography[heading=none]
    \end{english}}

\begin{document}
\begin{equation}
\label{equation:psnr}
\mathrm{PSNR}=10\log_{10}{\frac{\mathrm{MAX}^{2}}{\frac{1}{mn}\sum_{i=0}^{m-1}\sum_{j=0}^{n-1}\left[I(i,j)-K(i,j)\right]^{2}}}
\end{equation}
\end{document}

Amiri/Libertinus sample

I removed a few obsolete or redundant packages from the preamble, such as fontenc in Unicode mode. I also took the liberty of tweaking the output slightly

Redefine the Tag Format

The mathtools package includes a command \newtagform that you can use to redefine the format of your equation numbers. To display the number in English without parentheses, you could declare

\newtagform{english}[\textenglish]%
{}%
{}
\usetagform{english}

If you try to use \textenglish or LTR on the delimiters, they will still display the wrong way around, but you could, as an ugly workaround for a font you cannot change, display ) as your opening delimiter and ( as your closing delimiter.

\newtagform{english}[\textenglish]%
{\textenglish{)}}%
{\textenglish{(}}
\usetagform{english}

Set English as Your Default Language

Then switch the current language to Arabic at the start of the document.

PS

As of 2020, an up-to-date distribution fixes the problem with the Simplified Arabic from Windows 10, but I could still reproduce it with certain other fonts, such as Noto Naskh Arabic.

2
  • Many thanks for your detailed answer, however I must use the Simplified Arabic font, and I have solved the problem by upgrading the version of my TexLive. I work on 2 machines, one with Win 10 and MikTex, no problem with parenthesis, and an Elementary OS one with the problem, switching to Manjaro and its more up to date packages fixed the problem May 15 '20 at 14:51
  • 1
    Great. I didn’t test this on a Windows box, but I found Noto Naskh Arabic has the same issue even in TeX Live 2020.
    – Davislor
    May 15 '20 at 16:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.