From 7c1b6730768ed81f2bb137ec5ef71ef30dd915eb Mon Sep 17 00:00:00 2001 From: Jesse Tan Date: Thu, 9 Jan 2020 11:05:05 +0100 Subject: [PATCH 1/3] Add LaTeX styling hook for :kbd: role --- doc/latex.rst | 2 ++ sphinx/texinputs/sphinx.sty | 1 + sphinx/writers/latex.py | 2 ++ tests/test_markup.py | 7 +++++++ 4 files changed, 12 insertions(+) diff --git a/doc/latex.rst b/doc/latex.rst index dd5fd1679..81f70dc1e 100644 --- a/doc/latex.rst +++ b/doc/latex.rst @@ -817,6 +817,8 @@ Macros multiple paragraphs in header cells of tables. .. versionadded:: 1.6.3 ``\sphinxstylecodecontinued`` and ``\sphinxstylecodecontinues``. + .. versionadded:: 2.4.0 + ``\sphinxkeyboard`` - ``\sphinxtableofcontents``: it is a wrapper (defined differently in :file:`sphinxhowto.cls` and in :file:`sphinxmanual.cls`) of standard ``\tableofcontents``. The macro diff --git a/sphinx/texinputs/sphinx.sty b/sphinx/texinputs/sphinx.sty index 3e67b5610..e27b44aa8 100644 --- a/sphinx/texinputs/sphinx.sty +++ b/sphinx/texinputs/sphinx.sty @@ -1836,6 +1836,7 @@ \protected\def\sphinxtitleref#1{\emph{#1}} \protected\def\sphinxmenuselection#1{\emph{#1}} \protected\def\sphinxguilabel#1{\emph{#1}} +\protected\def\sphinxkeyboard#1{\sphinxcode{#1}} \protected\def\sphinxaccelerator#1{\underline{#1}} \protected\def\sphinxcrossref#1{\emph{#1}} \protected\def\sphinxtermref#1{\emph{#1}} diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py index 55348145f..a370b5144 100644 --- a/sphinx/writers/latex.py +++ b/sphinx/writers/latex.py @@ -1935,6 +1935,8 @@ class LaTeXTranslator(SphinxTranslator): def visit_literal(self, node: Element) -> None: if self.in_title: self.body.append(r'\sphinxstyleliteralintitle{\sphinxupquote{') + elif 'kbd' in node['classes']: + self.body.append(r'\sphinxkeyboard{\sphinxupquote{') else: self.body.append(r'\sphinxcode{\sphinxupquote{') diff --git a/tests/test_markup.py b/tests/test_markup.py index edf4d7379..b6d99db90 100644 --- a/tests/test_markup.py +++ b/tests/test_markup.py @@ -230,6 +230,13 @@ def get_verifier(verify, verify_re): '

Foo

', r'\sphinxguilabel{Foo}', ), + ( + # kbd role + 'verify', + ':kbd:`space`', + '

space

', + '\\sphinxkeyboard{\\sphinxupquote{space}}', + ), ( # non-interpolation of dashes in option role 'verify_re', From 6e83f0dcb3159da614db53e74b472cf94f34fb17 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Thu, 5 Mar 2020 23:46:58 +0900 Subject: [PATCH 2/3] doc: fix a versionchnaged to correct one --- doc/latex.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/latex.rst b/doc/latex.rst index 81f70dc1e..59a785c1e 100644 --- a/doc/latex.rst +++ b/doc/latex.rst @@ -817,7 +817,7 @@ Macros multiple paragraphs in header cells of tables. .. versionadded:: 1.6.3 ``\sphinxstylecodecontinued`` and ``\sphinxstylecodecontinues``. - .. versionadded:: 2.4.0 + .. versionadded:: 3.0 ``\sphinxkeyboard`` - ``\sphinxtableofcontents``: it is a wrapper (defined differently in :file:`sphinxhowto.cls` and in From 52ac6f11781464bcad24b21ec2a03557956481c6 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Thu, 5 Mar 2020 23:48:15 +0900 Subject: [PATCH 3/3] Update CHANGES for PR #7005 --- CHANGES | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES b/CHANGES index 74dc980f5..46fe00fa9 100644 --- a/CHANGES +++ b/CHANGES @@ -68,6 +68,7 @@ Features added ``no-scaled-link`` class * #7144: Add CSS class indicating its domain for each desc node * #7211: latex: Use babel for Chinese document when using XeLaTeX +* #7005: LaTeX: Add LaTeX styling macro for :rst:role:`kbd` role * #7220: genindex: Show "main" index entries at first * #7103: linkcheck: writes all links to ``output.json`` * #7025: html search: full text search can be disabled for individual document