gpoore / minted

minted is a LaTeX package that provides syntax highlighting using the Pygments library. Highlighted source code can be customized using fancyvrb.
1.75k stars 127 forks source link

Add "caption" and "captionpos" option #74

Open MrGoldenpioche opened 9 years ago

MrGoldenpioche commented 9 years ago

Hello,

I think it will be cool to add a "caption" and "captionpos" option. Before using Minted, I used \begin{lstlisting}

and there is a option for set directly the caption. Example.

\begin{lstlisting}[language=bash, caption="Installation of Oracle Java JDK 6 and 7", captionpos=b] mycode \end{lstlisting}

klmr commented 9 years ago

minted has the listingenvironment to do that. From the documentation:

\begin{listing}[H]
    \mint{cl}/(car (cons 1 '(2)))/ 
    \caption{Example of a listing.}
    \label{lst:example}
\end{listing}
MrGoldenpioche commented 9 years ago

Yes I know but im not able to do this. In your example you use \mint command which is only available for single line.... How can I use this option with the std command. \begin{minted}... ?

Le jeu. 23 avr. 2015 11:23, Konrad Rudolph notifications@github.com a écrit :

minted has the listingenvironment to do that. From the documentation:

\begin{listing}[H] \mint{cl}/(car (cons 1 '(2)))/ \caption{Example of a listing.} \label{lst:example}\end{listing}

— Reply to this email directly or view it on GitHub https://github.com/gpoore/minted/issues/74#issuecomment-95507732.

klmr commented 9 years ago

No, you misunderstood (a) what mint does and (b) how the listing environment works. Do read the documentation, it’s all explained there.

gpoore commented 9 years ago

As klmr has noted, minted can already do what you want with the listing environment, although it takes a little more typing than the case with the listings package.

Currently, the minted environment only typesets code. All additional functionality, likes captions, labels, and floats, is handled separately. I will think about whether caption-related options should be incorporated into the minted environment, or perhaps whether there should be a separate environment that functions as a shorthand for the minted and listing environment features combined. If additional functionality is added, it will probably take a while.

You should take a look at the tcblisting environment provided by the tcolorbox package, since when combined with minted it already provides most or all of what you want.

skanskan commented 5 years ago

Hello. How can I reduce the top and bottom blank space (margins) if I use ...?

\begin{listing}[H]
    \mint{cl}/(car (cons 1 '(2)))/ 
    \caption{Example of a listing.}
    \label{lst:example}
\end{listing}

I need to write many of this codes within normal text and don't like to have too much white space in between.

muzimuzhi commented 5 years ago

@skanskan The vertical white space you mentioned is the vertical skip between every float environment and around text, and this skip is globally controlled by \intextsep, see https://latexref.xyz/Floats.html#Floats for detailed doc and other sep controllers.

listing environment is just an instance of float environment created by minted, with the help of float or newfloat pacakge.

skanskan commented 5 years ago

Now I'm doing it like this:

\definecolor{bg}{rgb}{0.9,0.95,1}
\newenvironment{code}{\captionsetup{type=table}}{}
\SetupFloatingEnvironment{listing}{name=Tabla}

\begin{code}
\begin{minted}[fontsize=\footnotesize,baselinestretch=1.3, bgcolor=bg]{text}
   my  code
\end{minted}
\caption{\label{mycaption} Mycaption.}
\end{code}

If I write two consecutive minted blocks the spacing is OK, but the caption (below) is confusing because it's not clear if it pertains to the code above or to the code below it. How can I place it closer to its code or even better inside the colored area?