2

I'm facing an issue where the superscript and subscript do not align:

enter image description here

Now I'm using a command I defined to create this:

\newcommand{\pow}[2]{\ensuremath{\reflectbox{\ensuremath{{\reflectbox{\ensuremath{#1}}}^{\reflectbox{\ensuremath{#2}}}}}}}

\newcommand{\sub}[2]{\ensuremath{\reflectbox{\ensuremath{{\reflectbox{\ensuremath{#1}}}_{\reflectbox{\ensuremath{#2}}}}}}}

It's quite messy, but all it does is #1^#2 and then reflecting the whole thing, and then reflecting the individual symbols again.

Here's how I call the commands:

\[\sub{\pow{\iKaaf}{س}}{س}\]

iKaaf being the long shape--the base. Order matters. If I use pow before sub, the superscript and subscript would be pushed, just in reverse order. How could I fix this problem? Also, as a side-question, how could I make automatically scale the powers and subscripts? Using

\newcommand{\pow}[2]{\ensuremath{{{}^#2}#1}}
\newcommand{\sub}[2]{\ensuremath{{{}_#2}#1}}

works, but I cannot "nest" them into each other, since it creates problems such as these: enter image description here

when \[\pow{\lSeen}{\pow{\two}{\two}}\] is used.

EDIT: MWE.

\documentclass{article}

\usepackage{amsmath,amssymb} \usepackage{polyglossia} \usepackage{graphicx} \setmainlanguage{arabic} \setmainfont[Script=Arabic]{Amiri}

\input{commands} % where I get the pow and sub commands

\begin{document}

[\sub{\pow{\iKaaf}{س}}{س}]

\end{document}

I used egreg's answer in order to directly input Arabic in math mode.

  • Do you want right to left math in general or only for the sub and pow macros? – Marcel Krüger May 03 '21 at 13:51
  • @MarcelKrüger Really RTL math in general. I just don't understand why that specific macro isn't working well. – Bored Comedy May 03 '21 at 14:07
  • To understand why the specific macro doesn't work think about it in boxes: \reflectbox takes a box, reflects it and then outputs the reflected box. In your case you are reflecting it again, but that doesn't change that you wrapped your content in a box TeX can't really look into. So TeX more or less sees the \pow{\iKaaf}{س} as a rectangle corresponding to it's bounding box and places the subscript next to this box. – Marcel Krüger May 03 '21 at 15:34
  • Is there a reason why you aren't using the built-in \mathdirection to change the math direction? – Marcel Krüger May 03 '21 at 15:35
  • @MarcelKrüger Yes. My ignorance of such macro is the reason :) – Bored Comedy May 03 '21 at 20:20
  • Basically you need to use LuaLaTeX and then you can set \mathdir TRT. After that, your math should be in right-to-left. (It might confuse some packages though) (Disclaimer: I can neither read nor write any right to left language, so I don't have any experience with it. I would be interested to hear if it works for you though) – Marcel Krüger May 03 '21 at 20:48
  • @MarcelKrüger It works fine. It gives an error if I tried to use the XITS Math font when I try to import it using the unicode-math package, giving me errors like, "This is already defined by the amsmath or amssymb package." Eventually, I had to switch to using the Amiri font. Amiri doesn't have any RTL support for math, unlike the XITS math font, so I had to leave the amssymb and the Amiri font for the XITS math font. It works now. – Bored Comedy May 03 '21 at 23:17

0 Answers0