I have this LaTeX code:
Lorem $math$ ipsum $math$dolor sit consecteruer adipscing elit,
sed do eiusmod tempor incidunt ut labore et dolore magna aliqua.
$math$Ut $math$ enim ad minim veniam$math$, quis nostrum exercitationem
ullamco laboriosam, $math$nisi ut aliquid ex ea commodi consequatur$math$.
I want to split math from following and preceeding text, that's to say, I want to replace
$math$word
word$math$
with
$math$ word
word $math$
So, I have tried with the following:
M-x query-replace-regexp RET \$\([^$]+?\)\$\\([^\S]\) RET $\1$ \2
and
M-x query-replace-regexp RET \([^S]\)\$\([^$]+?\) RET \1 $\2$
The problem is that these regularx expressions match too much than it is necessary.
Indeed, first replacement matches
"$math$i"
"$math$d"
"$math$U"
"$math$ "
"$math$,"
"$math$n"
"$math$."
and only the first, second, third and sixth matches are necessary.
The second replacement matches:
" $math$"
" $math$"
"^J $match$"
" $math$"
"m$math$"
" $math$"
"r$math$"
and only the fifth and seventh matches are necessary.
How can I match only $math$word
and word$math$
?