I would like to add wrap something around an existing environment.

Consider an existing environment sphinxVerbatim, I would like to renew this environment by adding something before and after that environment call. I could write this, but obviously it doesn't work:


In context, I would like to wrap my code environment around an existing environment named sphinxVerbatim:


Sphinx generates some code such as:

\PYG{c+cp}{\PYGZsh{}}\PYG{c+cp}{include} \PYG{c+cpf}{\PYGZlt{}stdio.h\PYGZgt{}}

and I would like to redeclare this environment for this sphinxVerbatim to be wrapped inside a \begin{code}...\end{code}.

The main issue I have with sphinxVerbatim is that the frame goes outside from the page area, I want it to be inside with some margin as shown below:

enter image description here

enter image description here I thought I could simply redeclare sphinxVerbatim...

  • The etoolbox package defines \BeforeBeginEnvironment and \AfterEndEnvironment commands.
    – Bernard
    Commented Aug 2, 2020 at 14:41
  • @Bernard I don't think I can do \begin{something} inside a \BeforeBeginEnvironment :(
    – nowox
    Commented Aug 2, 2020 at 14:43
  • 1
    You didn't give many details. Could you show what you're trying to obtain and what you tried?
    – Bernard
    Commented Aug 2, 2020 at 15:06
  • @Bernard I've added some information to my question
    – nowox
    Commented Aug 2, 2020 at 15:10

1 Answer 1


You may benefit from looking at the documentation for Sphinx: https://www.sphinx-doc.org/en/master/latex.html

The section on sphinxsetup mentions the ability to do things like adding a frame, coloring, etc. which should allow you to do the customizations that you like.

  • No unfortunately it doesn't work. The standard Sphinx options are very ugly. I would like to declare a code-block inside a tcolorbox environment.
    – nowox
    Commented Aug 2, 2020 at 15:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .