Convert lines of magic squares into LaTeX format