<s>[INST] Finding $\int_0^{\frac{\pi}{2}} \frac{x}{\sin x} dx $ Is there a way to show $$\int_0^{\frac{\pi}{2}} \frac{x}{\sin x} dx = 2C$$ where $C=\sum_{n=0}^{\infty} \frac{(-1)^n}{(2n+1)^2} $ is Catalan’s constant, preferably without using complex analysis?
The following is an attempt to expand it as as a series:
\begin{align*}
\int_0^{\frac{\pi}{2}} \frac{x}{\sin x} dx
&= \int_0^{\frac{\pi}{2}} \frac{x}{1-\cos^2 x}\sin x\  dx \\
&= \sum_{n=0}^{\infty} \int_0^{\frac{\pi}{2}} x\sin x \ \cos^{2n}x \ dx \\
&= \sum_{n=0}^{\infty}\frac{1}{2n+1} \int_0^{\frac{\pi}{2}} \cos^{2n+1}x \ dx \\
&= \sum_{n=0}^{\infty} \frac{4^n}{\binom{2n}{n}(2n+1)^2}
\end{align*}
which is close but not quite there.
 [/INST] 1st Solution. Applying the Weierstrass substitution $t=\tan(x/2)$, it follows that
\begin{align*}
\int_{0}^{\frac{\pi}{2}} \frac{x}{\sin x} \, \mathrm{d}x
&= \int_{0}^{1} \frac{2\arctan(t)}{2t/(1+t^2)} \, \frac{2\mathrm{d}t}{1+t^2}
= 2 \int_{0}^{1} \frac{\arctan t}{t} \, \mathrm{d}t.
\end{align*}
Now note that we have
$$ \frac{\arctan(t)}{t} = \sum_{n=0}^{\infty} \frac{(-1)^n}{2n+1} t^{2n} $$
for $-1 \leq t \leq 1$. So by the Abel's theorem, its integral from $0$ to $1$ can be computed by performing term-wise integration. (In other words, we can interchange the order of infinite summation and integral.) This yields
\begin{align*}
\int_{0}^{\frac{\pi}{2}} \frac{x}{\sin x} \, \mathrm{d}x
&= 2 \sum_{n=0}^{\infty} \frac{(-1)^n}{2n+1} \int_{0}^{1} t^{2n} \, \mathrm{d}t 
= 2 \sum_{n=0}^{\infty} \frac{(-1)^n}{(2n+1)^2} 
= 2C.
\end{align*}

2nd Solution. Using $\sin x = (e^{ix} - e^{-ix})/2i$, the integral is recast as
$$ \int_{0}^{\frac{\pi}{2}} \frac{x}{\sin x} \, \mathrm{d}x
= \frac{2}{i} \int_{0}^{\frac{\pi}{2}} \frac{xe^{ix}}{1 - e^{2ix}} \, \mathrm{d}x. $$
To expand the integrand, se adopt the following regularization:
$$ \int_{0}^{\frac{\pi}{2}} \frac{xe^{ix}}{1 - e^{2ix}} \, \mathrm{d}x
= \lim_{r \to 1^-} \int_{0}^{\frac{\pi}{2}} \frac{xe^{ix}}{1 - re^{2ix}} \, \mathrm{d}x $$
(This limit is easily verified by the dominated convergence theorem.) Now taking advantage of the fact taht $|re^{2ix}| < 1$, we can invoke the geometric series formula to expand
\begin{align*}
\int_{0}^{\frac{\pi}{2}} \frac{xe^{ix}}{1 - re^{2ix}} \, \mathrm{d}x
&= \int_{0}^{\frac{\pi}{2}} xe^{ix} \sum_{n=0}^{\infty} \bigl( re^{2ix} \bigr)^n \, \mathrm{d}x \\
&= \sum_{n=0}^{\infty} r^n \int_{0}^{\frac{\pi}{2}} xe^{(2n+1)ix} \, \mathrm{d}x \\
&= \sum_{n=0}^{\infty} r^n \left( \frac{\pi}{2} \cdot \frac{(-1)^n}{2n+1} - \frac{1}{(2n+1)^2} + \frac{(-1)^n}{(2n+1)^2}i \right)
\end{align*}
Letting $ r \to 1^-$, by the Abel's theorem, the limit can be computed term-wise to yield
\begin{align*}
\int_{0}^{\frac{\pi}{2}} \frac{x}{\sin x} \, \mathrm{d}x
&= \frac{2}{i} \sum_{n=0}^{\infty} \left( \frac{\pi}{2} \cdot \frac{(-1)^n}{2n+1} - \frac{1}{(2n+1)^2} + \frac{(-1)^n}{(2n+1)^2}i \right) \\
&= \frac{2}{i} \biggl( \frac{\pi^2}{8} - \sum_{n=0}^{\infty} \frac{1}{(2n+1)^2} \biggr) + 2C
\end{align*}
However, since the integral is real-valued, the imaginary part must vanish. Therefore we obtain the desired identity as well as a lucky by-product:
$$ \int_{0}^{\frac{\pi}{2}} \frac{x}{\sin x} \, \mathrm{d}x = 2C
\qquad\text{and}\qquad
\sum_{n=0}^{\infty} \frac{1}{(2n+1)^2} = \frac{\pi^2}{8}. $$
</s>