0

I am trying to use \counterwithout{listing}{chapter}

  1. Chngcntr: \counterwithout not working
  2. Number listings the same way as figures and tables

But memoir keeps complaining Class memoir Error: listing is not a counter

\documentclass[english,12pt,a4paper,twoside]{memoir}
\usepackage{listings}
\AtBeginDocument{\counterwithout{listing}{chapter}}

\begin{document}  % test5.tex:5: Class memoir Error: listing is not a counter.
\chapter{Hi}

\begin{lstlisting}[caption=Code,label=acode]
Code
\end{lstlisting}

Something...

\end{document}

Memoir code:

\newcommand{\@ifbothcntrs}[3]{%
  \@ifundefined{c@#1}{% counter undefined
    \@memerror{#1 is not a counter}{\@eha}}%
  {% else counter is defined
    \@ifundefined{c@#2}{% within undefined
      \@memerror{#2 is not a counter}{\@eha}}%
    {% else both counter and within  are defined
     #3}}}

\newcommand{\counterwithin}{\@ifstar{\@csinstar}{\@csin}}
\newcommand{\@csinstar}[2]{%
  \@ifbothcntrs{#1}{#2}{\@addtoreset{#1}{#2}}}
\newcommand{\@csin}[2]{%
  \@ifbothcntrs{#1}{#2}{\@addtoreset{#1}{#2}%
                        \@namedef{the#1}{\@nameuse{the#2}.\arabic{#1}}}}

\newcommand{\counterwithout}{\@ifstar{\@csoutstar}{\@csout}}
\newcommand{\@csoutstar}[2]{%
  \@ifbothcntrs{#1}{#2}{\@removefromreset{#1}{#2}}}
\newcommand{\@csout}[2]{%
  \@ifbothcntrs{#1}{#2}{\@removefromreset{#1}{#2}%
                        \@namedef{the#1}{\arabic{#1}}}}
2
  • 5
    the name of the counter is lstlisting – Ulrike Fischer Aug 2 '20 at 18:43
  • Thanks! I see now that I should include the package minted (which defines the counter listing) instead of including the package listings (which defines the counter lstlisting. – user Aug 2 '20 at 18:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.