One of the great features of Emacs is its ability to handle bidirectional support for the right-to-left languages (like Hebrew, Arabic and Persian). Note that even in these languages mathematical formulae are written from left-to-right. So when typing a mathematical formula (usually between $ $) in a right-to-left line, it would be desirable to temporary force the direction left-to-right. For example in the following line I have written $V^*$ but Emacs shows it in reverse.
I know the setting
(setq bidi-paragraph-direction 'left-to-right) can be used to change to the correct direction. Also the variable
texmathp can be used to determine if the cursor is in a math environment (see how to detect if inside a LaTeX math environment? and https://emacs.stackexchange.com/a/548/2609).
But I don't know to put these altogether. So my question is
How to force the direction from right-to-left in a math environment?