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

荒凉一梦 提交于 2019-12-24 00:50:10

问题


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.


回答1:


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.

http://sphinx.pocoo.org/rest.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.




回答2:


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.




回答3:


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




回答4:


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


来源:https://stackoverflow.com/questions/6369049/how-do-i-write-the-multiplication-sign-in-restructuredtext-rest

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!