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\lccodea=#1\lowercase{\endgroup \Umathcodea}="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.

2 Answers2

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\lccodea=#1\lowercase{\endgroup \Umathcodea}="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

egreg
  • 1,121,712
0

Code compiles OK in Lualatex under TexLive2020.

What is the output supposed to look like?

Arabic Maths

Cicada
  • 10,129
  • That's weird, yours seems ok. Perhaps it's a XeTeX problem? – Bored Comedy Apr 18 '21 at 16:50
  • In Xelatex, use the glyph directly, ^^^^^1ee5b, instead of via the \char command. – Cicada Apr 19 '21 at 02: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 '21 at 02:53