1

I used this solution by a user Cicada from one of the questions on how to type Unicode characters in math mode:

\documentclass{article}

\usepackage{amsmath,amssymb}
\usepackage{polyglossia}
\setmainlanguage{arabic}

% Credits: Cicada's answer from https://bit.ly/3dpDg9t
\setmainfont[Script=Arabic]{Amiri}
\DeclareSymbolFont{arabicletters}{\encodingdefault}{Amiri(0)}{m}{n}
\newcommand{\makearabicmathletter}[1]{%
    \begingroup\lccode`a=#1\lowercase{\endgroup
    \Umathcode`a}="0 \csname symarabicletters\endcsname\space #1
}

% Normal Arabic Letters
\count255="0605
\loop\ifnum\count255<"064B
  \makearabicmathletter{\count255}
  \advance\count255 by 1
\repeat

% Arabic Mathematical Symbols!!!!!!
\count255="1EE00
\loop\ifnum\count255<"1EEBB
  \makearabicmathletter{\count255}
  \advance\count255 by 1
\repeat


\begin{document}
  \[ 
    \frac{م}{2؈} = ط
  \]

  \[\char126555 + م\]
\end{document}

The first loop seems to work well. I can directly type Arabic letters. However, since the latter loop deals with glyphs which don't exist on usual keyboards, my only chance of using them was to directly type in the character code. However it gave me an error:

! Bad character code (126555).
l.27 \char126555

Overleaf went as far as telling me that I can't use any character number above 65535. What should I do? And why did it work for Cicada, when they used Egyptian hieroglyphics, and not now?

EDIT: Credit where credit's due, the user egreg discovered the lccode trick.

1
  • 1
    It may be an Overleaf problem. Unrelated: the lcc trick is @egreg 's.
    – Cicada
    Apr 18, 2021 at 6:10

2 Answers 2

2

Apparently, XeTeX doesn't like \char in math mode. You can use \Umathchar instead, hidden in a macro for ease of use.

\documentclass{article}

\usepackage{amsmath,amssymb}
\usepackage{polyglossia}
\setmainlanguage{arabic}

% Credits: Cicada's answer from https://bit.ly/3dpDg9t
\setmainfont[Script=Arabic]{Amiri}
\DeclareSymbolFont{arabicletters}{\encodingdefault}{Amiri(0)}{m}{n}
\newcommand{\makearabicmathletter}[1]{%
    \begingroup\lccode`a=#1\lowercase{\endgroup
    \Umathcode`a}="0 \symarabicletters\space #1\relax
}

% Normal Arabic Letters
\count255="0605
\loop\ifnum\count255<"064B
  \makearabicmathletter{\count255}
  \advance\count255 by 1
\repeat

% Arabic Mathematical Symbols!!!!!!
\count255="1EE00
\loop\ifnum\count255<"1EEBB
  \makearabicmathletter{\count255}
  \advance\count255 by 1
\repeat

\newcommand{\achar}[1]{\Umathchar"0 \symarabicletters#1\relax}


\begin{document}
  \[ 
    \frac{م}{2؈} = ط
  \]
  \[\achar{126555} + م\]
\end{document}

enter image description here

2
  • Is there more documentation over this stuff, I find it kind of hidden and I have no idea from where it comes from. Apr 18, 2021 at 17:40
  • @BoredComedy \Umathcode is decribed in the XeTeX manual, texdoc xetex
    – egreg
    Apr 18, 2021 at 19:28
0

Code compiles OK in Lualatex under TexLive2020.

What is the output supposed to look like?

Arabic Maths

3
  • That's weird, yours seems ok. Perhaps it's a XeTeX problem? Apr 18, 2021 at 16:50
  • In Xelatex, use the glyph directly, ^^^^^1ee5b, instead of via the \char command.
    – Cicada
    Apr 19, 2021 at 2:45
  • For convenience, you can define named macros for the symbols, \newcommand\mghain{^^^^^1ee5b} and then use the name: \[\mghain + م\], if swapping over to Lualatex is not available as a choice.
    – Cicada
    Apr 19, 2021 at 2:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .