Text this: A variational approach to local optimality in control theory