Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have a source code listing with minted environment. How can I make a counter/caption to be shown as follows.

enter image description here

I also need to make \tableofsourcecode to enlist all the source code references.

The used source code environment is minted.

\documentclass[article]{memoir}

\usepackage{listings}
\usepackage{xcolor}
\usepackage{textcomp}
\usepackage[T1]{fontenc}
\usepackage{minted}

\begin{document}

\begin{minted}[mathescape,
               linenos,
               numbersep=5pt,
               gobble=0,
               frame=lines,
               framesep=2mm,
               fontsize=\tiny]{java}
public static void main(String[] args) {
    try {
        Registry r = LocateRegistry.getRegistry();
        r.bind("printer", new RemotePrinterImpl());
    }
    catch (Exception e){
        e.printStackTrace();
    }
}
\end{minted}

\end{document} 
share|improve this question

1 Answer 1

up vote 2 down vote accepted

You can use the listing environment as follows:

\documentclass[article]{memoir}

\usepackage{listings}
\usepackage{xcolor}
\usepackage{textcomp}
\usepackage[T1]{fontenc}
\usepackage{minted}

\renewcommand\listingscaption{code}

\begin{document}

\listoflistings

\begin{listing}
\caption{main}
\begin{minted}[mathescape,
               linenos,
               numbersep=5pt,
               gobble=0,
               frame=lines,
               framesep=2mm,
               fontsize=\tiny]{java}
public static void main(String[] args) {
    try {
        Registry r = LocateRegistry.getRegistry();
        r.bind("printer", new RemotePrinterImpl());
    }
    catch (Exception e){
        e.printStackTrace();
    }
}
\end{minted}

\end{listing}

\end{document} 

The default caption would be 'Listing 1: main'. So you can change the listingcaption with \renewcommand\listingscaption{code} to whatever you want, 'code 1: main' in this case.

EDIT: to print a list of all listings, you can use the \listoflistings command.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.