  We provide an integral formula for the Maslov index of a pair $(E,F)$ over a
surface $\Sigma$, where $E\rightarrow\Sigma$ is a complex vector bundle and
$F\subset E_{|\partial\Sigma}$ is a totally real subbundle. As in Chern-Weil
theory, this formula is written in terms of the curvature of $E$ plus a
boundary contribution.
  When $(E,F)$ is obtained via an immersion of $(\Sigma,\partial\Sigma)$ into a
pair $(M,L)$ where $M$ is K\"ahler and $L$ is totally real, the formula allows
us to control the Maslov index in terms of the geometry of $(M,L)$. We exhibit
natural conditions on $(M,L)$ which lead to bounds and monotonicity results.
