sphinx-contrib / tikz

A Sphinx extension to draw pictures with the TikZ/PGF LaTeX package
Other
19 stars 15 forks source link

0.4.17 introduced bug 'utf-8' codec can't decode byte 0xd0 in position 15877: invalid continuation byte #23

Closed 777arc closed 2 months ago

777arc commented 3 months ago

Starting in 0.4.17 I get a

Encoding error:
'utf-8' codec can't decode byte 0xd0 in position 15877: invalid continuation byte

Here's an example of the tikz that would trigger the error

.. tikz:: [font=\Large\bfseries\sffamily]
   \draw (0,0) node[align=center]{$A\cdot cos(2\pi ft+ \phi)$}
   (0,-2) node[align=center]{$\left(\sqrt{I^2+Q^2}\right)cos\left(2\pi ft + tan^{-1}(\frac{Q}{I})\right)$};
   \draw[->,red,thick] (-2,-0.5) -- (-2.5,-1.2);
   \draw[->,red,thick] (1.9,-0.5) -- (2.4,-1.5);
   \draw[->,red,thick] (0,-4) node[red, below, align=center]{Це те, що ми називаємо носієм} -- (-0.6,-2.7);

I'm on sphinx==7.3.7, using the normal html builder

philexander commented 2 months ago

This is a LaTeX problem. For support of cyrillic you have to modify the LaTeX preamble. You can do this in your Sphinx project's conf.py file by adding:

latex_elements = {
    'preamble': r'''
\usepackage[russian]{babel}
'''
}

This eliminates the encoding issue but surfaces another one: pdf2svg seems to have problems converting cyrillic letters from a PDF to an SVG. You can try to file an issue at https://github.com/dawbarton/pdf2svg, but this project has not been updated since seven years.

Luckily, the TikZ Sphinx extension provides alternative conversion suites to the pdf2svg. You configure the conversion suite in the conf.py file as follows:

Note that all of the above require some Prerequisites to be installed on your system.

Also note that the support for the Netpbm conversion suite was broken but is fixed again in the latest version 0.4.20 of the TikZ Sphinx extension.

777arc commented 2 months ago

@philexander ty!!!!! for anyone else who runs into this issue, what ended up working for me was

tikz_latex_preamble = r'''
\usepackage[russian]{babel}
'''

and also switching to GhostScript