General relativity - scalar gravitational field, variation principle I have a basic question about the variation principal when applied to a scalar gravitational field in general relativity.  Consider the action
$$S_M = \int d^4 x\sqrt{|g|}g^{uv}\partial_u \phi\partial_v\phi$$
Varying with respect to $\phi$ gives
$$\delta S_M = 2\int d^4 x\sqrt{|g|}g^{uv}\partial_u\phi\partial_v\delta\phi$$
Now, it seems the standard approach from here is to consider
$$\partial_v\left(\sqrt{|g|}g^{uv}\partial_u\phi\delta\phi\right) = \partial_v\left(\sqrt{|g|}g^{uv}\partial_u\phi\right)\delta\phi + \left(\sqrt{|g|}g^{uv}\partial_u\phi\right)\partial_v\delta\phi$$
As the first term is a total derivative, and we set $\delta \phi$ to be zero along the boundary, it does not contribute to the integral, and thus we have
$$\delta S_M = -2\int d^4x\partial_v\left(\sqrt{|g|}g^{uv}\partial_u\phi\right)\delta\phi,$$
from which we obtain $\partial_v(\sqrt{|g|}g^{uv}\partial_u\phi) = 0$.
In the third equation above, why must we have $\sqrt{|g|}$ inside the derivative?  If we omit it, we would arrive at a different equation of motion: $\partial_v(g^{uv}\partial_u\phi) = 0$, but it is unclear to me where a mistake is made.
 A: The determinant of the metric is, in general, dependent from the coordinates, hence you need to leave it inside the derivative. 
A: You certainly agree with
$$
\delta S_M = 2 \int d^4 x \sqrt{|g|} g^{\mu\nu} \partial_\mu \phi \partial_\nu \delta \phi 
$$
We can now integrate by parts in two ways
1) 
$$
\delta S_M = 2 \int d^4 x \partial_\nu  \left( \sqrt{|g|} g^{\mu\nu} \partial_\mu \phi \delta \phi  \right) - 2 \int d^4 x \partial_\nu \left( \sqrt{|g|} g^{\mu\nu} \partial_\mu \phi  \right) \delta \phi 
$$
In this case (as you have correctly argued) the first term is a total derivative and vanishes since $\delta \phi$ vanishes on the boundary. Only the second term contributes and we can read off the equations of motion as
$$
 \partial_\nu \left( \sqrt{|g|} g^{\mu\nu} \partial_\mu \phi  \right) = 0 . 
$$
2)
If we instead don't include $\sqrt{|g|}$ in the derivative, we would have to write
$$
\delta S_M = 2 \int d^4 x  \sqrt{|g|}\partial_\nu  \left( g^{\mu\nu} \partial_\mu \phi \delta \phi  \right) - 2 \int d^4 x \sqrt{|g|}  \partial_\nu \left(g^{\mu\nu} \partial_\mu \phi  \right) \delta \phi 
$$
Now, the first term is not a total derivative and therefore has no reason to be equal to zero. Both the first and second terms are non-zero and we cannot just read off the equations of motion as simply as you have done.  
