1

I have a custom newtcblisting defined, with an optional title. I would like to keep on the \lstlistoflistings only the ones with titles on it (this also affects numbering). Also, i have that unwanted tcolorbox in the index.

In the MWE, the expected number for the second listing would be 1, since the first one doesn't have a title:

MWE

\documentclass[12pt]{book}
\usepackage[utf8]{inputenc}
\usepackage{listings}
\usepackage{amssymb,amsmath,amsthm,amsfonts}
\usepackage[spanish]{babel}
\usepackage[nolist]{acronym}
\usepackage[table]{xcolor}
\usepackage[breakable,listings,skins,hooks]{tcolorbox}

\renewcommand{\lstlistingname}{Código} % Cambio 'Listing 4.1:' por 'Código 4.1:'
\renewcommand*{\lstlistlistingname}{Lista de cuadros de código}

\begin{document}

\lstdefinelanguage{isabelle}{
    keywords=[1]{abbreviation,by,contractLoop}
}
\lstdefinestyle{Isabelle}{
  language=isabelle,
  escapeinside={&}{&},
  columns=fixed,
  extendedchars,
  captionpos=b,                    
  breaklines=true,
  basewidth={0.5em,0.45em},
  basicstyle=\ttfamily,
  mathescape,
}

\newtcblisting[blend into=listings]{code}[2][]{%
 breakable,
 boxrule=0.75pt,
 listing options={ style={#2} },
 listing only,
 enhanced,
 listing remove caption=false,
 attach boxed title to bottom center={yshift=-8pt},
 before skip=15pt plus 2pt,after skip=15pt plus 2pt,
 boxed title style={enhanced jigsaw, colback=white, sharp corners, boxrule=0pt},
 coltitle=black,
 overlay first app={%
   \draw[dashed,line width=0.75pt,xshift=0.75pt] (frame.south east) -- (frame.south west); % chktex 8
  },
 overlay middle app={%
   \draw[dashed,line width=0.75pt,xshift=-0.75pt] (frame.north east) -- (frame.north west); % chktex 8
   \draw[dashed,line width=0.75pt,xshift=0.75pt] (frame.south east) -- (frame.south west); % chktex 8
  },
 overlay last app={%
   \draw[dashed,line width=0.75pt,xshift=-0.75pt] (frame.north east) -- (frame.north west); % chktex 8
  },
  #1
}



\begin{code}{Isabelle}
newtype Value = Value
    {getValue :: Map CurrencySymbol (Map TokenName Integer)}
\end{code}

\begin{code}[title=Definicion del tipo \texttt{Value}]{Isabelle}
newtype Value = Value
    {getValue :: Map CurrencySymbol (Map TokenName Integer)}
\end{code}


\end{document}

1 Answer 1

0

You can define a new environment, for example code*, which is blended into listings, but is unnumbered and adds no list entries.

\newtcblisting[blend into=listings]{code}[2][]{my code env={#1}{#2}}
\newtcblisting[blend into=listings, no counter, list inside=]{code*}[2][]{my code env={#1}{#2}}

Full example

\documentclass[12pt]{book}
\usepackage[utf8]{inputenc}
\usepackage{listings}
\usepackage{amssymb,amsmath,amsthm,amsfonts}
\usepackage[spanish]{babel}
\usepackage[nolist]{acronym}
\usepackage[table]{xcolor}
\usepackage[breakable,listings,skins,hooks]{tcolorbox}

\renewcommand{\lstlistingname}{Código} % Cambio 'Listing 4.1:' por 'Código 4.1:'
\renewcommand*{\lstlistlistingname}{Lista de cuadros de código}

\begin{document}

\lstdefinelanguage{isabelle}{
    keywords=[1]{abbreviation,by,contractLoop}
}
\lstdefinestyle{Isabelle}{
  language=isabelle,
  escapeinside={&}{&},
  columns=fixed,
  extendedchars,
  captionpos=b,                    
  breaklines=true,
  basewidth={0.5em,0.45em},
  basicstyle=\ttfamily,
  mathescape,
}

\tcbset{
  my code env/.style 2 args={
    breakable,
    boxrule=0.75pt,
    listing options={ style={#2} },
    listing only,
    enhanced,
    listing remove caption=false,
    attach boxed title to bottom center={yshift=-8pt},
    before skip=15pt plus 2pt,after skip=15pt plus 2pt,
    boxed title style={enhanced jigsaw, colback=white, sharp corners, boxrule=0pt},
    coltitle=black,
    overlay first app={%
      \draw[dashed,line width=0.75pt,xshift=0.75pt] (frame.south east) -- (frame.south west); % chktex 8
    },
    overlay middle app={%
      \draw[dashed,line width=0.75pt,xshift=-0.75pt] (frame.north east) -- (frame.north west); % chktex 8
      \draw[dashed,line width=0.75pt,xshift=0.75pt] (frame.south east) -- (frame.south west); % chktex 8
    },
    overlay last app={%
      \draw[dashed,line width=0.75pt,xshift=-0.75pt] (frame.north east) -- (frame.north west); % chktex 8
    },
    #1
  }
}

\newtcblisting[blend into=listings]{code}[2][]{my code env={#1}{#2}}
\newtcblisting[blend into=listings, no counter, list inside=]{code*}[2][]{my code env={#1}{#2}}

\lstlistoflistings

\begin{code*}{Isabelle}
newtype Value = Value
    {getValue :: Map CurrencySymbol (Map TokenName Integer)}
\end{code*}

\begin{code}[title=Definicion del tipo \texttt{Value}]{Isabelle}
newtype Value = Value
    {getValue :: Map CurrencySymbol (Map TokenName Integer)}
\end{code}

\end{document}

enter image description here

You must log in to answer this question.

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