A linear grammar approach for the analysis of mathematical documents