Action principle for a relativistic string in an external scalar field