Thanks for your work. This looks wonderful.
I think there's a misplaced parenthesis in the code for the tangent line. I think the corrected formulation would be
(D[expr, x] /. x -> x0)*(x - x0) + (expr /. x -> x0)