New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: UnicodeDecodeError
when using some special and accented characters in TeX
#23019
Comments
Fwiw, I get the same error on my Windows 10 machine. The unfortunate thing is that it is actually in the formatting of the error message that the error occurs. Removing the decode part leads to:
(FYI, you may get test errors due to slightly different fonts when running locally, especially on Windows, but this is clearly a different issue.) |
Can you check whether diff --git i/lib/matplotlib/texmanager.py w/lib/matplotlib/texmanager.py
index 2ffe0d5f66..a9022db5ed 100644
--- i/lib/matplotlib/texmanager.py
+++ w/lib/matplotlib/texmanager.py
@@ -243,7 +243,7 @@ class TexManager:
Return the file name.
"""
texfile = cls.get_basefile(tex, fontsize) + ".tex"
- Path(texfile).write_text(cls._get_tex_source(tex, fontsize))
+ Path(texfile).write_text(cls._get_tex_source(tex, fontsize), encoding="utf-8")
return texfile
@classmethod fixes the issue? (We should probably also fix _run_checked_subprocess to use something like |
Seems to fix it for me at least! |
Feel free to pick up the patch, then. |
Yep, this also works for me! |
Bug summary
I'm just getting started with the development side of matplotlib, and I'm getting a
UnicodeDecodeError
in some cases (not all cases) when TeX is being used in unit tests and building docs. The cause of the issue may be specific to my installation and seems to be isolated to the use of certain special and accented characters, but I'm not sure how to resolve it.The code below is an example (from tex_demo.py in the docs) of one instance where this error is occurring, and
\N{DEGREE SIGN}
is causing the issue (removing it allows the code to run without error).Code for reproduction
Actual outcome
Traceback from warning/error in building docs:
The
test_savefig_to_stringio()
test also fails four times, each time with a different set of arguments. This is also aUnicodeDecodeError
, but it originates from the title of the plot having accented characters ("Déjà vu"). Removing those characters resolves theUnicodeDecodeError
, but leaves me with anAssertionError
at the end of the test. Traceback is omitted here because it is over 200 lines long, and results in a similar error as above.Expected outcome
Expected outcome is to build docs and pass all tests without failure. Referring to the failing instance in the docs from tex_demo.py, that code should produce:
Additional information
Again, this could be isolated to my installation of matplotlib, but if anyone can reproduce this error or knows of a possible fix, that would be great.
Operating system
Windows 11
Matplotlib Version
3.6.0.dev2170+g40676bb62f
Matplotlib Backend
module://matplotlib_inline.backend_inline
Python version
3.8.13
Jupyter version
3.4.0
Installation
git checkout
The text was updated successfully, but these errors were encountered: