sorting and adding latex