4

using the \lstlistoflistings always named as Contents in table of contents.

I did look into lstlistoflistings entry in table of contents name is always 'Contents' and Change name of listings but the solutions there did not work.

Example: (my complete preamble)

\documentclass[11pt, oneside]{Thesis} 
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{pgfplots,filecontents}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{booktabs,colortbl}
\usepackage{graphicx}
\usepackage{rotating}
\usepackage{listings}
\usepackage{color}
\usepackage{comment}
\usepackage[official]{eurosym}
\usepackage{colortbl}
\usepackage{algorithm} 
\usepackage{algpseudocode}
\usepackage{indentfirst}
\usepackage{latexsym}
\usepackage{titlesec}
\usepackage[square, numbers, comma, sort&compress]{natbib}  
\hypersetup{urlcolor=blue, colorlinks=true} 
\renewcommand{\lstlistlistingname}{List of Code} 

\begin{document}

\tableofcontents
\lstlistoflistings
\lstinputlisting[language=python,firstline=1,lastline=68,caption=some caption here., label=code:getbb]{Code/getBoundingBox.py}
\end{document}

The renew command changes the header in the page but not in the table of contents. Any ideas?

EDIT x2:

Managed to get the naming correct by editing this in the Thesis.cls

 }
 \renewcommand\lstlistoflistings{
 \btypeout{List of Listings}
 \addtotoc{List of Listings}
 \begin{spacing}{1}{
\setlength{\parskip}{1pt}
\if@twocolumn
  \@restonecoltrue\onecolumn
\else
  \@restonecolfalse
\fi
\chapter*{\lstlistlistingname
  \@mkboth{
      \MakeUppercase\lstlistlistingname}{\MakeUppercase\lstlistlistingname}}
\@starttoc{lot}
\if@restonecol\twocolumn\fi
\cleardoublepage
 }\end{spacing}

Now the name appears correctly in the TOC but the Listings do no show in the Listings page, its just empty..

A MWE can be found here: https://www.dropbox.com/sh/xehv0crr7rqyptp/AAB-eNpJVLVpfQikO3IO3yCza?dl=0

Drak
  • 61
  • 2
    Welcome to TeX.SX! What does this class do? Can you reproduce it with a standard class? – TeXnician Jul 08 '17 at 11:27
  • 2
    Only a guess: Try \AtBeginDocument{\lstlistlistingname}{List of Code}} in the preamble. listings 'hijacks' \tableofcontents actually –  Jul 08 '17 at 11:46
  • 1
    @ChristianHupfer throws an error: .example.tex.swp:3: LaTeX Error: Missing \begin{document}. – Drak Jul 08 '17 at 11:56
  • 1
    The class you are using is simply not good. There are better templates. – Johannes_B Jul 08 '17 at 12:25
  • 1
    Best choice would be to use a minimal template. – Johannes_B Jul 08 '17 at 12:26
  • @Johannes_B too late for changing classes now. My thesis is due in 3 days.. – Drak Jul 08 '17 at 12:31
  • @Drak: Well, such error messages without full code to the Thesis.cls are not useful, sorry. –  Jul 08 '17 at 12:47
  • As there are various versions of that class (due to a very bad decision and missing knowledge) we need to know where exactly you got the class from (link). – Johannes_B Jul 08 '17 at 12:58
  • Is the Thesis.cls that you are using available anywhere? – Michael Palmer Jul 08 '17 at 14:13
  • Also, it appears that Christian Hupfer's suggestion was missing a \renewcommand? Should it not be \AtBeginDocument{\renewcommand{\lstlistlistingname}{List of Code}}? – Michael Palmer Jul 08 '17 at 14:22
  • @Michael Palmer: Yes –  Jul 08 '17 at 15:00
  • @MichaelPalmer it is a variant of this https://www.latextemplates.com/template/masters-doctoral-thesis – Drak Jul 09 '17 at 06:47
  • 1
    That template has been changed about two years ago. Why i know that? I am very familliar with that template, all the bad stuff that happened to users and the replacement, which still gives some sorrow to users (mostly because of not knowing what they are doing). If you are interested in the history, <- follow this link. – Johannes_B Jul 09 '17 at 07:58
  • 1
    A variant means changes. Changes we don't know. Changes that might caused (or not?) what you see right now. Please post a minimal working example that exactly reproduced your problem. I know you are on a tight schedule, this means you have to work even more concentrated right now. – Johannes_B Jul 09 '17 at 08:00
  • You should never ever edit a question to add the answer into the question! Please always separate answers from the question using "Your Answer" field and "Post Your Answer" button. However like questions, answers should be reproducible. Currently I only see once more a code snippet with very short information where it comes from but no information where in the file to find this code and what you have changed and why. You should add all those information to an answer. – Schweinebacke Jul 09 '17 at 08:20
  • @Schweinebacke thansk for the info. I added an example now and once the complete reason is known i will make "your answer" – Drak Jul 09 '17 at 08:22
  • I didn't test the example given, as i don't know what is going on. With the recent version of the template. it is simply \cleardoublepage\addchaptertocentry{List Of Listings}\lstlistoflistings – Johannes_B Jul 09 '17 at 08:22
  • You should not use external links for a MWE. Use external links only for customer classes and packages, if you cannot replace them by a class available from CTAN. The MWE itself should be added as block-code into the question. – Schweinebacke Jul 09 '17 at 09:48

3 Answers3

4

The hard-coded List of Listings ToC entry in \lstlistoflistings is of course the culprit.

This can be changed by a patch with xpatch and replacing List of Listings with the content of \lstlistlistingname (which is an awful macro name, by the way ;-))

\documentclass[11pt, oneside]{Thesis} 


\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{pgfplots,filecontents}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{booktabs,colortbl}
\usepackage{graphicx}
\usepackage{rotating}
\usepackage{listings}
\usepackage{color}
\usepackage{comment}
\usepackage[official]{eurosym}
\usepackage{colortbl}
\usepackage{algorithm} 
\usepackage{algpseudocode}
\usepackage{indentfirst}
\usepackage{latexsym}
\usepackage{titlesec}
\usepackage{xpatch}
\usepackage[square, numbers, comma, sort&compress]{natbib}  

\renewcommand{\lstlistlistingname}{List of codes}

\xpatchcmd{\lstlistoflistings}{
  \addtotoc{List of Listings}%
}{%
  \addtotoc{\lstlistlistingname}%
}{\typeout{patch success}}{\typeout{patching failed}}



\begin{document}


\tableofcontents

\clearpage
\lstlistoflistings


\lstinputlisting[language=python,caption=some caption here., label=code:getbb]{getBoundingBox.py}

\end{document}
  • 1
    Unlike my answer, this one doesn't require sed or shell mode and will work on any platform. I would suggest that it be accepted. I will leave mine up as an example of a bad hack that works, however. – Michael Palmer Jul 09 '17 at 16:42
  • 1
    @MichaelPalmer The whole class is a hack :-/ – Johannes_B Jul 09 '17 at 16:43
  • @Johannes_B you could say that about all of LaTeX, really. And I mean no disrespect to the hackers; TeX is just so maddeningly limited as a programming language. It makes simple things hard and hard things impossible. – Michael Palmer Jul 09 '17 at 16:47
  • @MichaelPalmer Not really, LaTeX is setting some limitations. Templates are the things that limitate what users want and get them a hard time. With a standard setting, everything is going to be fine. – Johannes_B Jul 09 '17 at 16:50
  • @Johannes_B - you probably know more about the ins and outs of LaTeX than I do. However, I note that TeX e.g. has no userland general purpose data structures to speak of. The invention of luatex and the common use of auxiliary Perl scripts in more complex packages speaks for itself. – Michael Palmer Jul 09 '17 at 17:06
  • 2
    @MichaelPalmer: Templates are often the result of weird thesis 'typography' restrictions by universities etc. They cause more evil than they are useful in 99.9999% of all cases. The problem is not (La)TeX, the problem is the bunch of users that screw up the standard classes and provide such templates. –  Jul 09 '17 at 17:30
  • @ChristianHupfer - what you say is certainly true in this case, and there are probably many cases of that kind -- the template in use at my school is horrible, too, and I shudder at the recollection of having to work with a publisher's book template some time ago; after a while, I just ditched it and mocked up the result using book and bunch of packages (titlesec, fancyhdr and so on). It was during that work that I formed my not so charitable opinion of LaTeX as a language, although I do admire its power as an executable program. – Michael Palmer Jul 09 '17 at 18:31
  • patching failed, sadly. – Drak Jul 12 '17 at 10:41
  • @Drak: patching failed is no precise description: I used your dropbox link and the files from there and did not change much: It worked with patching, otherwise I would not have posted a solution –  Jul 12 '17 at 11:59
  • @ChristianHupfer I am aware. Thank you for the solution. I added your solution to my tex file just as you posted above and it just didnt work. The build log reported "patching failed". Im sorry for not so much detailed answers, i am relatively new to latex. – Drak Jul 12 '17 at 13:31
3

The suggestions made in the comments by Christian and Johannes don't seem to work, so here is a gross hack to fix up things without actually understanding what is going on. To clarify, this is based on your Thesis class without the edit that renamed the TOC entry but made the list of listings itself disappear.

\documentclass[11pt, oneside]{Thesis} 

% long list of irrelevant packages omitted ...
\usepackage{listings}

\immediate\write18{sed -i '0,/{Contents}/! s/{Contents}/{List of Code}/' \jobname.toc}

\begin{document}

\tableofcontents
\clearpage
\lstlistoflistings

\lstinputlisting[language=python,caption=some caption here., label=code:getbb]{getBoundingBox.py}

\end{document}

Explanation: we use the line editor sed to modify the auxiliary file that contains the TOC entries. We replace the second occurrence of {Contents} -- as well as any others that follow, but I hope that doesn't matter -- with {List of Code}.

For this to work, you need to run TeX with the --shell-escape option.

Next time, try not to take custom class templates on good faith -- stick with the standard classes whenever possible, and customize using standard packages whenever possible. That helps to avoid strange bugs; those bugs that do surface usually have been observed in the wild before, and it is easier to get help.

  • 1
    My solution will only work with the dreadful Mastersdoctoralthesis.cls, not Thesis.cls. :-) – Johannes_B Jul 09 '17 at 15:26
  • It's a bold statement that suggestions made by others don't work. The suggestions were done at a stage where the OP misses any standard of providing help ;-) The Thesis.cls is rubbish –  Jul 09 '17 at 16:13
  • Christian, I tried both yours and Johannes' suggestions on the files that the asker posted on DropBox before posting my own answer. I meant no offence; I don't presume that my suggestions work every time, either. – Michael Palmer Jul 09 '17 at 16:21
2

Using Version 1.43 (17/5/14) of the template.

\documentclass[12pt, oneside]{Thesis} % The default font size and one-sided printing (no margin offsets)

\usepackage{etoolbox}

\begin{document}

\tableofcontents
\patchcmd{\tableofcontents}{\addtotoc{Contents}}{\addtotoc{Wombat}}{}{}
\lstlistoflistings

\end{document}

You can replace Wombat by any string you like, maybe even \lstlistlistingname. There is no redefinition of the listings in the original template.

The problem does not show with a recent version of the template. The reason is simple: The class was updated to get rid of such rubbish.

Johannes_B
  • 24,235
  • 10
  • 93
  • 248