Solution (source code)

= Solution

The <Fourier sine series> coefficients of $x$ on $(0,\pi)$ are
$$
b_n=\frac2\pi\int_0^\pi x\sin(nx)\,dx=\frac{2(-1)^{n+1}}n,
$$
by <integration by parts>. The odd periodic extension is piecewise smooth, so the <Fourier series> converges to $x$ at every interior point. Hence
$$
\boxed{x=2\sum_{n=1}^{\infty}\frac{(-1)^{n+1}}n\sin(nx),\qquad 0<x<\pi.}
$$
To justify integration from zero, the <Fourier sine series> partial sums converge to $x$ in <L2 norm>. By the <Cauchy-Schwarz inequality>, integration from zero to any $x\in[0,\pi]$ has error at most $\sqrt\pi$ times that <L2 norm> error, uniformly in $x$. Integrating the partial sums and taking the limit therefore gives
$$
\frac{x^2}{2}=2\sum_{n=1}^{\infty}\frac{(-1)^{n+1}}{n^2}(1-\cos nx).
$$
The integrated <series> is absolutely and uniformly convergent, since its terms are bounded by $4/n^2$. Thus the resulting <Fourier cosine series> has
$$
\boxed{a_n=\frac{4(-1)^n}{n^2}\quad(n\ge1),\qquad a_0=8\sum_{n=1}^{\infty}\frac{(-1)^{n-1}}{n^2}.}
$$
Independently, the constant coefficient is
$$
a_0=\frac2\pi\int_0^\pi x^2\,dx=\frac{2\pi^2}{3}.
$$
Comparison yields the requested exact sum
$$
\boxed{\sum_{n=1}^{\infty}\frac{(-1)^{n-1}}{n^2}=\frac{\pi^2}{12}.}
$$