Search code examples
utf-8special-characterspython-sphinxrestructuredtext

How do I write the Multiplication Sign in reStructuredText (reST)?


I'm writing reST documents that will be rendered to HTML and PDF using Sphinx. My source files are UTF-8, and expect my HTML to be displayed as UTF-8.

What's the best practice for writing the multiplication sign?

That is: ×, not x.

I know I can insert it as a Unicode character. If I were writing LaTeX, I'd use \times. In HTML there's ×. Is the simple Unicode going to properly survive the conversion process when I render everything with Sphinx? Even if I render to other more exotic formats?

I just want to double-check that this isn't going to trip things up somewhere.


Solution

  • It turns out that the Sphinx documentation contains the answer, I just didn't read quite far enough:

    Since the easiest way to include special characters like em dashes or copyright signs in reST is to directly write them as Unicode characters, one has to specify an encoding. Sphinx assumes source files to be encoded in UTF-8 by default; you can change this with the source_encoding config value.

    https://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html#source-encoding

    Edit: Just to follow up here: while the multiplication sign works just fine, many other seemingly standard unicode symbols (less than or equal to, and greater than or equal to) are missing from the default font used in LaTeX (and thus PDF) rendering.