executablebooks / sphinx-design

A sphinx extension for designing beautiful, screen-size responsive web components.
https://sphinx-design.readthedocs.io/en/furo-theme/
MIT License
194 stars 60 forks source link

Tabs items shouldn't be rendered as they are in LaTeX output #218

Open dbitouze opened 1 month ago

dbitouze commented 1 month ago

Context

Currently, tabs such as:

.. tab-set::

    .. tab-item:: Label1

                  Content 1

    .. tab-item:: Label2

                  Content 2

are converted for the PDF's LaTeX output into the following .tex code:

\begin{sphinxuseclass}{sd-tab-set}
\begin{sphinxuseclass}{sd-tab-item}\subsubsection*{Label1}

\begin{sphinxuseclass}{sd-tab-content}
\sphinxAtStartPar
Content 1

\end{sphinxuseclass}
\end{sphinxuseclass}
\begin{sphinxuseclass}{sd-tab-item}\subsubsection*{Label2}

\begin{sphinxuseclass}{sd-tab-content}
\sphinxAtStartPar
Content 2

\end{sphinxuseclass}
\end{sphinxuseclass}
\end{sphinxuseclass}

This solution is sub-optimal because it introduces a level of structure (sub-sub-section) that may not be consistent with the context.

Proposal

Something such as what results from a definition list would be much better:

\begin{description}
\sphinxlineitem{Label1}
\sphinxAtStartPar
Content 1

\sphinxlineitem{Label2}
\sphinxAtStartPar
Content 2

\end{description}

Tasks and updates

No response

jfbu commented 1 month ago

@dbitouze I did not investigate where the \subsubsection* mark-up originates but defining appropriately the sphinxclasssd-tab-set, sphinxclasssd-tab-item and sphinxclasssd-tab-content LaTeX environment could transmogrify the mark-up you show into the one you wish.

edited to do s/sphinx/sphinxclass/ sorry

jfbu commented 1 month ago

I tried with

% Support **experimental** pour les tab-set de sphinx-design
% cf https://github.com/executablebooks/sphinx-design/issues/218
% ATTENTION C'EST FRAGILE CAR IL NE FAUT PAS QUE LE MARK-UP LATEX DE
% sphinx-design CHANGE (surtout pour sd-tab-item)
\newenvironment{sphinxclasssd-tab-set}{\begin{description}}{\end{description}}
\newenvironment{sphinxclasssd-tab-item}[3]{\item[#3]\leavevmode}{}
% pas besoin pour le moment de définir sphinxsd-tab-content

in the preamble and it gives an acceptable result. The above has been tested with success on a big project, now it may not be at all a sufficient test as that project might have been using sphinx-design tab-set always the same way. About the \leavevmode the contents were often code-blocks and for some reason I needed it to avoid overlap in the output (that may be an upstream Sphinx issue, not sure, to be checked at later date).

jfbu commented 1 month ago

@dbitouze I should probably have proposed

\newenvironment{sphinxclasssd-tab-item}[3]{\sphinxlineitem{#3}}{}

following more closely your initial advice with \sphinxlineitem.

I think \sphinxlineitem main purpose is to handle situations with a label but no contents, which may not be probable here, but it also avoids collision with a literal block as content, so no \leavevmode addition is needed. Besides this is indeed the mark-up produced by Sphinx from

Term
 ::

   hello

which gives

\begin{description}
\sphinxlineitem{Term}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{n}{hello}
\end{sphinxVerbatim}

\end{description}

and renders correctly.

You could use sphinxclasssd-tab-content to do something for example with \sphinxsetup to modify the characteristics of the rendered verbatim blocks which are the contents, style them especially. But this could also be done already at sphinxclasssd-tab-item level. I don't know if multiple tab-content can appear in one tab-item.