Show that $\int_{-\infty}^{\infty} \frac{\cos (\theta) e^{\theta y}}{2 \cosh(\pi y/2)} y dy=\tan (\theta)$. I'm not a hardcore mathematician. I have exhausted all integration trick I learned in calculus including change of variables, integration by parts. That cosh on denominator is just very much in the way. How one should approach an integral like this. 
 A: 
How one should approach an integral like this.

Lots of ways - but trying to find an antiderivative isn't one of them.
We need $|\theta| < \frac{\pi}{2}$ for the integral to converge, so that the $\cosh$ in the denominator will be large enough to overwhelm the $e^{\theta y}$ in the numerator.
First thought: complex analysis. Close the loop around some large chunk of the complex plane, treat it as a contour integral, and apply the residue theorem. Looking at our function, in the imaginary direction, $\cosh\left(\frac{\pi}{2}y\right)$ and $e^{\theta y}$ are both periodic. That suggests we use a rectangle that doesn't go too high. From $\cosh(t+i\pi) = -\cosh t$, we integrate around a rectangle with height $2$. The vertical segments at $\pm R$ go to zero as $R\to\infty$, and
$$\int_{-\infty}^{\infty}\frac{\cos\theta\cdot e^{\theta y}}{2\cosh\frac{\pi y}{2}}\cdot y\,dy - \int_{-\infty}^{\infty}\frac{\cos\theta\cdot e^{\theta (y+2i)}}{2\cosh\frac{\pi (y+2i)}{2}}\cdot (y+2i)\,dy = 2\pi i\text{Res}_{z=i}(f)=2\pi i\frac{i\cos\theta e^{i\theta}}{\pi\sinh\frac{\pi i}{2}}$$
$$I(\theta) + e^{2i\theta}I(\theta) +2i\cos\theta e^{2i\theta}\int_{-\infty}^{\infty} \frac{e^{\theta y}}{2\cosh\frac{\pi y}{2}}\,dy = 2i\cos\theta e^{i\theta}$$
$$2\cos(\theta)I(\theta) = 2i\cos\theta\left(1-e^{i\theta}\int_{-\infty}^{\infty}\frac{e^{\theta y}}{2\cosh\frac{\pi y}{2}}\,dy\right)$$
Now, we need to evaluate that integral with a $\cosh$ in the denominator but no multiplication by $y$. How? Just do the same thing again - integrate around the same rectangular contour.
$$\int_{-\infty}^{\infty}\frac{e^{\theta y}}{2\cosh\frac{\pi y}{2}}\,dy - \int_{-\infty}^{\infty}\frac{e^{\theta (y+2i)}}{2\cosh\frac{\pi (y+2i)}{2}}\,dy = 2\pi i\text{Res}_{z=i}(g) = 2\pi i\frac{e^{i\theta}}{\pi i}$$
$$\left(1+e^{2i\theta}\right)\int_{-\infty}^{\infty}\frac{e^{\theta y}}{2\cosh\frac{\pi y}{2}}\,dy = 2e^{i\theta}$$
$$\int_{-\infty}^{\infty}\frac{e^{\theta y}}{2\cosh\frac{\pi y}{2}}\,dy = \frac1{\cos\theta}$$
Substituting that in,
$$I(\theta) = i\left(1-e^{i\theta}\cdot\frac1{\cos\theta}\right) = i\left(1-\frac{\cos\theta+i\sin\theta}{\cos\theta}\right)=\tan\theta$$
Done.
OK, I did a bunch of things without really explaining them. Let's go through them. First, the residue theorem is an enormously useful calculation tool from complex analysis, allowing us to calculate exact values for many integrals without finding antiderivatives. I've linked a part of the article with an example of such a calculation.
In this case, we use a rectangular contour with endpoints at $-R,R,R+2i,-R+2i$ and then let $R\to\infty$. On the vertical segments from $R$ to $R+2i$ and $-R+2i$ to $-R$, the function we're integrating at is comparable to $\frac{Re^{\pm R\theta}}{e^{R\theta}}$, which decays exponentially. In the limit, those vertical segments don't affect the integral. On the horizontal segments, we traverse the boundary counterclockwise, so the segment from $-R$ to $R$ is traversed "forward" with a $+$ sign and the segment from $-R+2i$ to $R+2i$ is traversed "backward" with a $-$ sign.
Then, we calculate the residues at the poles of the function we're integrating. The only way we can get a pole here is for that denominator $\cosh (\pi y/2) = \cos(i\pi y/2)$ to be zero - which, inside our contour, happens at exactly one point $y=i$. The calculation shortcut I used for the residue: evaluate the other parts at that point, divide by the derivative of the term in the denominator that goes to zero.
Also, I named the integral we wanted to find $I(\theta)$. That's just a notational convenience, but it is a definition that needs to be written down somewhere.
There are likely other approaches that work. If someone wants to try them, be my guest.
A: Note that the integral converges iff $\operatorname{Re}(\theta) \in (-\pi/2,\pi/2)$. You can use differentiation under the integral sign and the substitution $\mathrm{e}^{y} = x$ to get
\begin{align} 
\int \limits_{-\infty}^\infty \frac{\cos(\theta) \mathrm{e}^{\theta y}y}{2 \cosh(\pi y/2)} \, \mathrm{d} y &= \cos(\theta) \frac{\mathrm{d}}{\mathrm{d} \theta} \int \limits_{-\infty}^\infty \frac{\mathrm{e}^{\theta y}}{2 \cosh(\pi y/2)} \, \mathrm{d} y = \cos(\theta) \frac{\mathrm{d}}{\mathrm{d} \theta} \int \limits_0^\infty \frac{x^{\theta - 1}}{x^{\pi/2} + x^{-\pi/2}} \, \mathrm{d} x \\
&= \cos(\theta) \frac{\mathrm{d}}{\mathrm{d} \theta} \int \limits_0^\infty \frac{x^{\frac{\pi}{2} + \theta - 1}}{1 + x^{\pi}} \, \mathrm{d} x \, . 
\end{align}
A more general form of the final integral has already been computed here . If you plug in the parameters from your integral, you should arrive at the desired result.
A: Here is a real method.
Let
$$I = \int_{-\infty}^\infty \frac{\cos \theta \, e^{\theta y} \, y}{2 \cosh \left (\frac{\pi y}{2} \right )} \, dy,$$
where $\theta \in (-\pi/2, \pi/2)$.
Now
$$I = \frac{\cos \theta}{2} \int_{-\infty}^0 \frac{y e^{\theta y}}{\cosh \left (\frac{\pi y}{2} \right )} \, dy + \frac{\cos \theta}{2} \int_0^\infty \frac{y e^{\theta y}}{\cosh \left (\frac{\pi y}{2} \right )} \, dy = I_1 + I_2.$$
In the first of the integrals, enforcing a substitution of $y \mapsto -y$ gives
\begin{align}
I_1 &= -\frac{\cos \theta}{2} \int_0^\infty \frac{y e^{-\theta y}}{\cosh \left (\frac{\pi y}{2} \right )} \, dy\\
&= -\cos \theta \int_0^\infty \frac{y e^{-\theta y}}{e^{\frac{\pi y}{2}} + e^{-\frac{\pi y}{2}}} \, dy \tag1\\
&= -\cos \theta \int_0^\infty \frac{y e^{-\theta y - \pi y/2}}{1 + e^{-\pi y}} \, dy\\
&= -\cos \theta \sum_{n = 0}^\infty (-1)^n \int_0^\infty y e^{-(n \pi + \pi/2 + \theta)} \, dy \tag2\\
&= -\cos \theta \sum_{n = 0}^\infty \frac{(-1)^n}{(n \pi + \pi/2 + \theta)^2} \tag3\\
&= -\frac{\cos \theta}{\pi^2} \sum_{n = 0}^\infty \frac{(-1)^n}{(n + \frac{1}{2} + \frac{\theta}{\pi})^2}\\
&= -\frac{\cos \theta}{\pi^2} \sum_{\substack{n = 0\\n \in \text{even}}}^\infty \frac{1}{\left (n + \frac{1}{2} + \frac{\theta}{\pi} \right )^2} - \frac{\cos \theta}{\pi^2} \sum_{\substack{n = 0\\n \in \text{odd}}}^\infty \frac{1}{\left (n + \frac{1}{2} + \frac{\theta}{\pi} \right )^2}\\ 
&= -\frac{\cos \theta}{4 \pi^2} \sum_{n = 0}^\infty \frac{1}{\left (n + \frac{1}{4} + \frac{\theta}{2 \pi} \right )^2} - \frac{\cos \theta}{4 \pi^2} \sum_{n = 0}^\infty \frac{1}{\left (n + \frac{3}{4} + \frac{\theta}{2 \pi} \right )^2} \tag4\\
&= -\frac{\cos \theta}{4 \pi^2} \left [\psi^{(1)} \left (\frac{\theta}{2 \pi} + \frac{1}{4} \right ) - \psi^{(1)} \left (\frac{\theta}{2 \pi} + \frac{3}{4} \right ) \right ] \tag5 
\end{align}
In a similar manner, for the second of the integrals it can be shown that
$$I_2 = \frac{\cos \theta}{4 \pi^2} \left [\psi^{(1)} \left (\frac{1}{4} - \frac{\theta}{2 \pi} \right ) - \psi^{(1)} \left (\frac{3}{4} - \frac{\theta}{2 \pi} \right ) \right ].$$
Thus
\begin{align}
I &= -\frac{\cos \theta}{4 \pi^2} \left [\psi^{(1)} \left [1 - \left (\frac{3}{4} - \frac{\theta}{2 \pi} \right ) \right ] + \psi^{(1)} \left (\frac{3}{4} - \frac{\theta}{2 \pi} \right ) \right ]\\
& \qquad \quad + \frac{\cos \theta}{4 \pi^2} \left [\psi^{(1)} \left [1 - \left (\frac{1}{4} - \frac{\theta}{2 \pi} \right ) \right ] + \psi^{(1)} \left (\frac{1}{4} - \frac{\theta}{2 \pi} \right ) \right ]\\
&= -\frac{\cos \theta}{4 \pi^2} \left [\pi^2 \operatorname{cosec}^2 \left (\frac{3 \pi}{4} - \frac{\theta}{2} \right ) - \pi^2 \operatorname{cosec}^2 \left (\frac{\pi}{4} - \frac{\theta}{2} \right ) \right ] \tag6\\
&= -\frac{\cos \theta}{4} \left (\frac{2}{\sin \theta + 1} + \frac{2}{\sin \theta - 1} \right )\\
&= -\frac{\cos \theta}{4} \cdot -\frac{4 \sin \theta}{\cos^2 \theta},
\end{align}
or finally
$$\int_{-\infty}^\infty \frac{\cos \theta \, e^{\theta y} \, y}{2 \cosh \left (\frac{\pi y}{2} \right )} \, dy = \tan \theta,$$
as required.

Explanation
(1) Using $\cosh x = (e^x + e^{-x})/2$.
(2) Geometric expansion.
(3) Integration by parts twice.
(4) Shifting of the indices. Here $n \mapsto 2n$ for $n$ even and $n \mapsto 2n + 1$ for $n$ odd.
(5) Using the series representation for the polygamma function.
(6) Using the reflexion relation for the trigamma function.
