Go upwards until the document root if scanning for an equation.