Why is $e^{i\hat{p}L/\hbar}$ only an operator when it is outside an integral? 
Looking at the screenshot provided below, which is an excerpt from this textbook, really nothing more than a derivation of momentum as the generator of translations, would someone be kind enough to explain why "$p$ is an operator only outside the integral" as he says? It's not clear to me that this should be true. What about the act of integration is turning $p$ from an operator into a variable?
 A: What is going on is that you have one operator which is diagonal in one particular basis. So to act with it on some vector, you expand the vector on the basis, and act with it on each term.
Very explicitly, and using a finite basis first to make the point. Let us suppose that you have a vector space $V$ and one operator $T$ which has the property that it has one basis of eigenvectors, i.e., one basis $\{e_i\}\subset V$ such that $$Te_i=\lambda_i e_i\tag{1}.$$
In that case if you want to act with $T$ on some generic $v$, the way to go is to expand $v$ in the basis and use linearity of $T$:
$$Tv=T\sum_{i=1}^n v^ie_i=\sum_{i=1}^n v^i Te_i=\sum_{i=1}^n v^i\lambda_i e_i\tag{2}.$$
In particular this is good to define functions of operators. If you have a function $F(x)$ and you want to define $F(T)$ it is immediate to do so in the basis of eigenvectors of $T$. You define the action on the basis by $$F(T)e_i=F(\lambda_i)e_i\tag{3}$$
and extend the action by linearity. In other words, $F(T)$ is defined by: $$F(T)v=F(T)\sum_{i=1}^n v^ie_i = \sum_{i=1}^n v^i F(T)e_i = \sum_{i=1}^n v^i F(\lambda_i)e_i.\tag{4}$$
Now, what you have is the "continuous basis" version of that. You are describing the states of your system in the position representation by position space wavefunctions $f(x)$. In that space, the momentum operator $P$ acts by differentiation,
$$Pf(x)=-i\hbar \dfrac{d}{dx}f\tag{5}.$$
You want to define a particular function of $P$, namely $e^{i\frac{L}{\hbar}P}$. To do so, you want to use the basis of eigenstates of $P$. This means you must solve $$P\psi_p(x)=-i\hbar \dfrac{d}{dx}\psi_p(x)=p\psi_p(x)\tag{6}.$$
This gives you the exponentials $\psi_p(x)=\frac{1}{\sqrt{2\pi\hbar}}e^{i\frac{p}{\hbar}x}$. This is a basis of eigenstates of $P$, the analogue $e_i$ appearing in (1). You can now define your desired exponential using the analogue of (3):
$$e^{i\frac{L}{\hbar}P}\psi_p(x)=e^{i\frac{L}{\hbar}p}\psi_p(x)\tag{7}$$
and extension by linearity. But beware that now linear combinations are taken with integrals since we are working with a continuous basis. In that case, expanding $f(x)$ on the basis and using the definition of $e^{i\frac{L}{\hbar}P}$ we have $$e^{i\frac{L}{\hbar}P}f(x)=e^{i\frac{L}{\hbar}P}\int dp \tilde{f}(p)\psi_p(x)=\int dp \tilde{f}(p)e^{i\frac{L}{\hbar}P}\psi_p(x)=\int dp e^{i\frac{L}{\hbar}p}\tilde{f}(p)\psi_p(x)\tag{8}.$$
So you see that in the end this is, in fact, the definition of $e^{i\frac{L}{\hbar}P}$ on the position representation: it acts diagonally on the basis and is extended by linearity. This is the continuous version of (4) and is nothing but a definition.
