I'm facing an issue where the superscript and subscript do not align:
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:

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.

subandpowmacros? – Marcel Krüger May 03 '21 at 13:51\reflectboxtakes 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\mathdirectionto change the math direction? – Marcel Krüger May 03 '21 at 15:35\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