Search code examples
python-sphinxrestructuredtext

How can I change font using ReStructured Text with .. raw:: html?


I'm working on a project using Sphinx for the first time and wanted to create a method (I'm not sure if that is what it's called, but similar to programming methods just a body of text to do a specific task) to change the font in my Sphinx project. I have found a useful question that allowed me to change the color of text here.

Code used to change color below.

.. raw:: html

    <style> .red {color:red} </style>

After this, I simply added

.. role:: red

To my .rst file, allowing me to call this method by simply using

:red:`Text here is red.`

Similarly, I am trying to do this to change the font of text when needed, not of the entire project. Here is my tweaked version of that.

.. raw:: html

    <p style="font-family:'Courier New'"> .font </p>

.. role:: font

This worked, sort of... After I use "make html" to compile, my html page will only show ".font" in the new font, and when I try to call

:font:`new font here`

as before, it will not change the text.

Any advice on how to get this working properly would be greatly appreciated. Thanks.


Solution

  • I finally solved this by practically brute-force, but for anyone curious for this issue here is the update.

    .. raw:: html
        
         <style> .font {font-family:'Courier New'} </style>
    

    And I can call this anywhere like my other method to change color.