<s>[INST] What to do to calculate $\int_{-\pi/4}^{+\pi/4}e^{-\tan\theta}\mathrm{d}\theta$ 
*

*I have to calculate the following integral:
$$A=\int_{-\pi/4}^{+\pi/4}e^{-\tan\theta}\mathrm{d}\theta.$$
What I did:
Let $t=\tan\theta$. Thus, $\dfrac{\mathrm{d}t}{\mathrm{d}\theta}=1+\tan^2\theta=1+t^2.$
Therefore, 
$$A=\int_{-1}^{+1}\dfrac{e^{-t}}{1+t^2}\mathrm{d}t.$$
Now, I write $\dfrac{1}{1+t^2}=\sum\limits_{k=0}^{\infty}(-t^2)^k.$
And therefore, $$A=\int_{-1}^{+1}\sum\limits_{k=0}^{\infty}(-1)^k t^{2k}e^{-t}\mathrm{d}t.$$
What to do now?

*Also, what to do to calculate $$B=\int_{\pi/4}^{\pi/2}e^{-\tan\theta}\mathrm{d}\theta.$$
Should I do the same as the previous case?
Thanks.
 [/INST] Consider the transformation $t = \tan\theta$ for which the integral in question becomes
\begin{align}
I &= \int_{a}^{b} e^{- \tan\theta} d\theta \\
&= \int_{x}^{y} \frac{ e^{-t} \ dt}{1+t^{2}}.
\end{align}
where $x=\tan a$ and $y=\tan b$. Now consider 
\begin{align}
\frac{1}{1+t^{2}} = \frac{i}{2} \left( \frac{1}{i+t} + \frac{1}{i -t} \right)
\end{align}
for which the integral $I$ becomes
\begin{align}
I &= \frac{i}{2} \int_{x}^{y} \left( \frac{e^{-t}}{i+t} + \frac{e^{-t}}{i-t} \right) \ dt \\
&= \frac{i}{2} \left[ e^{i} \ \int_{i+x}^{i+y} \frac{e^{-u} \ du}{u} - e^{-i} \ \int_{i-x}^{i-y}
 \frac{e^{-u} \ du}{u} \right] \\
&= \frac{i}{2} \left[ e^{i} Ei(-t-i) - e^{-i} Ei(i-t) \right]_{x}^{y} \\
&= \frac{i}{2} \left[ e^{i} \left( Ei(-\tan b - i) - Ei(-\tan a - i) \right) \right. \nonumber\\ 
& \hspace{15mm} \left. - e^{-i} \left( Ei(i-\tan b ) - Ei(i -\tan a) \right) \right].
\end{align}
which is
\begin{align}
\int_{a}^{b} e^{- \tan\theta} d\theta &= \frac{i}{2} \left[ e^{i} \left( Ei(-\tan b - i) - 
Ei(-\tan a - i) \right) \right. \nonumber\\ 
& \hspace{15mm} \left. - e^{-i} \left( Ei(i-\tan b ) - Ei(i -\tan a) \right) \right].
\end{align}
In the case that $-a = b = \pi/4$ then this becomes
\begin{align}
\int_{-\pi/4}^{\pi/4} e^{- \tan\theta} d\theta &= \frac{i}{2} \left[ e^{i} \left( Ei(-1 - i) - 
Ei(1 - i) \right) \right. \nonumber\\ 
& \hspace{15mm} \left. - e^{-i} \left( Ei(i-1 ) - Ei(i +1) \right) \right].
\end{align}
Using 
\begin{align}
-1-i &= - \sqrt{2} e^{\pi i/4} \\
1-i &= \sqrt{2} e^{-\pi i/4} \\
-1+i &= \sqrt{2} e^{-\pi i/4} \\
1+i &= \sqrt{2} e^{\pi i/4}
\end{align}
and the series form of the Exponential integral
\begin{align}
Ei(x) = \gamma + \ln|x| + \sum_{k=1}^{\infty} \frac{x^{k}}{k \cdot k!}
\end{align}
then after some reductions it is seen that
\begin{align}
\int_{-\pi/4}^{\pi/4} e^{- \tan\theta} d\theta = - \frac{\pi}{2} \cos(1) - 2 \sum_{k=1}^{\infty}
\frac{2^{k/2}}{k \cdot k!} \ \cos\left( \frac{k \pi}{2} +1\right) \ \sin\left( \frac{3 k \pi}{4} 
\right).
\end{align}
In a similar manor when $b = \pi/2$ and $a = - \pi/4$ the resulting form, in series, is
\begin{align}
\int_{-\pi/4}^{\pi/2} e^{- \tan\theta} d\theta &= \left( \gamma + \frac{1}{2} \ln(2) \right) \sin(1) 
- \frac{\pi}{4} \cos(1) \nonumber\\
& \hspace{5mm} + i \sum_{k=1}^{\infty} \frac{2^{k/2}}{k \cdot k!} \ e^{\frac{k \pi i}{2}} 
\cos\left( \frac{k \pi}{4} + 1 \right).
\end{align}
</s>