I am kindly requesting for assistance on how to put the headings Matlab Code and Pseudocodes under List of Codes and headings Matlab Output and R Output under List of Output using the below MWE. In other words, I am desiring to have two separate list of listings namely List of Codes and List of Output. However under List of Codes,I want to have sections (unnumbered) namely Matlab Code and Pseudocode, and under List of Output,I want to have sections (unnumbered) as well namely R Output and Matlab Output. Your help is going to be greatly appreciated. The suggested solution to my problem at Multiple listings styles is not producing the desired output since it does not address the following specifications:
- List of C++, List of R and List of Pseudocode are in chapter format using
bookdocument class which is something I do not like; - List of C++, List of R and List of Pseudocode are supposed to be in an unnumbered section format under the chapter (unnumbered) by the name List of Codes;
- I also want to create a second independent listing by the chapter (unnumbered) name List of Output. Under this unnumbered chapter, I want to have unnumbered sections namely Matlab Output and R Output, and
- The suggested solution does not work well under the new caption package. Actually, I had already tried that suggested solution and failed to get the desired output before @Tom pointed out the issue of the new
captionpackage at Incorrect classification of multiple listings entries.
The output I am desiring is shown in the attached picture:

I would kindly appreciate if other users stop suggesting the solution at Multiple listings styles since it does not solve my problem as I have mentioned above. I may have not explained my case well and I would greatly appreciate if someone could improve this post so that other users may not consider it a duplicate or vote to close it. From my understanding, Tex.SE is meant to provide assistance to those with Latex problems given that they have tried something that did not work out, and not to close questions that are in need of a solution or solutions. I would also appreciate if I can get the solution to my problem.
My MWE takes into account the caption package updates:
\documentclass[openany]{book}
\usepackage{regexpatch}
\usepackage[nottoc]{tocbibind}
\usepackage{caption}
\usepackage{listings}
% --------------------------------------- C++
\newcommand{\lstlistmatlaboutputname}{List of Matlab Output}
\newcommand{\lstlistofmatlaboutput}{\begingroup
\tocfile{\lstlistmatlaboutputname}{loc}
\endgroup}
\newcommand{\lstlistroutputname}{List of R Output}
\newcommand{\lstlistofroutput}{\begingroup
\tocfile{\lstlistroutputname}{loo}
\endgroup}
% --------------------------------------- R
\newcommand{\lstlistmatlabcodename}{List of Matlab Code}
\newcommand{\lstlistofmatlabcode}{\begingroup
\tocfile{\lstlistmatlabcodename}{lor}
\endgroup}
% --------------------------------------- Pseudocode
\newcommand{\lstlistpseudocodename}{List of Pseudocode}
\newcommand{\lstlistofpseudocode}{\begingroup
\tocfile{\lstlistpseudocodename}{lop}
\endgroup}
\makeatletter
\lstnewenvironment{matlaboutput}[1][]{%
\renewcommand{\lstlistingname}{Matlab Output}%
\renewcommand{\ext@lstlisting}{loc}%
%\xpatchcmd*{\caption@ORI@lst@MakeCaption}{lol}{loc}{}{}% use this with earlier version caption package
\lstset{language=C++,#1}}%
{}
\lstnewenvironment{routput}[1][]{%
\renewcommand{\lstlistingname}{R Output}%
\renewcommand{\ext@lstlisting}{loo}%
%\xpatchcmd*{\caption@ORI@lst@MakeCaption}{lol}{loc}{}{}% use this with earlier version caption package
\lstset{language=R,#1}}%
{}
\lstnewenvironment{matlabcode}[1][]{%
\renewcommand{\lstlistingname}{Matlab Code}%
\renewcommand{\ext@lstlisting}{lor}%
%\xpatchcmd*{\caption@ORI@lst@MakeCaption}{lol}{lor}{}{}% use this with earlier version caption package
\lstset{language=R,#1}}
{}
\lstnewenvironment{pseudocode}[1][]{%
\renewcommand{\lstlistingname}{Pseudocode}%
\renewcommand{\ext@lstlisting}{lop}%
%\xpatchcmd*{\caption@ORI@lst@MakeCaption}{lol}{lop}{}{}% use this with earlier version caption package
\lstset{basicstyle=\ttfamily,#1}}%
{}
\makeatother
\begin{document}
\lstlistofmatlaboutput
\lstlistofroutput
\lstlistofmatlabcode
\lstlistofpseudocode
\chapter{Listings}
\begin{matlaboutput}[caption = {Some class definition}]
% example matlab output
\end{matlaboutput}
\begin{routput}[caption = {Some class definition}]
% example matlab output
\end{routput}
\begin{matlabcode}[caption = {For educational purposes}]
% example matlab code 1
\end{matlabcode}
\begin{matlabcode}[caption = {Sample code from Matlab}]
% example matlab code 2
\end{matlabcode}
\begin{pseudocode}[caption={Hello world}]
% example pseudocode
\end{pseudocode}
\end{document}