23

I want to use some symbols in restructuredText; how can I do this? (e.g. → in Markdown yields the "→" symbol as defined in the list of standard HTML character entities -- see also w3c reference)

Note: I don't want to require math formula support as a dependency.

Ned Batchelder
  • 364,293
  • 75
  • 561
  • 662
Jason S
  • 184,598
  • 164
  • 608
  • 970

4 Answers4

19

You have a large number of defined symbols via the "substitution" operator.

You have to include the definitions via .. include:: <isonum.txt> or something similar.

Most of them have the form |larr| or |rarr|.

They are defined in the docutils.parsers.rst.include installation directory. There are dozens of files which define numerous Unicode characters.

S.Lott
  • 384,516
  • 81
  • 508
  • 779
  • Hmmm. These look really lousy compared to the Markdown symbols that result. – Jason S Dec 07 '09 at 20:15
  • 1
    "lousy"? What does that mean in this context? Are you saying that `←` is worse than `|larr|` or are you saying that your browser font looks lousy? – S.Lott Dec 07 '09 at 21:06
  • I'm looking at this `→` on this site, and comparing it against Sphinx (using RST) HTML output of |rarr|. Both are HTML and are using the same default font. I'm not sure if they are the same unicode character, I don't have a character-codepoint-decoder on hand. – Jason S Dec 07 '09 at 21:41
  • 1
    You don't need much of a code-point decoder. The standard HTML entities give you the Unicode character number. The `` file gives you the character defined by RST. You can create your own definition if the HTML entity is different than the RST entity. – S.Lott Dec 08 '09 at 00:35
  • Hmm. Both sources claim codepoint 0x2192 for rarr, and the surrounding text is in the same font, yet the symbols look different. Something is fishy, and like I said, I don't have a character codepoint decoder. – Jason S Dec 08 '09 at 14:45
  • Argh -- a red herring, it has something to do with the CSS or font displays, nothing to do with UTF-8 encoding vs. HTML entity encoding. Thanks! – Jason S Dec 08 '09 at 15:14
  • 4
    As a reference: [reStructuredText Standard Definition Files](http://docutils.sourceforge.net/docs/ref/rst/definitions.html). – Paolo Jun 25 '13 at 14:43
4

It was my impression that rst supported Unicode; can you just type in the raw character and let docutils handle encoding for HTML?

Hank Gay
  • 70,339
  • 36
  • 160
  • 222
4

I think you were looking for this: http://docutils.sourceforge.net/docs/ref/rst/roles.html#raw

You can define the following role:

.. role::  raw-html(raw)
    :format: html

And then you can write:

This way :raw-html:`&rarr;`

Which renders like this:

This way →

davidrmcharles
  • 1,923
  • 2
  • 20
  • 33
0

I had a similar problem when making html from .rst files containing the ± character in Windows using Sphinx. Changing the file encoding from windows-1252 to UTF-8 fixed it for me.

Simply open with notepad, Save As..., and change Encoding: to UTF-8

HyperActive
  • 1,129
  • 12
  • 12