[Tex/LaTex] Inserting external table of content into another document

table of contents

How do I insert the table of contents of a document into another LaTeX document? If this is even possible.
In the first document, the ToC is created using \tableofcontents

edited from comments:
(partial) MWE:

\documentclass[%
 paper=A4, twoside=true, openright, parskip=full, chapterprefix=true,
 11pt, headings=normal, bibliography=totoc, listof=totoc,
 titlepage=on, captions=tableabove, draft=false,
 ]{scrreprt}
\usepackage[utf8]{inputenc}     
\usepackage[english]{babel}   
\usepackage[                    
    figuresep=colon,
    sansserif=false,
    hangfigurecaption=false,
    hangsection=true,
    hangsubsection=true,
    colorize=full,
    colortheme=bluemagenta,
]{cleanthesis}

\usepackage{amsmath}
\usepackage{cleveref}
\usepackage{tabularx}
\usepackage{epstopdf}
\usepackage{placeins}
\usepackage{float}
\usepackage{amssymb}
\usepackage{color}
\restylefloat{figure}
\usepackage{tablefootnote}
\usepackage[framed,numbered,autolinebreaks,useliterate]{mcode}
\lstset{breakatwhitespace=false}
\usepackage{courier}
\usepackage{appendix}
\usepackage{booktabs}
\usepackage{eso-pic}
\usepackage{pbox}
\usepackage{ragged2e}
\usepackage{adjustbox}
\usepackage{graphicx} %allows for including images
\usepackage{biblatex}
\addbibresource{bib-refs}
\usepackage{pdfpages}
\usepackage{subcaption}
\usepackage{xcolor,colortbl}
\usepackage{multirow}

.toc file:

\boolfalse {citerequest}
\boolfalse {citetracker}
\boolfalse {pagetracker}
\boolfalse {backtracker}\relax 
\defcounter {refsection}{0}\relax
\select@language {english}
\defcounter {refsection}{0}\relax 
\contentsline {chapter}{\numberline {1}Introduction}{1}{chapter.1} 
\defcounter {refsection}{0}\relax 
\contentsline {section}{\numberline {1.1} Expansion Project}{1}{section*.11} 
\defcounter {refsection}{0}\relax 
\contentsline {section}{\numberline {1.2} Safety Management}{2}{section*.12} 
\defcounter {refsection}{0}\relax

Best Answer

It's possible to include an external .toc file, but tedious and the usability is limited, since the page numbers etc. are not consistent, most likely.

The shown .toc file was made with hyperref, which complicats the whole issue.

But here's a way:

\documentclass[%
 paper=A4, twoside=true, openright, parskip=full, chapterprefix=true,
 11pt, headings=normal, bibliography=totoc, listof=totoc,
 titlepage=on, captions=tableabove, draft=true,final=false
 ]{scrreprt}
\usepackage[utf8]{inputenc}     
\usepackage[english]{babel}   
\usepackage[                    
    figuresep=colon,
    sansserif=false,
    hangfigurecaption=false,
    hangsection=true,
    hangsubsection=true,
    colorize=full,
    colortheme=bluemagenta,
]{cleanthesis}

\usepackage{amsmath}
\usepackage{tabularx}
\usepackage{epstopdf}
\usepackage{placeins}
\usepackage{float}
\usepackage{amssymb}
\restylefloat{figure}
\usepackage{tablefootnote}
%
\usepackage{courier}
\usepackage{appendix}
\usepackage{booktabs}
\usepackage{eso-pic}
\usepackage{pbox}
\usepackage{ragged2e}
\usepackage{adjustbox}
\usepackage{graphicx} %allows for including images
\usepackage{biblatex}
\addbibresource{bib-refs}
\usepackage{pdfpages}
\usepackage{subcaption}
\usepackage{xcolor,colortbl}
\usepackage{multirow}

\usepackage{hyperref}
\usepackage{cleveref}


%\usepackage[framed,numbered,autolinebreaks,useliterate]{mcode}
%\lstset{breakatwhitespace=false}


\newcommand{\othercontentsname}{%
  Secondary Contents%
}

% now some code that resembles the `\@starttoc` command 
\makeatletter
\newcommand{\usetocfromothersource}[1]{%
  \begingroup
  \makeatletter
  \IfFileExists{#1}{%
    \chapter*{\othercontentsname}%
    \@input{#1}% 
    \@nobreakfalse
  }{}%
  \makeatother
  \endgroup
}
\makeatother


\begin{document}
\tableofcontents

\usetocfromothersource{otherdoc.toc}

\part{Some part}
\chapter{Foo}




\end{document}

And the otherdoc.toc:

\boolfalse {citerequest}%
\boolfalse {citetracker}
\boolfalse {pagetracker}
\boolfalse {backtracker}\relax 
\defcounter {refsection}{0}\relax
\select@language {english}
\defcounter {refsection}{0}\relax 
\contentsline {chapter}{\numberline {1}Introduction}{1}{chapter.1} 
\defcounter {refsection}{0}\relax 
\contentsline {section}{\numberline {1.1} Expansion Project}{1}{section*.11} 
\defcounter {refsection}{0}\relax 
\contentsline {section}{\numberline {1.2} Safety Management}{2}{section*.12} 
\defcounter {refsection}{0}\relax

Please note that mcode changes the section headings etc and seems to be incompatible with KOMA.

enter image description here

Related Question