tikzplotlib icon indicating copy to clipboard operation
tikzplotlib copied to clipboard

standalone latex file required UTF-8 encoding

Open Aikhjarto opened this issue 5 years ago • 7 comments
trafficstars

fixes #410 by enforcing UTF-8 encoding for standalone latex files (issue warning if user supplied encoding is not adhered)

Aikhjarto avatar May 24 '20 18:05 Aikhjarto

But is UTF-8 the only supported encoding for standalone? Seems weird.

nschloe avatar May 24 '20 18:05 nschloe

It seems that at least it is for the latex flavor according the used latex header https://github.com/nschloe/tikzplotlib/blob/adcf150493404b1c52e0f7f1c4f36627b31b6a4d/tikzplotlib/_save.py#L400-L403

Aikhjarto avatar May 24 '20 19:05 Aikhjarto

Well it seems we should rather adopt that, right?

nschloe avatar May 24 '20 19:05 nschloe

For that task we would require a latex preamble that is working with all encodings supported by python's codec module. Making a latex preamble working with different encodings is not an easy task and I was not able to do that. Therefore I favor the approach of enforcing UTF-8. But of course, it is up to you to accept the pull-request or decline it in favor of a more versatile solution.

Aikhjarto avatar May 24 '20 19:05 Aikhjarto

The line is

\\usepackage[utf8]{{inputenc}} 

Why can't we simply insert the encoding there?

nschloe avatar May 24 '20 19:05 nschloe

Latex's inputenc does support a much smaller number of encodings than python's codec module does. So simply putting the codec there would generated an error later on.

Also I have no idea what \DeclareUnicodeCharacter will do with other encodings than UTF-8.

Aikhjarto avatar May 24 '20 20:05 Aikhjarto

I can confirm this is still an error under Windows 10 because the default encoding to write to a file is cp1252, which apparently doesn't support this character.

I would also argue for enforcing utf-8, because this seems generally to be the standard recommendation for working with Latex.

Why is this \DeclareUnicodeCharacter{{2212}}{{−} there in the first place? I couldn't find any occurrence of this character.

Naikless avatar Apr 10 '22 14:04 Naikless