[rtems-central commit] sphinxcontent: Add SphinxContent.latex_tiny()

Sebastian Huber sebh at rtems.org
Tue May 9 13:45:26 UTC 2023


Module:    rtems-central
Branch:    master
Commit:    35a64e258226397348aa6c7060247f0e22b5cd2a
Changeset: http://git.rtems.org/rtems-central/commit/?id=35a64e258226397348aa6c7060247f0e22b5cd2a

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Fri May  5 14:41:18 2023 +0200

sphinxcontent: Add SphinxContent.latex_tiny()

---

 rtemsspec/sphinxcontent.py             | 18 ++++++++++++++++++
 rtemsspec/tests/test_content_sphinx.py | 16 ++++++++++++++++
 2 files changed, 34 insertions(+)

diff --git a/rtemsspec/sphinxcontent.py b/rtemsspec/sphinxcontent.py
index f9849fc1..abec5553 100644
--- a/rtemsspec/sphinxcontent.py
+++ b/rtemsspec/sphinxcontent.py
@@ -72,6 +72,7 @@ def _grid_row(row: Iterable[str], maxi: Iterable[int]) -> str:
 class SphinxContent(Content):
     """ This class builds Sphinx content. """
 
+    # pylint: disable=too-many-public-methods
     def __init__(self, section_level: int = 2):
         super().__init__("CC-BY-SA-4.0", True)
         self._tab = "    "
@@ -195,6 +196,23 @@ class SphinxContent(Content):
         yield self.open_section(name, label_prefix, label)
         self.close_section()
 
+    def open_latex_tiny(self, size: str = "tiny") -> None:
+        """ Opens a LaTeX tiny environment. """
+        with self.directive("raw", "latex"):
+            self.add(f"\\begin{{{size}}}")
+
+    def close_latex_tiny(self, size: str = "tiny") -> None:
+        """ Closes a LaTeX tiny environment. """
+        with self.directive("raw", "latex"):
+            self.add(f"\\end{{{size}}}")
+
+    @contextmanager
+    def latex_tiny(self, size: str = "tiny") -> Iterator[None]:
+        """ Opens a LaTeX tiny environment. """
+        self.open_latex_tiny(size)
+        yield
+        self.close_latex_tiny(size)
+
     def add_licence_and_copyrights(self) -> None:
         """
         Adds a licence and copyright block according to the registered licenses
diff --git a/rtemsspec/tests/test_content_sphinx.py b/rtemsspec/tests/test_content_sphinx.py
index 82312157..59903283 100644
--- a/rtemsspec/tests/test_content_sphinx.py
+++ b/rtemsspec/tests/test_content_sphinx.py
@@ -207,6 +207,22 @@ def test_add_image():
 """
 
 
+def test_latex_tiny():
+    content = SphinxContent()
+    with content.latex_tiny():
+        content.add("abc")
+    assert str(content) == """.. raw:: latex
+
+    \\begin{tiny}
+
+abc
+
+.. raw:: latex
+
+    \\end{tiny}
+"""
+
+
 def test_add_index_entries():
     content = SphinxContent()
     content.add_index_entries(["x", "y"])



More information about the vc mailing list