2

I was looking to create a table of contents for my preliminary thesis topics as Acknowledgments, Abstract, etc. I would put it after the cover so the reader can easy access the actual Table of Contents, Acknowledgments, Abstract, etc. This is due because on my thesis template it is required about 30 pages of contents as Acknowledgments, Abstract, etc. before the actual Table of Contents and the chapters. Initially I looked over creating two table of contents and I found these questions:

  1. Add preliminary elements to the ToC
  2. Two independent TOCs
  3. How do I set up two independent tables of contents
  4. ToC chapter number width & memoir class
  5. \part and tocloft

But when trying to make things work with memoir class I got several errors and problems on my thesis template. Then I noticed I just actually need a simple list of things. Therefore I started searching on how to create lists of contents manually. Then I found these questions:

  1. How to get a list of appendices?
  2. How to create my own list of things

And come up with the following minimal example which works fine with the report class:

\documentclass{memoir}
% \documentclass{report}

\usepackage{tocloft}
\usepackage{hyperref}

\usepackage[english]{babel}
\hypersetup{colorlinks=true}

\newcommand{\listexamplename}{List of mycustomfiction}
\newlistof{mycustomfiction}{mcf}{\listexamplename}

\newcommand{\mycustomfiction}[1]
{%
    \refstepcounter{mycustomfiction}
    \addcontentsline{mcf}{mycustomfiction}
    {\protect\numberline{\themycustomfiction}#1}\par
}

\begin{document}

    \tableofcontents
    \newpage
    \listofmycustomfiction

    \chapter{Two mycustomfiction}
    \mycustomfiction{Your first example}
    \label{1st_ex}
    Your first example

    \mycustomfiction{Your second example}
    \label{2nd_ex}
    Your second example

    \chapter{One example}
    \mycustomfiction{Your third example. (See example \ref{1st_ex} and \ref{2nd_ex})}
    Your third example. (See example \ref{1st_ex} and \ref{2nd_ex})

\end{document}

But throw these errors with the memoir class:

! LaTeX Error: Command \mycustomfiction already defined.
               Or name \end... illegal, see p.192 of the manual.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.18 }

Your command was ignored.
Type  I <command> <return>  to replace it with another command,
or  <return>  to continue without it.

Redoing nameref's sectioning
Redoing nameref's label
LaTeX Info: Redefining \nameref on input line 20.
LaTeX Info: Redefining \ref on input line 20.
LaTeX Info: Redefining \pageref on input line 20.
LaTeX Info: Redefining \nameref on input line 20.

{D:/User/Documents/latex/texmfs/data/pdftex/config/pdftex.map}]
! Undefined control sequence.
l.24     \listofmycustomfiction

The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

[2

However when replacing the memoir class with report class, it does compiles without any errors:

enter image description here

How can it be fixed so I can build it with memoir class? Perhaps I should use another package other than tocloft


Update

Now I following the example from memoir class manual, but my list is going nuts:

enter image description here

\documentclass{memoir}

\usepackage{hyperref}
\hypersetup{colorlinks=true}

\usepackage[english]{babel}

\newcommand{\listanswername}{List of Answers}
\newlistof{listofanswers}{ans}{\listanswername}

\newcounter{answercounter}[chapter]
\renewcommand{\theanswercounter}{\arabic{answercounter}}

\newcommand{\answer}[1]
{
    \refstepcounter{answercounter}
    \par\noindent\textbf{Answer \theanswercounter. #1}
    \addcontentsline{ans}{answercounter}{\protect\numberline{\theanswercounter}#1}\par
}

\begin{document}

    \tableofcontents
    \newpage
    \listofanswers*

    \chapter{Chapter Two mycustomfiction}
    \answer{Your first example}
    Your first example

    \answer{Your second example}
    Your second example

    \chapter{One example}
    \answer{Your third example.}
    Your third example.

\end{document}

What is wrong with it?


Update 2

If I do:

\newcommand{\answer}[1]
{%
    \refstepcounter{answercounter}
    \addcontentsline{ans}{answercounter}{\newline\newline#1\hfill}
}

I got these warnings and format:

Underfull \hbox (badness 10000) in paragraph at lines 1--25

 []


Underfull \hbox (badness 10000) in paragraph at lines 1--25

 []


Underfull \hbox (badness 10000) in paragraph at lines 1--25

 []

[2]
Package hyperref Info: bookmark level for unknown answercounter defaults to 0 o
n input line 27.
 [3

enter image description here

user
  • 4,745
  • 3
    \newlistof create a control sequence with the same name. – Johannes_B Aug 27 '17 at 17:21
  • 1
    Doesn't memoir have some external stuff so you don't need to load tocloft? – Johannes_B Aug 27 '17 at 17:22
  • "This is due because on my thesis template it is required about 30 pages of contents as Acknowledgments, Abstract, etc. before the actual Table of Contents and the chapters." Well, this is weird... You could as well paste a link to your thesis requirements so we can sort it out... –  Aug 27 '17 at 17:26
  • 2
    Advanced tip: Sprinkle \show\mycustomfiction around your preamble and compile to see where a change happens. Works for other control sequences as well. – Johannes_B Aug 27 '17 at 17:29
  • Did you see "p.192 of the manual"? Check out if you really need memoir, or if it would be easier to use another class. You seem to be heads on making a memoir-compatible-custom-ABNT-class for UFSC (as I suppose). Also check out your grammar, it sounds clumsy and hard to grasp. E.g., "Why does my custom list", etc. –  Aug 27 '17 at 17:29
  • 2
    @Johannes_B: memoir does unfortunately emulate some other packages but incomplete, in my point of view, that's why I don't use memoir, however, it is possible to disemulate the packages –  Aug 27 '17 at 17:52
  • Don't mix solutions from memoir, KOMA and standard classes -- this is no good approach –  Aug 27 '17 at 17:53
  • @Johannes_B Thanks! I used your command, when I build with the report class it shows > \mycustomfiction=undefined. l.13 \show\mycustomfiction but when I build with memoir class it shows > \mycustomfiction=macro: ->\@ifstar {\@nameuse {mem@mycustomfiction}{01}}{\@nameuse {mem@mycustomfiction }{00}}. l.13 \show\mycustomfiction – user Aug 27 '17 at 18:12
  • 1
    @Joseph, I looked over page 192 on memoir manual but I do not see anything which makes me sense. But I searched for \newlistof on the memoir manual and I found on page 162 the section 9.3 NEW ‘LIST OF. . . ’ AND ENTRIES, which seems to explain the command \newlistof. Looked like I must remove the package tocloft and use the memoir own implementation of it. I am going to look into the manual and see if I can figure it out on how to create new lists with memoir implementation of tocloft. – user Aug 27 '17 at 18:17
  • @user: Joseph meant p 192. of the LaTeX manual, not memman.pdf –  Aug 27 '17 at 18:21
  • @ChristianHupfer, where is this manual? I cannot find it anywere: Where can I find the standard LaTeX reference manual?, is this: http://ctan.mirrors.hoobly.com/macros/latex/base/source2e.pdf ? – user Aug 27 '17 at 18:39
  • @ChristianHupfer what exactly does memoir do incompletely? – daleif Aug 27 '17 at 18:39
  • @daleif: Try `\documentclass{memoir}

    %\documentclass{report} %\usepackage{tocloft}

    \newcommand{\listofsomethingname}{List of something} \newlistof{foo}{foo}{\listofsomethingname} \begin{document} \listoffoo

    \end{document}-- it should work if I understandmemoircorrectly and then try the same with\documentclass{report}\usepackage{tocloft}`

    –  Aug 27 '17 at 18:44
  • @user: The manual isn't available as .pdf as far as I know –  Aug 27 '17 at 18:46
  • @daleif: According to tocloft manual the \newlistof macro generates the foo counter → it does so really with report (or another non-memoir) class, but it does not define \c@foo etc. with memoir's emulation of tocloft -- that's what I call incomplete –  Aug 27 '17 at 18:49
  • 3
    The thing is, after decades of LaTeX several (broadly used) classes came up and solutions to specific problems depend on the classes in use. Like cars ... The ashtray of a BMW won't fit into a Volkswagen, nor into a Mercedes, nor into a Mazda (to name just a few) but all ashtrays are doing the same job. It is a kind of messiness you have to accept. – Johannes_B Aug 27 '17 at 19:17

2 Answers2

3

Any \addcontentsline statement needs a proper format of contentsline, i.e. \addcontentsline{toc}{chapter}{...} etc.

This chapter name here is actually a macro defined usually by the class or package and has the name \l@chapter, there are \l@section etc. as well. Those macros define the indentation, the level, the spacings and the distance from the entry to the page number slot (usually on the right margin)

Using \newlistof{listofanswers}{ans}{...} does not define the \l@answers macro, however, this must be done with \newlistentry{answers}{ans}{0}, which defines the answers counter as well.

\documentclass{memoir}


\usepackage[english]{babel}

\newcommand{\listanswername}{List of Answers}
\newlistof{listofanswers}{ans}{\listanswername}
\newlistentry[chapter]{answers}{ans}{0}

\newcommand{\answer}[1]
{%
  \refstepcounter{answers}%
  \par\noindent\textbf{Answer \theanswers. #1}%
  \addcontentsline{ans}{answers}{\protect\numberline{\theanswers}#1}\par
}

\usepackage{hyperref}
\hypersetup{colorlinks=true}


\begin{document}

    \tableofcontents
    \newpage
    \listofanswers*

    \chapter{Chapter Two mycustomfiction}
    \answer{Your first example}
    Your first example

    \answer{Your second example}
    Your second example

    \chapter{One example}
    \answer{Your third example.}
    Your third example.

\end{document}

enter image description here

  • Thanks! This complements the answer on Poorly formatted newlistof with memoir teaching on how to create my own \l@answers macro instead of copy one from some other command. – user Aug 27 '17 at 21:13
  • 1
    Adding the table of preliminary contents to may full thesis immediately raised the issue ! No room for a new \write error. After I few more hours I figured out what was going. On the question Making efficient use of \writes this is explained. Adding the package \usepackage{morewrites} to my preamble top solves the problem. – user Aug 28 '17 at 01:01
  • @user: Yes, but this morewrites issue is nothing what was in your original question ;-) Of course morewrites is the solution then –  Aug 28 '17 at 10:57
1

I finally fixed my update version of the question after finding the question Poorly formatted newlistof with memoir I added this to my preamble:

\makeatletter
\let\l@answercounter\l@figure
\makeatother

This is the full version:

\documentclass{memoir}
\usepackage{hyperref}

\usepackage[english]{babel}
\hypersetup{colorlinks=true}

% How to create my own list of things
% https://tex.stackexchange.com/questions/61086/how-to-create-my-own-list-of-things
\newcommand{\mycustomfictionlistname}{List of mycustomfiction}
\newlistof{mycustomfiction}{mcf}{\mycustomfictionlistname}

% Custom list throw LaTeX Error: Command \mycustomfiction already defined?
% https://tex.stackexchange.com/questions/388489/custom-list-throw-latex-error-command-mycustomfiction-already-defined
\newlistentry{answers}{ans}{0}

% Resetting counter
% https://tex.stackexchange.com/questions/66604/resetting-counter
\newcounter{mycustomfictioncounter}

% Continuing Page Numbering (Roman to Arabic)
% https://tex.stackexchange.com/questions/56131/continuing-page-numbering-roman-to-arabic
\renewcommand{\themycustomfictioncounter}{\arabic{mycustomfictioncounter}}

% Reset section numbering between unnumbered chapters
% https://tex.stackexchange.com/questions/71162/reset-section-numbering-between-unnumbered-chapters
\newcommand{\addtomycustomfiction}[1]
{%
    \refstepcounter{mycustomfictioncounter}
    \addcontentsline{mcf}{mycustomfictioncounter}{\protect\numberline{\themycustomfictioncounter}#1}\par
}

% Poorly formatted newlistof with memoir
% https://tex.stackexchange.com/questions/89743/poorly-formatted-newlistof-with-memoir
\makeatletter
\let\l@mycustomfictioncounter\l@figure
\makeatother

\begin{document}

    % How to remove double “Contents” heading generated by memoir?
    % https://tex.stackexchange.com/questions/47225/how-to-remove-double-contents-heading-generated-by-memoir
    \tableofcontents
    \newpage
    \mycustomfiction*

    \chapter{Two mycustomfiction}
    \addtomycustomfiction{Your first example}
    \label{1st_ex}
    Your first example

    \addtomycustomfiction{Your second example}
    \label{2nd_ex}
    Your second example

    \chapter{One example}
    \addtomycustomfiction{Your third example. (See example \ref{1st_ex} and \ref{2nd_ex})}
    Your third example. (See example \ref{1st_ex} and \ref{2nd_ex})

\end{document}

enter image description here


Related questions:

  1. Reset section numbering between unnumbered chapters
  2. Generating lists of custom environment.
  3. Resetting counter
  4. Continuing Page Numbering (Roman to Arabic)
  5. How to remove double "Contents" heading generated by memoir?
  6. How to remove the self-reference of the ToC from the ToC?

Update

Adding the table of preliminary contents to may full thesis immediately raised the issue ! No room for a new \write error. After I few more hours I figured out what was going. On the question Making efficient use of \writes this is explained. Adding the package \usepackage{morewrites} to my preamble top solves the problem.

Related question to ! No room for a new \write:

  1. Difference between morewrites and scrwfile
  2. Special package combination gives "No room for new \write."
  3. debug No room for a new \write problem
  4. TOC not generated with imakeidx and Reledpar
  5. Does morewrites not support filecontents, and can I write body of environment using TeX primatives?
  6. How to increase the TeX open file limit?
  7. Using indexing packages with memoir
  8. What are the strengths and weaknesses of KOMA-Script and memoir?
  9. List of Indexing Packages - Pros and Cons
user
  • 4,745