\myheading{Merge sort} How merge sort works? I have copypasted Python code from rosettacode.com almost intact: \lstinputlisting[style=custompy]{\CURPATH/8_sorting/1.py} But here is a function which compares elements. Obviously, it wouldn't work correctly without it. So we can track both expression for each element and numerical value. Both will be printed finally. But whenever values are to be compared, only numerical parts will be used. Result: \lstinputlisting{\CURPATH/8_sorting/result.txt}