minted icon indicating copy to clipboard operation
minted copied to clipboard

Add option for centering and natural width during it

Open tmplt opened this issue 9 years ago • 2 comments

Last year when I wrote my bachelor's degree minted was of great use. But as the tex.stackexchange.com question I asked explains, the code snippet doesn't keep its good looks when centering it. Could an option be added to center the code like the answer presents?

For the sake of example completion, and unless this feature isn't added, here is the current environment I use:

% Here be dragons
\makeatletter
\newenvironment{code}
{
    \RecustomVerbatimEnvironment{Verbatim}{BVerbatim}{}
        \def\FV@BProcessLine##1{
            \hbox{
                \hbox to\z@{\hss\theFancyVerbLine\kern\FV@NumberSep}
                \FancyVerbFormatLine{##1}
            }
        }
    \VerbatimEnvironment
    \begin{figure}[htp]
    \centering
    \setbox\z@=\hbox\bgroup
    \begin{minted}{c++}
}
{
    \end{minted}\egroup
    \leavevmode\vbox{\hrule\kern2mm\box\z@\kern2mm\hrule}
    \end{figure}
}
\makeatother

and how it looks: minted, centered with natural width

tmplt avatar Sep 27 '16 16:09 tmplt

I'm afraid this isn't something that can be added easily. The code you have works for your case and gives nice results. However, adding something like this to minted would be complicated, because it would need to cooperate with all of the other minted options. Currently, it doesn't work with line numbering options, line breaking options, or page breaking, and there are probably lots of other incompatibilities.

Ultimately, the easiest way to get this feature would be to create a new verbatim environment that extends fancyvrb. That could get relatively technical. What we really need is a new verbatim package that provides lots of new options, including things like what you are suggesting.

gpoore avatar Sep 27 '16 17:09 gpoore

Just chiming in here that having a "natural width" option would be very much appreciated. Especially when using a background colour, the code snippet looks very weird spanning the whole page when it could occupy the center 30% instead.

The abovequoted workaround also does not work for me...

h-2 avatar Sep 11 '19 13:09 h-2