Solution (source code)

= Solution

Oddness gives zero cosine coefficients. Integration by parts gives the sine <Fourier coefficients>
$$
b_n=\frac2\pi\int_0^\pi x\sin(nx)\,dx=\frac{2(-1)^{n+1}}n,
\qquad \boxed{x=2\sum_{n=1}^\infty\frac{(-1)^{n+1}}n\sin(nx)\quad(-\pi<x<\pi).}
$$
The <Fourier series> of the piecewise smooth periodic extension converges to its value at interior continuity points. <Termwise integration> from 0 to $x$ is valid: on the interval between these points, which stays inside $(-\pi,\pi)$, the partial sums of $\sum(-1)^{n+1}\sin(nt)$ are uniformly bounded by the geometric-sum formula, since $|1+e^{it}|$ is bounded away from zero. The <Dirichlet test> therefore gives uniform convergence there. Integrating gives
$$
x^2=4\sum_{n=1}^\infty\frac{(-1)^{n+1}}{n^2}(1-\cos nx).
$$
The integrated series is absolutely and uniformly convergent. Consequently
$$
\boxed{a_n=\frac{4(-1)^n}{n^2}\ (n\ge1),\qquad a_0=8\sum_{n=1}^\infty\frac{(-1)^{n-1}}{n^2}.}
$$
Independently, the constant <Fourier coefficient> is $a_0=\pi^{-1}\int_{-\pi}^\pi x^2\,dx=2\pi^2/3$. Comparison yields
$$
\boxed{\sum_{n=1}^\infty\frac{(-1)^{n-1}}{n^2}=\frac{\pi^2}{12},\qquad x^2=\frac{\pi^2}{3}+4\sum_{n=1}^\infty\frac{(-1)^n}{n^2}\cos nx.}
$$
The original sine series is not uniformly convergent on the whole open interval; that stronger assertion is unnecessary for the justified integration.