开发者

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

开发者 https://www.devze.com 2023-03-13 04:22 出处:网络
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.

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开发者_StackOverflow I render to other more exotic formats?

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


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.


To add to @Paul McMillan's answer, if you're trying to publish your sphinx documentation as a latex pdf, you can often get around the missing unicode symbols by including in your conf.py preamble:

_PREAMBLE = r"""
\usepackage[utf8]{inputenc}
\DeclareUnicodeCharacter{00D7}{\times}
"""

latex_elements = {
    'preamble': _PREAMBLE,
}

Where 00D7 is the unicode encoding, and \times is what you want it to be replaced by in latex.

You can find the unicode encoding for your character on the fileformat website.

More information here and here.


I would use MathML within rst :math:`m \times p`


What's wrong with |times| after using .. include:: <isonum.txt> ?

From http://docutils.sourceforge.net/0.6/docutils/parsers/rst/include/isonum.txt :

.. |sup2|   unicode:: U+000B2 .. SUPERSCRIPT TWO
.. |sup3|   unicode:: U+000B3 .. SUPERSCRIPT THREE
.. |times|  unicode:: U+000D7 .. MULTIPLICATION SIGN
.. |trade|  unicode:: U+02122 .. TRADE MARK SIGN
.. |uarr|   unicode:: U+02191 .. UPWARDS ARROW
0

精彩评论

暂无评论...
验证码 换一张
取 消