The objective is to find the Fourier series for $|x|$ in the range $-\pi \le x \lt \pi$ so I started by finding the Fourier coefficients:
$$a_0=\frac{1}{\pi}\int_{x=-\pi}^{\pi}|x|\mathrm{d}x=\frac{2}{\pi}\int_{x=0}^{\pi}x\mathrm{d}x=\pi$$
$$a_n=\frac{1}{\pi}\int_{x=-\pi}^{\pi}|x|\cos(nx)\mathrm{d}x=\frac{2}{\pi}\int_{x=0}^{\pi}x\cos(nx)\mathrm{d}x=\frac{2\left((-1)^n-1\right)}{\pi n^2}$$
Then using the general Fourier series expansion: $$f(x)=\frac{a_0}{2}+ \sum_{n=1}^{n=\infty}\left(a_n\cos\left(\frac{2\pi n x}{L}\right)+b_n\sin\left(\frac{2\pi n x}{L}\right)\right) \tag{1}$$ where $2L$ is the period of the function and noting that $f(x)=|x|$ is even so $b_n=0$ such that only the cosine terms contribute to the sum. Insertion of $a_0$ and $a_n$ into $(1)$ yields $$f(x) = |x| =\frac{\pi}{2}+\frac{2}{\pi}\sum_{n=1}^{\infty}\frac{\left((-1)^n-1\right)\cos(nx)}{n^2}\tag{A}$$ I can tell you from this that $(\mathrm{A})$ is correct and I just need to show it is equal to $$\frac{\pi}{2} - \frac{4}{\pi}\sum\limits_{k=0}^\infty\frac{\cos\left((2k+1)x\right)}{(2k+1)^2}\tag{B}$$ where $k$ is an integer, but I don't know how to. The calculation here doesn't show the steps to get from $(\mathrm{A})$ to $(\mathrm{B})$. Could someone please show me these steps to complete the proof?
Thank you.
\begin{align} \sum_{n=1}^{\infty}\frac{\left((-1)^n-1\right)\cos(nx)}{n^2}&=\sum_{n \text{ is odd}}\frac{\left((-1)^n-1\right)\cos(nx)}{n^2}+\sum_{n \text{ is even}}\frac{\left((-1)^n-1\right)\cos(nx)}{n^2}\\ &=\sum_{n=1}^{\infty}\frac{\left((-1)^{2n-1}-1\right)\cos((2n-1)x)}{(2n-1)^2}+\sum_{n=1}^{\infty} \frac{\left((-1)^{2n}-1\right)\cos((2n)x)}{(2n)^2}\\ &=\sum_{n=0}^{\infty}\frac{\left(-1-1\right)\cos((2n+1)x)}{(2n+1)^2}+\sum_{n=1}^{\infty} \frac{\left(1-1\right)\cos((2n)x)}{(2n)^2}\\ &=-2\sum_{n=0}^{\infty}\frac{\cos((2n+1)x)}{(2n+1)^2}+0\\ \end{align}