Hamiltonian theory of anyons in crystals