I'm working on my bachelor's thesis on the Gibbs phenomenon and in one of my sources the following step is made during a proof of the existence of the Gibbs phenomenon for the ramp function: $$ \sum_{n=1}^{\infty}\int_{0}^{x}\cos(nt)\,\mathrm{d}t = \lim_{n\to\infty} \int_{0}^{x} \left( \frac{ 1 }{ 2 } + \sum_{k=1}^{n}\cos(kt)\right)\,\mathrm{d}t - \frac{x}{2}\,. $$ For some reason, I can't for the life of me figure out what the author did here. Obviously the series was moved inside of the integral, but where do the $\frac{1}{2}$ and $-\frac{x}{2}$ come from? Was a specific trig identity used here or what?
Any help or suggestions on possible sources to consult would be much appreciated.
The $\frac12$ and $\frac x2$ cancel, so I think that's a separate step to what the author did. It's a standard trick to add something, then subtract the same thing to make other simplifications possible down the line. My guess is that this is the reason for this manouver: either the $\frac12$ or the $\frac x2$ is going to be useful to simplify something else a few lines down.
As to the sum and integral, $\sum_{n = 1}^\infty$ by definition means $\lim_{k\to \infty}\sum_{n = 1}^k$ (and then for some reason he swapped $n$ and $k$ around). In any of these finite sums, you can without problem swap the order of $\sum$ and $\int$. What you can't do is change the order of $\int$ and $\lim$.