Formula/mathematical expression for PWM
I was looking for an answer to the same question. With help of your picture with the carrier and comparator, I might have a solution:

In time domain, a sawtooth wave can be described as:
$$
sawtooth (t) = A \cdot \biggl( \dfrac{t} {T} - \text{floor} \Bigl( \dfrac{t} {T} \Bigr) \biggr)
$$

where \$t\$ is the time, \$T\$ the period and \$A\$ the amplitude.

(Probably superfluous, \$\text{floor}(x)\$ rounds \$x\$ down to the closest integer, e.g. \$\text{floor}(2.75)=2\$ ). 

For the purpose of comparison (the comparator of your picture), both signals should between the same values, let's choose 0 and 1. (You could also choose -1 and 1).

Therefore, for the carrier signal, choose amplitude \$A = 1\$ and period \$ T = \dfrac{1} {F_{carrier}} \$

$$
carrier(t) = \biggl( F_{carrier} \cdot t - \text{floor} \bigl( F_{carrier} \cdot t \bigr) \biggr)
$$

Next, the message signal needs to be fit between 0 and 1. In case of \$\sin(t)\$ this becomes

$$ message(t) = \dfrac{1} {2} + \dfrac{1} {2} \sin(t) $$

The comparator function can mathematically be expressed using \$\text{sgn}(x)\$, so the pulse width modulated wave becomes

$$ pwm(t) = \text{sgn} \Bigl( message(t)-carrier(t) \Bigr)$$



I used this to describe an Arbitrary Behavioral Voltage Source in Spice. I needed to adjust the simulation step size to 1/100 of the the carried period time to get decent results.

You can also express a sawtooth wave as function of arctan and cot, check:


Wikipedia: Sawtooth wave
Wikipedia: Sign function
Wikipedia:Floor and ceiling functions