Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option for centering and natural width during it #133

Open
tmplt opened this issue Sep 27, 2016 · 2 comments
Open

Add option for centering and natural width during it #133

tmplt opened this issue Sep 27, 2016 · 2 comments

Comments

@tmplt
Copy link

tmplt commented Sep 27, 2016

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

@gpoore
Copy link
Owner

gpoore commented Sep 27, 2016

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.

@h-2
Copy link

h-2 commented Sep 11, 2019

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...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants