# Evaluate $\int_0 ^x \frac{\sin\left(\frac{1}{2}-n\right) t}{\sin\frac{t}{2}}\,dt$.

Evaluate $$\int_0 ^x \frac{\sin\left(\frac{1}{2}-n\right) t}{\sin\frac{t}{2}}\,dt$$ for $x\in(0,2\pi)$ and $n\in\mathbb Z$. From trigonometric formulas, we have: $$\int_0 ^x\cos nt\, dt-\int_0 ^x \frac{\cos\frac{t}{2}}{\sin\frac{t}{2}}\, \sin nt\,dt$$ What can we say for the second integral? I was not able to solve it.

Only a partial answer for $n\in\mathbb{N}$, but maybe helpful nonetheless. Call $f_n(x)=\int_0^x dt \sin(nt)\cot(t/2)$ and consider the generating function $$F(z,x)=\sum_{n=0}^\infty f_n(x)z^n=\int_0^x dt\cot(t/2)\frac{\mathrm{i} \left(-1+e^{2 \mathrm{i} t}\right) z}{2 \left(-z+e^{\mathrm{i} t}\right) \left(-1+e^{\mathrm{i} t} z\right)}=$$ $$=-\frac{z}{2}\int_0^x dt\ \frac{\left(1+e^{\mathrm{i} t}\right)^2 }{\left(-z+e^{\mathrm{i} t}\right) \left(-1+e^{\mathrm{i} t} z\right)}\ ,$$ using the Euler's representation of the cotangent. The real part of it can be computed with the help of Mathematica, yielding eventually (for $0<x<2\pi$ and $|z|<1$) $$F(z,x)=-\frac{(x+\pi ) z+2 (z+1) \arctan\left(\frac{(z-1) \cot \left(\frac{x}{2}\right)}{z+1}\right)-x+\pi }{2 (z-1)}\ .$$ [This agrees with numerics]. The generating function can be represented as $$F(z,x)=\varphi\left(\frac{z-1}{z+1};x\right)+\frac{x}{z-1}\ ,$$ where $$\varphi(\xi,x)=-\frac{1}{\xi}\arctan(\xi\cot(x/2))-\frac{x+\pi}{2\xi}\ .$$ With any symbolic software, you can obtain a closed form solution for any $n$ by simply Taylor-expanding this result around $z=0$. For example: $$f_3(x)=x+2 \sin (x)+\sin (2 x)+\frac{1}{3} \sin (3 x)\ ,$$ and based on some experiments, one might conjecture a general form as $$f_n(x)=x+\sum_{k=1}^n \frac{n_k}{m_k}\sin(k x)\ ,$$ with $n_k$ and $m_k$ small integers. A closed-closed form solution might be obtained after some painstaking work on the generating function (using also the great simplification that $\arctan(\cot(x/2))=(\pi-x)/2$). But that's not for me tonight.
It is sufficient to consider an integral of the form $$\int \frac{\sin \left(\left(2k+1\right)t\right)}{\sin t}dt.$$ One has $$\frac {\sin\left(\left(2k+1\right)t\right)}{\sin t}=\frac{e^{i\left(2k+1\right)t}-e^{-i\left(2k+1\right)t}}{e^{it}-e^{-it}}=2\left[\cos 2kt +\cos \overline{2(k-1)}t + \cos \overline{2(k-2)}t + \cdot\cdot\cdot+\cos 2t \right]+1.$$ Each of the terms are easily integrated, but can't think of a further simplification.