A pencil-sized quantum magnetometer built for submarine detection has tracked a subway train beneath a city street.