daqana / tikzDevice

A R package for producing graphics output as PGF/TikZ code for use in TeX documents.
https://daqana.github.io/tikzDevice
132 stars 26 forks source link

enforcing the encoding of temp TeX file to UTF-8 #159

Closed jszhao closed 6 years ago

jszhao commented 7 years ago

Make the encoding of temporal TeX file tikzStringWidthCalc.tex to UTF-8, so that the xelatex and lualatex can compile the file correctly.

Closes #154.

jszhao commented 7 years ago

This change can solve the https://github.com/yihui/tikzDevice/issues/154 partially. However, the encoding of final output file can not be controlled from the R code. In the https://github.com/yihui/tikzDevice/issues/154, the final output file is in UTF-8 encoding. If I change 模式 to 中文, the final file is in encoding CP936. I don't find a clue to solve it, because I am know nothing about C.

yihui commented 7 years ago

In fact, the encoding of a file can be precisely controlled from R. The original authors of this package seem to like using file() connections, which are unnecessary in my eyes.

In this case, if you want the file to be precisely encoded in UTF8, the correct way is first enc2utf8(), then writeLines(useBytes = TRUE). From my experience, file(encoding = 'UTF-8') cannot guarantee the output file is encoded in UTF-8 on Windows.

jszhao commented 7 years ago

I think all files to be encoded in UTF-8 is a acceptable or best way. It also simplifies the code. However, how to encode the final output file generated by tikz in UTF-8. The file is not generated by R code, but by C code.

krlmlr commented 6 years ago

Thanks!