Skip to content

Commit 6188f62

Browse files
Merge branch 'master' into dependabot/pip/types-docutils-0.21.0.20250516
2 parents 97f7aaa + 5461707 commit 6188f62

File tree

9 files changed

+143
-90
lines changed

9 files changed

+143
-90
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*.so
44
*.swp
55

6+
.auto/
67
.dir-locals.el
78
.cache/
89
.idea

CHANGES.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ Features added
2020
``linkcheck_allowed_redirects = {}``.
2121
Patch by Adam Turner.
2222
* #13497: Support C domain objects in the table of contents.
23+
* #13500: LaTeX: add support for ``fontawesome6`` package.
24+
Patch by Jean-François B.
2325
* #13535: html search: Update to the latest version of Snowball (v3.0.1).
2426
Patch by Adam Turner.
2527
* #13704: autodoc: Detect :py:func:`typing_extensions.overload <typing.overload>`
@@ -29,6 +31,8 @@ Features added
2931
Bugs fixed
3032
----------
3133

34+
* #12821: LaTeX: URLs/links in section titles should render in PDF.
35+
Patch by Jean-François B.
3236
* #13369: Correctly parse and cross-reference unpacked type annotations.
3337
Patch by Alicia Garcia-Raboso.
3438
* #13528: Add tilde ``~`` prefix support for :rst:role:`py:deco`.

doc/latex.rst

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,18 +1006,20 @@ 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
1020+
``div.note_title-icon`` and similar keys to use then that LaTeX package
1021+
interface (see the :ref:`additionalcss` section for these extra
1022+
``'sphinxsetup'`` keys).
10211023
10221024
.. versionadded:: 7.4.0
10231025
@@ -1410,17 +1412,17 @@ The next keys, for admonitions, :dudir:`topic`, contents_, and
14101412
(it applies only to the icon, not to the title of the admonition).
14111413
14121414
- ``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.
1415+
icon. If you want to modify the icons used by Sphinx, employ in these keys
1416+
the ``\faIcon`` LaTeX command (assuming either ``fontawesome6`` or
1417+
``fontawesome5`` LaTeX package is available on your system). For example
1418+
the default for :dudir:`note` is
1419+
``div.note_title-icon=\faIcon{info-circle}`` with ``fontawesome5`` and
1420+
``div.note_title-icon=\faIcon{circle-info}`` with ``fontawesome6`` (which is
1421+
used automatically if available). If your system only provides the
1422+
``fontawesome`` package (automatically detected) use its command ``\faicon``
1423+
rather in order to modify the choice of icons. The ``iconpackage`` key can
1424+
be used to use some other package providing icons, use then the commands
1425+
suitable to that package as values of the ``div.<type>_title-icon`` keys.
14241426
14251427
.. note::
14261428

sphinx/texinputs/sphinx.sty

Lines changed: 87 additions & 61 deletions
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
@@ -67,7 +67,7 @@
6767
Footnote rendering may have had problems, due to extra package or
6868
document class; check latex log for instructions}%
6969
\@namedef{sphinx_buildwarning_badiconpackage}{%
70-
You have set iconpackage=\spx@opt@iconpackage, but this LaTeX package
70+
You have set iconpackage=\spx@usr@iconpackage, but this LaTeX package
7171
is not found}%
7272

7373
%% OPTION HANDLING
@@ -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,106 @@
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}{%
927-
You have set iconpackage=\spx@opt@iconpackage\MessageBreak
928-
But \spx@opt@iconpackage.sty is not found by LaTeX}
910+
\let\spx@usr@iconpackage\spx@opt@iconpackage
911+
\sphinxbuildwarning{badiconpackage}%
912+
\PackageWarningNoLine{sphinx}{%
913+
You have set iconpackage=\spx@usr@iconpackage\MessageBreak
914+
But \spx@usr@iconpackage.sty is not found by LaTeX}
915+
\let\spx@opt@iconpackage\spxstring@none
929916
}%
930917
\fi
931918
}
932919

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

sphinx/texinputs/sphinxlatexadmonitions.sty

Lines changed: 2 additions & 3 deletions
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

sphinx/texinputs/sphinxlatexstyletext.sty

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
%% TEXT STYLING
22
%
33
% change this info string if making any custom modification
4-
\ProvidesPackage{sphinxlatexstyletext}[2024/07/28 v8.1.0 text styling]
4+
\ProvidesPackage{sphinxlatexstyletext}[2025/05/24 v8.3.0 text styling]
55

66
% 7.4.0 has moved all that is related to admonitions to sphinxlatexadmonitions.sty
77
% 8.1.0 has moved topic/contents/sidebar to sphinxlatexshadowbox.sty
@@ -57,7 +57,11 @@
5757
% reduce hyperref "Token not allowed in a PDF string" warnings on PDF builds
5858
\AtBeginDocument{\pdfstringdefDisableCommands{%
5959
% all "protected" macros possibly ending up in section titles should be here
60-
% TODO: examine if \sphinxhref, \sphinxurl, \sphinnolinkurl should be handled
60+
% next four were added so that URLs and internal links in titles can be allowed
61+
\let\sphinxurl \@firstofone
62+
\let\sphinxnolinkurl\@firstofone
63+
\let\sphinxhref \@secondoftwo
64+
\def\hyperref[#1]#2{#2}% for PDF bookmark to ignore #1
6165
\let\sphinxstyleemphasis \@firstofone
6266
\let\sphinxstyleliteralemphasis \@firstofone
6367
\let\sphinxstylestrong \@firstofone

sphinx/writers/latex.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1962,7 +1962,7 @@ def visit_reference(self, node: Element) -> None:
19621962
uri = node.get('refuri', '')
19631963
if not uri and node.get('refid'):
19641964
uri = '%' + self.curfilestack[-1] + '#' + node['refid']
1965-
if self.in_title or not uri:
1965+
if not uri:
19661966
self.context.append('')
19671967
elif uri.startswith('#'):
19681968
# references to labels in the same document

tests/roots/test-root/markup.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,3 +469,9 @@ Smart quotes
469469

470470
.. [#] Like footnotes.
471471

472+
473+
Link in a title: `Field lists <https://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html#field-lists>`_
474+
---------------------------------------------------------------------------------------------------------------------
475+
476+
Again: https://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html#field-lists
477+
------------------------------------------------------------------------------------------

tests/test_builders/test_build_latex.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,17 @@ def compile_latex_document(app, filename='projectnamenotset.tex', docclass='manu
7272
filename,
7373
]
7474
subprocess.run(args, capture_output=True, check=True)
75+
# Run a second time (if engine is pdflatex), to have a chance to
76+
# detect problems caused on second LaTeX pass (for example, this
77+
# is required for the TOC in PDF to show up, for internal
78+
# hyperlinks to actually work). Of course, this increases
79+
# duration of test, but also its usefulness.
80+
# TODO: in theory the correct way is to run Latexmk with options
81+
# as configured in the Makefile and in presence of latexmkrc
82+
# or latexmkjarc and also sphinx.xdy and other xindy support.
83+
# And two passes are not enough except for simplest documents.
84+
if app.config.latex_engine == 'pdflatex':
85+
subprocess.run(args, capture_output=True, check=True)
7586
except OSError as exc: # most likely the latex executable was not found
7687
raise pytest.skip.Exception from exc
7788
except CalledProcessError as exc:

0 commit comments

Comments
 (0)