In the following sentence
If all $f(x_j), j=1,\dots,N$ are positive, then ...
Do you think there should be a comma after the $N$? I always considered the math as a single unit and read the sentence as
If all [MATH] are positive, then ...
Accordingly I only put commas when the surrounding sentence required them, as in
Given $f(x_j), j=1,\dots,N$, our goal is to ...
I am asking because I observed a lot of authors not following my thinking. However, there are also some that more or less do put the commas as I do, so I wondered if you know about guidelines regarding this question or simply have a definite opinion about it.
To summarise those comments with which I agree: the following are preferable.
A little more clumsy: