Backport PR #47059 on branch 1.4.x (REGR: Styler buf and encoding in to_latex and to_html)
Backport PR #47059

release note already backported in #47062
hmm this is failing on backport: https://github.com/pandas-dev/pandas/runs/6523596334?check_suite_focus=true

cc @attack68 

