Prove $ \sum_{n=1}^{2q-1}\frac{n}{q}\sin\left(\frac{\pi np}{q}\right)=-\cot\left(\frac{\pi p}{q}\right)-\csc\left(\frac{\pi p}{q}\right) $ For $p$ and $q$ are positive integers, $p < q$.
How to prove this identity?
$$
\sum_{n=1}^{2q-1}\frac{n}{q}\sin\left(\frac{n\pi p}{q}\right)=-\cot\left(\frac{\pi p}{q}\right)-\csc\left(\frac{\pi p}{q}\right)=-\cot\left(\frac{\pi p}{2q}\right)
$$
This identity is comprised by two parts.
$$
\sum_{n=1}^{q-1}\frac{2n}{q}\sin\left(\frac{2n\pi p}{q}\right)=-\cot\left(\frac{\pi p}{q}\right)\\
\sum_{n=1}^{q}\frac{(2n-1)}{q}\sin\left(\frac{(2n-1)\pi p}{q}\right)=-\csc\left(\frac{\pi p}{q}\right)
$$
I found these identities during the calculations when proving the other identity in my previous question by comparison. I am curious how to prove the identities in general ways.
I also found some other identities all by comparison like:
For $q$ is odd
$$
\sum_{n=1}^{(q-1)/2}\frac{2n}{q}\sin\left ( \frac{2n\pi p}{q} \right )=\frac{(-1)^{p-1}}{2}\csc\left( \frac{\pi p}{q} \right ) \\
\sum_{n=1}^{(q-1)/2}\frac{(2n-1)}{q}\sin\left ( \frac{(2n-1)\pi p}{q} \right )=\frac{(-1)^{p-1}}{2}\cot\left( \frac{\pi p}{q} \right ) \\
\sum_{n=1}^{(q-1)/2}2\sin\left ( \frac{2n\pi p}{q} \right )=\cot\left( \frac{\pi p}{q} \right )+(-1)^{p-1}\csc\left( \frac{\pi p}{q} \right ) \\
\sum_{n=1}^{(q-1)/2}2\sin\left ( \frac{(2n-1)\pi p}{q} \right )=\csc\left( \frac{\pi p}{q} \right )+(-1)^{p-1}\cot\left( \frac{\pi p}{q} \right )
$$
For $q$ is even
$$
\sum_{n=1}^{q/2}\frac{2n}{q}\sin\left ( \frac{2n\pi p}{q} \right )=\frac{(-1)^{p-1}}{2}\cot\left( \frac{\pi p}{q} \right ) \\
\sum_{n=1}^{q/2}\frac{(2n-1)}{q}\sin\left ( \frac{(2n-1)\pi p}{q} \right )=\frac{(-1)^{p-1}}{2}\csc\left( \frac{\pi p}{q} \right ) \\
\sum_{n=1}^{q/2}2\sin\left ( \frac{2n\pi p}{q} \right )=\cot\left( \frac{\pi p}{q} \right )+(-1)^{p-1}\cot\left( \frac{\pi p}{q} \right ) \\
\sum_{n=1}^{q/2}2\sin\left ( \frac{(2n-1)\pi p}{q} \right )=\csc\left( \frac{\pi p}{q} \right )+(-1)^{p-1}\csc\left( \frac{\pi p}{q} \right )
$$
How to prove them in general ways?
 A: Thanks to Mr. metamorphy's answer. I rearrange the proof to make it suitable for my question.
Let $\omega =e^{2\pi pi/q}$
\begin{align}
(\omega-1)\sum_{n=1}^{q}n\omega^n&=(\omega-1)\left(\sum_{n=1}^{q}\omega^n+\sum_{n=2}^{q}\omega^n+\sum_{n=3}^{q}\omega^n+\cdots \sum_{n=q}^{q}\omega^n  \right) \\
&=\omega(\omega^q-1)+\omega^2(\omega^{q-1}-1)+\omega^3(\omega^{q-2}-1)-1)+\cdots+\omega^q(\omega-1) \\
&=q\omega^{q+1}-\sum_{n=1}^{q}\omega^n=q\omega,\quad\text{since }\omega^q=1\text{ and }\sum_{n=1}^{q}\omega^n=0 \\
\sum_{n=1}^{q}\frac{n}{q}\omega^n&=\frac{\omega}{\omega-1},\quad\sum_{n=1}^{q}\frac{n}{q}\omega^{-n}=\frac{\omega^{-1}}{\omega^{-1}-1} \\
\sum_{n=1}^{q}\frac{2n}{q}\sin\left(\frac{2n\pi p}{q}\right)&=\sum_{n=1}^{q}\frac{2n}{q}\left(\frac{\omega^n-\omega^{-n}}{2i}\right)=\frac{1}{i}\left(\frac{\omega}{\omega-1}-\frac{\omega^{-1}}{\omega^{-1}-1}\right) \\
&=-\frac{1}{i}\left(\frac{1+\omega}{1-\omega}\right)=-\cot\left(\frac{\pi p}{q}\right) \\
\sum_{n=1}^{q}\frac{2n}{q}\cos\left(\frac{2n\pi p}{q}\right)&=\sum_{n=1}^{q}\frac{2n}{q}\left(\frac{\omega^n+\omega^{-n}}{2}\right)=\frac{\omega}{\omega-1}+\frac{\omega^{-1}}{\omega^{-1}-1} \\
&=\frac{\omega-1}{\omega-1}=1
\end{align}
Replace $q$ with $2q$,
$$
\sum_{n=1}^{2q}\frac{n}{q}\sin\left(\frac{n\pi p}{q}\right)=-\cot\left(\frac{\pi p}{2q}\right)=-\cot\left(\frac{\pi p}{q}\right)-\csc\left(\frac{\pi p}{q}\right)
$$
A: Computationally, I could transform the sum $\sum _{n=1}^{2 q-1} \frac{n \sin \left(\frac{\pi  n p}{q}\right)}{q}$ to the following term:
$$
\frac{1}{4} \csc \left(\frac{p \pi }{2 q}\right) \left(-4 \cos \left(\frac{1}{2} p \pi  \left(4-\frac{1}{q}\right)\right)+\frac{\csc \left(\frac{p \pi }{2 q}\right) \sin (2 p \pi )}{q}\right)
$$
Here conversions to exponential forms (which are expanded back to trigonometric forms) internally occurred. One can retrace it using Wolfram:
Trace[FullSimplify[Sum[(n/q)*Sin[Pi*n*p/q], {n, 1, 2 q - 1}]], 
 TraceInternal -> True]

This looks like a (possibly hard) pathway to obtain the identity given in the question. Interestingly, when setting $p=1$, we obtain a much simpler term:
$$
\sum _{n=1}^{2 q-1} \frac{n \sin \left(\frac{\pi  n}{q}\right)}{q}=-\cot \left(\frac{\pi }{2 q}\right)
$$
Running $q$ from $0$ to $2\pi$, the plot of the sum $\sum _{n=1}^{2 q-1} \frac{n \sin \left(\frac{\pi  n}{q}\right)}{q}$ looks as follows:

The Partial Fractions Expansion of Cotangent has been elaborated by this MSE Post or by this Proof Wiki Page.
