sphinx_rtd_theme icon indicating copy to clipboard operation
sphinx_rtd_theme copied to clipboard

:cpp:expr: is not rendered as monospace

Open jgcodes2020 opened this issue 3 years ago • 3 comments

Problem

Exactly what the title says. According to the Sphinx documentation, :cpp:expr: should render as code, while :cpp:texpr: should render as normal text.

Reproducible Project

This is the offending code in my docs:

  .. cpp:function:: m64::frame& back()
  .. cpp:function:: const m64::frame& back() const
  
    Returns a reference to the last frame of this M64.  
    Equivalent to :cpp:expr:`(*this)[this->size() - 1]` or :cpp:expr:`*(this->end())`.

Error Logs/Results

This is what comes out:

image

Expected Results

The text marked as :cpp:expr: should be in monospace font (style class cpp-expr, for anyone messing with the CSS)

Environment Info

  • Python Version: 3.8
  • Sphinx Version: 4.0.3
  • RTD Theme Version: 0.5.2

jgcodes2020 avatar Jul 18 '21 15:07 jgcodes2020

I also notice that there is no colouring of keywords. Does the theme derive from the basic theme in Sphinx or some other theme? From the Sphinx side, what can we do to better propagate basic CSS changes to the RTD theme?

jakobandersen avatar Nov 21 '21 12:11 jakobandersen

I managed to do a quick workaround ... add the following to your stylesheet.

.cpp-expr {
  background: #fff;
  background-clip: initial;
  background-color: #fff;
  border: 1px solid #e1e4e5;
  box-sizing: border-box;
  color: #404040;
  font-family: SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,Courier,monospace;
  font-size: 75%;
  font-weight: 700;
  line-height: 24px;
  max-width: 100%;
  overflow-x: auto;
  padding: 2px 5px;
  white-space: normal;
}

But someone who knows better can do a proper fix...

https://github.com/sphinx-doc/sphinx/blob/v5.3.0/tests/test_domain_cpp.py#L1313 'span' to 'code'?

AA11BB22 avatar Oct 20 '22 05:10 AA11BB22

But someone who knows better can do a proper fix...

I can at least give some pointers, as the CSS "interface" for Sphinx is not really documented. This particular stuff was added/changed in https://github.com/sphinx-doc/sphinx/pull/9023:

  • All signature-like elements have the class sig.
  • Declarations, e.g., .. py:function:: or .. cpp:function:: further have sig-object.
  • Inline elements (of which I think only :cpp:expr:/:cpp:texpr: exists) instead have sig-inline.
  • Each signature-like element further have the name of the domain as a class, e.g., py or cpp.

So, all :cpp:expr:/:cpp:texpr: can be selected with .sig-inline.cpp. If you want all C++ domain objects to be selected, then .sig.cpp.

jakobandersen avatar Oct 21 '22 20:10 jakobandersen