2

I use minted for listing Objective-C code and I need to replace the label text from Listing 1. to Source Code #chapter_number#.#subsection_number#.#subsubsection_number#.#label_number# like "Source Code 2.2.2.1. Starting the accelerometer". Also, I need to refer this like "Source Code 2.2.2.1.".

How can I accomplish this?

I tried:

\usepackage{minted}
    \renewcommand\listingscaption{Source Code \thesubsection -}

But it isn't working when I try to use \cref or \ref or \autoref I got "listing 1 1".

Thanks for your time and help!

1
  • 1
    Welcome to TeX.SX! Shouldn't caption_number be chapter_number?
    – egreg
    Commented Jun 17, 2014 at 9:10

1 Answer 1

3

This seems to be what you want:

\documentclass{book}
\usepackage{minted}

\usepackage{hyperref}
\usepackage{cleveref}

\renewcommand{\listingscaption}{Source code}
\renewcommand{\thelisting}{\thesubsection.\arabic{listing}}
\crefname{listing}{source code}{source codes}

\begin{document}
\mainmatter
\chapter{Ctitle}
\section{Stitle}
\subsection{Sstitle}

\begin{listing}
\begin{minted}{objective-c}
Abc
\end{minted}
\caption{Caption}\label{list}
\end{listing}

References: \cref{list}, \ref{list}

\end{document}

enter image description here

1
  • Thank you very much. That works as I imagined :). Thanks for your help.
    – flatronka
    Commented Jun 17, 2014 at 12:43

You must log in to answer this question.

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