Sphinx Emoji Codes
Sphinx Emoji Codes (sphinxemoji) is a Sphinx extension that enables the use of emoji shortcodes (e.g., |:smile:|) directly within your Sphinx documentation. It is currently at version 0.3.2 and primarily releases updates to maintain compatibility with new Sphinx versions or to fix bugs.
Common errors
-
Package inputenc Error: Unicode character ๐ (U+1F69A) (inputenc) not set up for use with LaTeX.
cause The default LaTeX engine (pdfLaTeX) often struggles with direct Unicode emoji characters, especially when not explicitly configured with appropriate packages or a Unicode-friendly engine.fixIn `conf.py`, set `latex_engine = 'xelatex'` or `latex_engine = 'lualatex'`. Ensure these engines are installed and available in your LaTeX distribution. Alternatively, use `sphinxemoji_style = 'twemoji'` to render emojis as images. -
Sphinx build fails with an error related to `SphinxComponentRegistry.create_source_parser` or `Cannot import name 'create_source_parser' from 'sphinx.util.parsers'`.
cause You are likely using Sphinx v9, which introduced breaking changes to its internal API, specifically how source parsers are registered and created. `sphinxemoji` versions prior to a compatible update do not support this new API.fixUpgrade `sphinxemoji` to its latest version (if a v9-compatible release exists). If not, temporarily downgrade your Sphinx installation to a version below 9.x (e.g., `pip install 'Sphinx<9'`). -
SyntaxError: invalid syntax in conf.py or unexpected keyword 'sphinxemoji.sphinxemoji'
cause The `extensions` list in `conf.py` is Python code, and improper formatting (e.g., missing commas, incorrect quotes, or direct `import` statements) will cause a `SyntaxError` during the Sphinx build process.fixEnsure that `extensions = ['sphinxemoji.sphinxemoji']` (or `extensions.append('sphinxemoji.sphinxemoji')`) is correctly formatted within your `conf.py` file, respecting Python list syntax.
Warnings
- breaking sphinxemoji version 0.3.2 (and earlier) is incompatible with Sphinx v9 due to changes in `SphinxComponentRegistry.create_source_parser`.
- gotcha Building documentation to PDF via LaTeX can result in `inputenc Error: Unicode character ... not set up for use with LaTeX` if your LaTeX distribution or configuration does not properly handle Unicode emojis.
- gotcha Users on Windows might encounter `encoding` errors when `sphinxemoji.py` attempts to load its `codes.json` file.
Install
-
pip install sphinxemoji
Imports
- sphinxemoji
import sphinxemoji # Not directly imported in Python code
extensions = ['sphinxemoji.sphinxemoji'] # In conf.py
Quickstart
# conf.py
extensions = [
'sphinxemoji.sphinxemoji',
]
# Your RST or MyST file (e.g., index.rst or index.md)
# This text includes a smiley face |:smile:| and a snake too! |:snake:|
# Don't you love it? |:heart_eyes:|
# Optional: Set a consistent emoji style (e.g., Twemoji)
# sphinxemoji_style = 'twemoji'