Skip to content

Commit 3c753e1

Browse files
committed
LaTeX: add support for fontawesome6 package
1 parent 021d6a8 commit 3c753e1

File tree

3 files changed

+109
-84
lines changed

3 files changed

+109
-84
lines changed

doc/latex.rst

+24-23
Original file line numberDiff line numberDiff line change
@@ -1006,18 +1006,19 @@ The color used in the above example is available from having passed the
10061006
10071007
``iconpackage``
10081008
1009-
The name of the LaTeX package used for icons in the admonition titles. It
1010-
defaults to ``fontawesome5`` or to fall-back ``fontawesome``. In case
1011-
neither one is available the option value will automatically default to
1012-
``none``, which means that no attempt at loading a package is done.
1013-
Independently of this setting, arbitrary LaTeX code can be associated to
1014-
each admonition type via ``div.<type>_icon-title`` keys which are
1015-
described in the :ref:`additionalcss` section. If these keys are not
1016-
used, Sphinx will either apply its default choices of icons (if
1017-
``fontawesome{5,}`` is available) or not draw the icon at all. Notice that
1018-
if fall-back ``fontawesome`` is used the common icon for :dudir:`caution`
1019-
and :dudir:`danger` will default to "bolt" not "radiation", which is only
1020-
found in ``fontawesome5``.
1009+
The name of the LaTeX package used for rendering icons in the admonition
1010+
titles. Its default is set dynamically to either ``fontawesome6``,
1011+
``fontawesome5``, or ``fontawesome``, or ``none``, depending on whether
1012+
packages with those names exist in the used LaTeX installation. The LaTeX
1013+
code will use ``\faIcon`` command if with ``fontawesome6/fontawesome5``,
1014+
and ``\faicon`` if with ``fontawesome``. In the latter case the icon used
1015+
both for :dudir:`caution` and :dudir:`danger` will default to "bolt" not
1016+
"radiation", which is only found in ``fontawesome6`` and ``fontawesome5``.
1017+
If no "Font Awesome" related package is found (or if the option is set
1018+
forcefully to ``none``) the icons are silently dropped. User can set this
1019+
option to some specific package and must configure the ``div.note_title-icon``
1020+
and similar keys to use then that LaTeX package interface (see the
1021+
:ref:`additionalcss` section for these extra ``'sphinxsetup'`` keys).
10211022
10221023
.. versionadded:: 7.4.0
10231024
@@ -1410,17 +1411,17 @@ The next keys, for admonitions, :dudir:`topic`, contents_, and
14101411
(it applies only to the icon, not to the title of the admonition).
14111412
14121413
- ``div.<type>_title-icon``: the LaTeX code responsible for producing the
1413-
icon. For example, the default for :dudir:`note` is
1414-
``div.note_title-icon=\faIcon{info-circle}``. This uses a command from the
1415-
LaTeX ``fontawesome5`` package, which is loaded automatically if available.
1416-
1417-
If neither ``fontawesome5`` nor fall-back ``fontawesome`` (for which the
1418-
associated command is :code-tex:`\\faicon`, not :code-tex:`\\faIcon`) are
1419-
found, or if the ``iconpackage`` key of :ref:`'sphinxsetup'
1420-
<latexsphinxsetup>` is set to load some other user-chosen package, or no
1421-
package at all, all the ``title-icons`` default to empty LaTeX code. It is
1422-
up to user to employ this interface to inject the icon (or anything else)
1423-
into the PDF output.
1414+
icon. If you want to modify the icons used by Sphinx, employ in these keys
1415+
the ``\faIcon`` LaTeX command (assuming either ``fontawesome6`` or
1416+
``fontawesome5`` LaTeX package is available on your system). For example
1417+
the default for :dudir:`note` is
1418+
``div.note_title-icon=\faIcon{info-circle}`` with ``fontawesome5`` and
1419+
``div.note_title-icon=\faIcon{circle-info}`` with ``fontawesome6`` (which is
1420+
used automatically if available). If your system only provides the
1421+
``fontawesome`` package (automatically detected) use its command ``\faicon``
1422+
rather in order to modify the choice of icons. The ``iconpackage`` key can
1423+
be used to use some other package providing icons, use then the commands
1424+
suitable to that package as values of the ``div.<type>_title-icon`` keys.
14241425
14251426
.. note::
14261427

sphinx/texinputs/sphinx.sty

+83-58
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
% by the Sphinx LaTeX writer.
1010

1111
\NeedsTeXFormat{LaTeX2e}[1995/12/01]
12-
\ProvidesPackage{sphinx}[2024/11/23 v8.2.0 Sphinx LaTeX package (sphinx-doc)]
12+
\ProvidesPackage{sphinx}[2025/04/24 v8.3.0 Sphinx LaTeX package (sphinx-doc)]
1313

1414
% provides \ltx@ifundefined
1515
% (many packages load ltxcmds: graphicx does for pdftex and lualatex but
@@ -672,7 +672,7 @@
672672
% defaults for them remain not to have specific colour.
673673
%
674674
% 7.4.0 adds keys for admonition titles: for background and foreground colors,
675-
% and for icons (whose defaults are picked from Free Fontawesome 5).
675+
% and for icons.
676676
\def\spx@tempa#1{%
677677
\expandafter\spx@tempb
678678
\csname if#1withshadowcolor\expandafter\endcsname
@@ -869,80 +869,105 @@
869869
}
870870

871871
% 7.4.0 Support for icons in admonition titles
872-
% We try to
873-
% - get Sphinx PDF builds to process fine in absence of fontawesome5
874-
% - use fontawesome5 if present, but not if user prefers another package
875-
% - provide an interface for using other LaTeX code for icons
876-
% - provide an interface for using some other package than fontawesome5
877-
% Indeed we can't load fontawesome5 unconditionally even if available,
878-
% as it proves incompatible with fontawesome package.
879-
% We thus must delay its loading.
880-
\IfFileExists{fontawesome5.sty}{%
881-
\DeclareStringOption[fontawesome5]{iconpackage}%
872+
%
873+
% We let Sphinx use in order of priority: some user-specifid package,
874+
% fontawesome6 (since 8.3.0), fontawesome5, fontawesome, or nothing (and then
875+
% not draw any icon). To allow a user-specified package, an extra interface
876+
% is provided for specifying the icon-drawing LaTeX code.
877+
%
878+
% We can't load fontawesome6 (or 5) unconditionally even if available, as it
879+
% is incompatible with fontawesome package which may be preferred by user. We
880+
% thus must delay loading the package to at begin document, and for now can
881+
% only set the default value of iconpackage key..
882+
\IfFileExists{fontawesome6.sty}{%
883+
\DeclareStringOption[fontawesome6]{iconpackage}%
882884
}%
883885
{%
886+
\IfFileExists{fontawesome5.sty}{%
887+
\DeclareStringOption[fontawesome5]{iconpackage}%
888+
}%
889+
{%
884890
\IfFileExists{fontawesome.sty}
885891
{\DeclareStringOption[fontawesome]{iconpackage}}
886892
{\DeclareStringOption[none]{iconpackage}}%
893+
}%
887894
}%
888-
\newcommand\spx@faIcon[2][]{}%
889-
% The above \spx@faIcon which gobbles one mandatory and one optional
890-
% argument is put into use only if both fontawesome5 and fontawesome
891-
% LaTeX packages are not available, as part of the defaults for the
892-
% div.*_title-icon keys (these keys can be redefined via the sphinxsetup
893-
% interface).
894-
%
895-
\def\spxstring@fontawesome{fontawesome}
896-
\def\spxstring@fontawesomev{fontawesome5}
895+
% Unfortunately icon names differ between fontawesome, fontawesome5, and
896+
% fontawesome6 LaTeX packages. At 8.3.0 we refactor the icon support code
897+
% into something easier to maintain in future in case of a fontawesome7,
898+
% etc...
899+
%
900+
% TODO: Handle spaces possibly caused by bad user usage of iconpackage key?
901+
% This would need to check how LaTeX handle spaces in package name
902+
% in \RequirePackage command. Things in this area may have changed
903+
% recently (2025/04).
897904
\AtBeginDocument{%
898905
\ifx\spx@opt@iconpackage\spxstring@none
899906
\else
900907
\IfFileExists{\spx@opt@iconpackage.sty}
901-
{\RequirePackage{\spx@opt@iconpackage}%
902-
\ifx\spx@opt@iconpackage\spxstring@fontawesomev
903-
\renewcommand\spx@faIcon{\faIcon}%
904-
\else
905-
\ifx\spx@opt@iconpackage\spxstring@fontawesome
906-
\renewcommand\spx@faIcon[2][]{\faicon{##2}}%
907-
% The \ifdefined's are a bit silly because we know that
908-
% fontawesome.sty does not provide it, but perhaps
909-
% there can be some new release of that package?
910-
\ifdefined\faicon@lightbulb\else
911-
\let\faicon@lightbulb\faLightbulbO
912-
\fi
913-
\ifdefined\faicon@radiation\else
914-
\let\faicon@radiation\faBolt
915-
\fi
916-
\ifdefined\faicon@pen\else
917-
\let\faicon@pen\faPencil
918-
\fi
919-
% if neither has been required, \spx@faIcon will simply swallow
920-
% its argument and it is up to user
921-
% to set the various div.*_title-icon keys appropriately.
922-
\fi\fi %
923-
}%
908+
{\RequirePackage{\spx@opt@iconpackage}}%
924909
{%
925-
\sphinxbuildwarning{badiconpackage}%
926-
\PackageWarningNoLine{sphinx}{%
910+
\sphinxbuildwarning{badiconpackage}%
911+
\PackageWarningNoLine{sphinx}{%
927912
You have set iconpackage=\spx@opt@iconpackage\MessageBreak
928913
But \spx@opt@iconpackage.sty is not found by LaTeX}
914+
\let\spx@opt@iconpackage\spxstring@none
929915
}%
930916
\fi
931917
}
932918

919+
% Icon defaults depending on package used.
920+
% Attention! no extra spaces for alignment when using \@namedef!
921+
\@namedef{spx@fontawesome6@note}{\faIcon{circle-info}}
922+
\@namedef{spx@fontawesome6@hint}{\faIcon[regular]{lightbulb}}
923+
\@namedef{spx@fontawesome6@tip}{\faIcon[regular]{lightbulb}}
924+
\@namedef{spx@fontawesome6@seealso}{\faIcon{share}}
925+
\@namedef{spx@fontawesome6@todo}{\faIcon{pen}}
926+
\@namedef{spx@fontawesome6@important}{\faIcon{circle-pause}}
927+
\@namedef{spx@fontawesome6@caution}{\faIcon{radiation}}
928+
\@namedef{spx@fontawesome6@warning}{\faIcon{triangle-exclamation}}
929+
\@namedef{spx@fontawesome6@attention}{\faIcon{triangle-exclamation}}
930+
\@namedef{spx@fontawesome6@danger}{\faIcon{radiation}}
931+
\@namedef{spx@fontawesome6@error}{\faIcon{circle-xmark}}
932+
933+
\@namedef{spx@fontawesome5@note}{\faIcon{info-circle}}
934+
\@namedef{spx@fontawesome5@hint}{\faIcon[regular]{lightbulb}}
935+
\@namedef{spx@fontawesome5@tip}{\faIcon[regular]{lightbulb}}
936+
\@namedef{spx@fontawesome5@seealso}{\faIcon{share}}
937+
\@namedef{spx@fontawesome5@todo}{\faIcon{pen}}
938+
\@namedef{spx@fontawesome5@important}{\faIcon{pause-circle}}
939+
\@namedef{spx@fontawesome5@caution}{\faIcon{radiation}}
940+
\@namedef{spx@fontawesome5@warning}{\faIcon{exclamation-triangle}}
941+
\@namedef{spx@fontawesome5@attention}{\faIcon{exclamation-triangle}}
942+
\@namedef{spx@fontawesome5@danger}{\faIcon{radiation}}
943+
\@namedef{spx@fontawesome5@error}{\faIcon{times-circle}}
944+
945+
\def\spx@fontawesome@note {\faicon{info-circle}}
946+
\def\spx@fontawesome@hint {\faicon{lightbulb-o}}
947+
\def\spx@fontawesome@tip {\faicon{lightbulb-o}}
948+
\def\spx@fontawesome@seealso {\faicon{share}}
949+
\def\spx@fontawesome@todo {\faicon{pencil}}
950+
\def\spx@fontawesome@important{\faicon{pause-circle}}
951+
\def\spx@fontawesome@caution {\faicon{bolt}}
952+
\def\spx@fontawesome@warning {\faicon{exclamation-triangle}}
953+
\def\spx@fontawesome@attention{\faicon{exclamation-triangle}}
954+
\def\spx@fontawesome@danger {\faicon{bolt}}
955+
\def\spx@fontawesome@error {\faicon{times-circle}}
956+
957+
% \spx@none@{note,hint,...} left undefined, the \@nameuse will be \relax
958+
\def\spx@titleicon@default#1{\@nameuse{spx@\spx@opt@iconpackage @#1}}
933959
\setkeys{sphinx}{
934-
% Icon defaults.
935-
div.note_title-icon = \spx@faIcon{info-circle},
936-
div.hint_title-icon = \spx@faIcon[regular]{lightbulb},
937-
div.tip_title-icon = \spx@faIcon[regular]{lightbulb},
938-
div.seealso_title-icon = \spx@faIcon{share},
939-
div.todo_title-icon = \spx@faIcon{pen},
940-
div.important_title-icon = \spx@faIcon{pause-circle},
941-
div.caution_title-icon = \spx@faIcon{radiation},
942-
div.warning_title-icon = \spx@faIcon{exclamation-triangle},
943-
div.attention_title-icon = \spx@faIcon{exclamation-triangle},
944-
div.danger_title-icon = \spx@faIcon{radiation},
945-
div.error_title-icon = \spx@faIcon{times-circle},
960+
div.note_title-icon = \spx@titleicon@default{note},
961+
div.hint_title-icon = \spx@titleicon@default{hint},
962+
div.tip_title-icon = \spx@titleicon@default{tip},
963+
div.seealso_title-icon = \spx@titleicon@default{seealso},
964+
div.todo_title-icon = \spx@titleicon@default{todo},
965+
div.important_title-icon = \spx@titleicon@default{important},
966+
div.caution_title-icon = \spx@titleicon@default{caution},
967+
div.warning_title-icon = \spx@titleicon@default{warning},
968+
div.attention_title-icon = \spx@titleicon@default{attention},
969+
div.danger_title-icon = \spx@titleicon@default{danger},
970+
div.error_title-icon = \spx@titleicon@default{error},
946971
% MEMO: the new at 8.1.0 defaults for contents/topic/sidebar directives
947972
% use no icons, they use \sphinxdotitlerow which detects automatically
948973
% whether title-icon key has been set or not.

sphinx/texinputs/sphinxlatexadmonitions.sty

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
%% NOTICES AND ADMONITIONS
22
%
33
% change this info string if making any custom modification
4-
\ProvidesPackage{sphinxlatexadmonitions}[2024/10/11 v8.1.1 admonitions]
4+
\ProvidesPackage{sphinxlatexadmonitions}[2025/04/24 v8.3.0 admonitions]
55

66
% Provides support for this output mark-up from Sphinx latex writer:
77
%
@@ -342,8 +342,7 @@
342342
\textcolor{sphinx#1TtlFgColor}{%
343343
\@nameuse{sphinx#1TtlIcon}%
344344
% The next macro is located here for legacy reasons of earlier
345-
% functioning of \spx@faIcon. When fontawesome{5,}.sty both
346-
% are unavailable, it (formerly) gobbled this next macro.
345+
% functioning of sphinx.sty now removed \spx@faIcon macro.
347346
% We leave it here now although it could be moved to after
348347
% the closing brace.
349348
\sphinxtitlerowaftericonspacecmd

0 commit comments

Comments
 (0)