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?

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.
