I quote the Green Book by IUPAC, 2nd printing (2008), section 1.6, enumeration item 2:
The overall rule is that symbols representing physical quantities or variables are italic, but symbols representing units, mathematical constants, or labels, are roman. [...]
As such, the correct way to write it is $\ce{NO}_x$, because $x$ is a variable. Please note that it is only the sum formula for the compound and not its name. Since the element names still are in roman (upright) font, everything is fine.
The same goes for a formula like $\ce{C_{$n$}H_{$2n+2$}}$, which is typeset exactly like that in the Gold Book (hat tip to @Martin).
Here at StackExchange, you can type it as $\ce{NO_$x$}$
($\ce{NO_$x$}$) or $\ce{NO_x}$
($\ce{NO_x}$).