Rewriting bosonic action in Altland and Simon Chapter 4 In page 179 of Altland and Simon, Condensed Matter Field Theory, the author obtained the action 
\begin{equation}
S[\theta]=\frac{1}{2\pi}\int dx\,d\tau\,\left[(\partial_x\theta)^2+(\partial_\tau\theta)^2\right] \tag{4.48b}
\end{equation}
The author then obtained the canonical momentum corresponding to $\theta$ as 
$$\pi_\theta=\partial_{\partial_\tau \theta}\mathcal{L}=\partial_\tau\theta/\pi.\tag{4.48c}$$ 
According to Hamiltonian mechanics, 
\begin{equation}
\mathcal{H}=\dot{q}\frac{\partial\mathcal{L}}{\partial\dot{q}}-\mathcal{L}=\dot{q}p-\mathcal{L}
\end{equation}
taking $\theta\leftrightarrow q$ and making use of $\partial_\tau\theta=\pi\pi_\theta$, we should have
\begin{align}
\mathcal{H}&=(\partial_\tau\theta)\pi_\theta-\frac{1}{2\pi}\left[(\partial_x\theta)^2+(\partial_\tau\theta)^2\right]\\
&=\frac{1}{2\pi}\left[\pi^2\pi_\theta^2-(\partial_x\theta)^2\right].
\end{align}
However, this expression is different from the Hamiltonian density given in the textbook 
$$\mathcal{H}=\frac{1}{2\pi}\left[(\partial_x\theta)^2+\pi^2\pi_\theta^2\right].\tag{4.48d}$$ What did I do wrong here? How to obtain the Hamiltonian given in the textbook? And also how to obtain the new action
\begin{equation}
S[\theta,\pi_\theta]=\frac{1}{2}\int dx\,d\tau\,\left(\frac{1}{\pi}(\partial_x\theta)^2 +\pi\pi_\theta^2 +2i\partial_\tau\theta\pi_\theta\right)~?\tag{4.48e}
\end{equation}
In particular, where is the last term in the parenthesis $2i\partial_\tau\theta\pi_\theta$ coming from?
 A: TL;DR: The trick is not to Wick-rotate the momentum field
$$ \Pi_M~=~i\Pi_E, \tag{1}$$
because it would otherwise lead to a divergent Gaussian momentum integral in the Euclidean (E) path integral. So we will keep the Minkowski (M) momentum $\Pi_M\in\mathbb{R}$ even in the Euclidean formulation.
Further details: Standard conventions for the Wick rotation are
$$ -S_E~=~iS_M, \qquad t_E~=~it_M, \qquad {\cal L}_E~=~-{\cal L}_M, \tag{2}$$
cf. p. 106 in Ref. 1.
The potential density is 
$${\cal V}~=~\frac{1}{2\pi}(\partial_x\Theta)^2.\tag{3}$$
The Minkowski & Euclidean Hamiltonian densities read
$${\cal H}_M~=~\frac{\pi}{2}\Pi_M^2+{\cal V},\tag{4M}$$
$${\cal H}_E~=~\frac{\pi}{2}\Pi_E^2-{\cal V}~=~-\frac{\pi}{2}\Pi_M^2-{\cal V}.\tag{4E}$$
The Minkowski & Euclidean Hamiltonian Lagrangian densities read
$$\begin{align} {\cal L}_H^M&~=~\Pi_M\frac{d\Theta}{dt_M} - {\cal H}_M
~\stackrel{(4M)}{=}~ 
\Pi_M\frac{d\Theta}{dt_M}-\frac{\pi}{2}\Pi_M^2-{\cal V} \cr
&\stackrel{\text{int. out } \Pi_M}{\longrightarrow}\quad 
{\cal L}_M~=~\frac{1}{2\pi}\left(\frac{d\Theta}{dt_M}\right)^2 - {\cal V}. \tag{5M} \end{align}$$
$$\begin{align} {\cal L}_H^E&~=~\Pi_E\frac{d\Theta}{dt_E} - {\cal H}_E
~\stackrel{(4E)}{=}~
\color{Red}{-}i\Pi_M\frac{d\Theta}{dt_E} + \frac{\pi}{2}\Pi_M^2+{\cal V}\cr 
&\stackrel{\text{int. out } \Pi_M}{\longrightarrow} \quad
{\cal L}_E~=~\frac{1}{2\pi}\left(\frac{d\Theta}{dt_E}\right)^2 + {\cal V}. \tag{5E}\end{align}$$
The last expression in eq. (5E) corresponds to OP's first eq. (4.48b).
The second expression in eq. (5E) corresponds to OP's sought-for eq. (4.48e), although with an opposite sign marked in red. We have not
investigated further the origin of this discrepancy. 
References:


*

*A. Altland & B. Simons, Condensed matter field theory, 2nd ed., 2010.

A: Here $\tau$ is imagine time, which may lead to the difference with real time condition. You can first let $\tau = it$ and get a result, then let $t=-i\tau$ to the imagine time. Maybe you can get the result.
