I found the Fourier series $$ f(x)=\frac{4k}{\pi}\sum_{n \text{ odd}}^{\infty}\frac{1}{n}\sin(n x) \tag 1 $$ for the square wave function $$ f(x)= \begin{cases} \begin{align} -k, \quad -\pi <x<0\\ k, \quad 0<x<\pi \end{align} \end{cases} $$ But the answer is written as $$ f(x)=\frac{4k}{\pi}\sum_{n=1}^{\infty}\frac{1}{2n-1}\sin(2n-1)x \tag 2 $$
How can I find $(2)$ from $(1)$?
This is your sum:$\displaystyle f(x)=\frac{4k}{\pi}\sum_{n \text{ odd}}^{\infty}\frac{1}{n}\sin(n x) \tag 1 $ As it clearly states, for odd $n$ this summation have to be calculated.
So we say for odd $n$ we have: $n=2i-1$ where $i=1,2,...$
By substituting this into our summation we have: $$\begin{align} \displaystyle f(x)=\frac{4k}{\pi}\sum_{i=1}^{\infty}\frac{1}{2i-1}\sin((2i-1) x) \end{align}$$ Or in another notation:
$\displaystyle f(x)=\frac{4k}{\pi}\sum_{n=1}^{\infty}\frac{1}{2n-1}\sin((2n-1) x) \tag 2 $