sphinx-inline-tabs icon indicating copy to clipboard operation
sphinx-inline-tabs copied to clipboard

Render tab title as section heading for latex

Open sscherfke opened this issue 2 years ago • 5 comments

Non-HTML build targets (e.g., Latex) don't support tabs.

Multiple tabs are correctly serialized in PDFs but the original Tab title is lost. It would be good if that tab title could be inserted has headings in that case.

Edit:

@BrennanGit 's comment contains a well working workaround: https://github.com/pradyunsg/sphinx-inline-tabs/issues/34#issuecomment-1771051042

sscherfke avatar Nov 29 '22 16:11 sscherfke

A PR for this would be welcome!

pradyunsg avatar Nov 30 '22 09:11 pradyunsg

I was afraid you were going to say that. 😅

I am not very experienced with writing Sphinx extensions but I am willing to help. Imho, the hardest problem is figuring out which nesting level you are in and which kind of heading/section you need to use. Do you know if this is something that the rest-nodes-tree can help with? e.g.:

def handle_tab_node(node, parent):
    level = parent.level + 1
    section = Section(level, node.description)
    section.add_child(node)
    return section

sscherfke avatar Nov 30 '22 10:11 sscherfke

I have an idea for an easy to implement improvement.

My current workaround is this:


Heading
=======

.. tab:: My Tab

   .. raw:: latex

      \subsubsection{My Tab}

Sub heading
-----------


.. tab:: Another Tab

   .. raw:: latex

      \paragraph{Another Tab}

A nicer (and maybe "good enough") solution would be:

Heading
=======

.. tab:: My Tab
   :latex: subsubsection

Sub heading
-----------

.. tab:: Another Tab
   :latex: paragraph

I don't know how easy to implement this would be.

sscherfke avatar Dec 09 '22 13:12 sscherfke

I have come up against this issue recently and I think I have a slightly different workaround for anyone else who ends up here.

Heading
=====

.. tab:: Linux

    .. only:: latex

        .. rubric:: Linux

    Linux instructions


.. tab:: Windows

    .. only:: latex

        .. rubric:: Windows

    Windows instructions


.. tab:: Mac

    .. only:: latex

        .. rubric:: Mac

    MacOS instructions

You can swap out rubric for a proper heading if you want it to appear in your toc.

The benefit over @sscherfke's suggestion is that we don't need to know the depth of heading in the full document.

I'd still love to see this more elegantly dealt with by sphinx though.

BrennanGit avatar Oct 19 '23 13:10 BrennanGit

I'm not really a Latex user but I do like the rubric approach as that's also something that could be implemented by tweaking how the specifics of the DOM work (we could have the tab label DOM node inherit from rubric maybe? -- if so, it'll actually get rendered that way in non-HTML output).

pradyunsg avatar Oct 19 '23 17:10 pradyunsg