Reputation: 11
I maked a Sphinx (Readthedocs) project with custom font.
Exported - http://1ra-manual-dentrenament-basic-de-combat.readthedocs.io/ca/latest/
Github - https://github.com/CavallersDelCel/1RA_EBC/blob/master/docs/index.rst
Custom font in _static/fonts/LinBiolinum_Kah.ttf
I have a _static/css/custom.css with:
@font-face {
font-family: "Linux Biolinum Keyboard";
src: url(../fonts/LinBiolinum_Kah.ttf);
}
.keys {
font-family: "Linux Biolinum Keyboard", sans-serif;
}
In conf.py i have:
def setup(app):
app.add_stylesheet('css/custom.css')
And in one page i write:
<span class="keys">FM</span>
But the result is a plain text with the tags, not text with the custom font:
Upvotes: 1
Views: 1236
Reputation: 111
There is a simpler and more precise way to do this.
Let me review the background, mostly from the question:
Transfer the font to the fonts folder. In my set-up, it is found in the build folder, build/_static/fonts.
In source/_static/css/, create or edit a file custom.css.
Add the lines:
@font-face {
font-family: "Linux Biolinum Keyboard";
src: url(../fonts/LinBiolinum_Kah.ttf);
}
.keys {
font-family: "Linux Biolinum Keyboard", sans-serif;
}
Assuming that you want HTML output, make sure that conf.py has these lines under "Options of HTML output":
html_css_files = ['css/custom.css',]
html_static_path = ['_static']
Now for the trick.
In conf.py, define a role for the font in rst.prolog
:
rst_prolog = """
.. role:: LBK
:class: keys
"""
This role can be invoked in any document in the project, in one of two ways:
a. by applying the role to a bit of text, eg.
:LBK:`FM`
b. by appending the class option to a body element, eg.
.. list-table:: My Table
:header-rows: 1
:widths: 20 20
:class: keys
Upvotes: 0
Reputation: 15055
You have two issues.
"
gets converted to »
.<
and >
) from plain text to their HTML-encoded entities <
and >
.To correct the issue in this case, you probably want to use the .. raw::
directive, like so:
.. raw:: html
<span class="keys">FM</span>
...and then Sphinx should allow the HTML code to render properly.
Additionally if you want to show the source HTML code inline:
.. code-block:: html
<span class="keys">FM</span>
Upvotes: 1