Electrostatics of lateral p-n junctions in atomically thin materials