A new formula is presented for computing Maslov indices in integrable and near-integrable Hamiltonian systems. For several kinds of applications the new formula is particularly easy to use. It does not rely on counting caustics or other kinds of discontinuities. Its theoretical justification calls on wave-packet concepts and the topological properties of the group of symplectic matrices. Techniques are also presented for manipulating the Maslov index in analytical expressions.