Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to underline text in reStructuredText?

Of course, on the web an underline denotes hyperlink, but what if I need underline which is not a hyperlink?

like image 904
Alex Bolotov Avatar asked Jan 31 '12 17:01

Alex Bolotov


People also ask

How do you set an underline for text?

The quickest way to underline text is to press Ctrl+U and start typing. When you want to stop underlining, press Ctrl+U again. You can also underline text and spaces in several other ways.

How do you underline text in HTML style?

To underline a text in HTML, use the <u> tag. The <u> tag deprecated in HTML, but then re-introduced in HTML5. Now it represents a text different from another text stylistically, such as a misspelled word. To underline a text, you can also use the style attribute.

How do you underline in LaTeX?

To underline text use the \underline command: Some of the greatest discoveries in \underline{science} were made by accident. Open this LaTeX fragment in Overleaf.

How do I comment a line in an RST file?

For comments, add 2 periods .. followed by a newline and then your comment indented.


2 Answers

I asked a similar question here. Try like this:

.. role:: underline     :class: underline 

In the document, this can be applied as follows:

:underline:`This text is underlined` 

In your css file you could have:

.underline {   text-decoration: underline; } 

This should work for HTML output. However, underlining is intentionally not part of the ReST specs. See this link.

like image 173
gozzilli Avatar answered Sep 22 '22 09:09

gozzilli


You add the following directive in the index.rst file for example:

.. role:: underline     :class: underline 

In the document you indicate the text as underlined with the following:

:underline:`This text is underlined` 

To specify the css for your underline class you add some css to the layout.html file inside the folder _themes/sphinx_rtd_theme/sphinx_rtd_theme/ if you are using the sphinx_rtd_theme, otherwise your default theme directory:

<style>     .underline {     text-decoration: underline;   } </style> 

This will style your html accordingly.

Underlining is part of the StructureText but not of Sphinx's reStructuredText specifications, according to a quote from David Ascher in his 2000-01-21 Doc-SIG mailing list post, "Docstring grammar: a very revised proposal":

The tagging of underlined text with _'s is suboptimal. Underlines shouldn't be used from a typographic perspective (underlines were designed to be used in manuscripts to communicate to the typesetter that the text should be italicized -- no well-typeset book ever uses underlines), and conflict with double-underscored Python variable names (init and the like), which would get truncated and underlined when that effect is not desired. Note that while complete markup would prevent that truncation ('init'), I think of docstring markups much like I think of type annotations -- they should be optional and above all do no harm. In this case the underline markup does harm.

like image 28
saimiris_devel Avatar answered Sep 18 '22 09:09

saimiris_devel