fourier sine series representation 
Represent $\phi(x)$ on $[0,\pi]$ using Fourier sine series, where $$\phi(x)=\frac{\pi}{2}-|x-\frac{\pi}{2}|$$

Definition: suppose f(x) is a periodic function with period 2L and f(x) is piecewise differentiable on $[-L,L]$. Then f(x) has a Fourier series representation $$f(x)=\sum_{i=1}^{\infty} B_n sin(\frac{n \pi x}{L})$$
I am supposed to integrate $$[\frac{\pi}{2}-|x-\frac{\pi}{2}|] sin(nx)$$ over $[0,\pi]$, then the rest is simply integration by parts right?
 A: Taking in account odd character of the sine series, the presentation of the given function is
$$ f(x) =
\begin{cases}
-x-\pi,\quad\text{if}\quad x\in\left[-\pi,-\dfrac\pi2\right]\\[4pt]
x,\quad\text{if}\quad x\in\left[-\dfrac\pi2,\dfrac\pi2\right]\\[4pt]
\pi-x,\quad\text{if}\quad x\in\left[\dfrac\pi2,\pi\right],
\end{cases}$$
wherein the derivative
$$g(x)=f'(x) =
\begin{cases}
-1,\quad\text{if}\quad x\in\left[-\pi,-\dfrac\pi2\right]\\[4pt]
1,\quad\text{if}\quad x\in\left[-\dfrac\pi2,\dfrac\pi2\right]\\[4pt]
-1,\quad\text{if}\quad x\in\left[\dfrac\pi2,\pi\right],
\end{cases}$$
is an even function.
Therefore,
$$g(x) = a_0 + 2\sum\limits_{n=1}^\infty a_n\cos nx,\quad\text{where}$$
$$a_n=\dfrac1\pi\int\limits_0^\pi g(x)\cos nx \,\mathrm dx,$$
$$a_{2k} = 0\quad\text{by symmetry},$$
\begin{align}
&\pi a_{2k+1} = \int\limits_0^{\large\,^\pi/_2} \cos(2k+1)x \,\mathrm dx -\int\limits_{\large\,^\pi/_2}^\pi \cos(2k+1)x \,\mathrm dx\\[4pt] 
&= \dfrac1{2k+1}\left(\sin(2k+1)x\bigg|_0^{\large^\pi/_2} - \sin(2k+1)x\bigg|_{\large^\pi/_2}^\pi\right) = \dfrac2{2k+1}.\\[8pt]
&\text{Finally,}\\[4pt]
& f(x) = \dfrac4\pi \sum\limits_{n=1}^\infty\dfrac1{2k+1} \int\limits_0^x \cos(2k+1)x \,\mathrm dx = 
\color{brown}{\mathbf{\dfrac4\pi \sum\limits_{n=1}^\infty\dfrac{\sin(2k+1)x}{(2k+1)^2}}}.
\end{align}
