rewrote to match the LaTeX version