I use etoc package to make separate ToC for each part. I now need to put ToC at the end of each part instead of begining. Is there a way to do this?

Here is my MWE:

\documentclass[twoside]{scrbook}
\usepackage{lipsum}
\usepackage{etoc}
\newlength\tocrulewidth
\setlength{\tocrulewidth}{1.5pt}
\begin{document}
%
\part{Part 1}
\etocsettocdepth{3}
\localtableofcontents
\clearpage
\section{Section}
\lipsum[1-20]
\section{Section}
\lipsum[21-40]
%
\part{Part 2}
\etocsettocdepth{3}
\localtableofcontents
\clearpage
\section{Section}
\lipsum[1-20]
\section{Section}
\lipsum[21-40]
%
\part{Part 3}
\etocsettocdepth{3}
\localtableofcontents
\clearpage
\section{Section}
\lipsum[1-20]
\section{Section}
\lipsum[21-40]
%
\end{document}


Here is one way:

\documentclass[twoside]{scrartcl}
\usepackage{lipsum}
\usepackage{etoc}
%\newlength\tocrulewidth
%\setlength{\tocrulewidth}{1.5pt}
\begin{document}

\part{Part 1}
\invisiblelocaltableofcontents\label{parttoc:1}
%\clearpage
\section{Section}
\lipsum[1-20]
\section{Section}
\lipsum[21-40]
%
\etocsetnexttocdepth{3}
\tableofcontents\ref{parttoc:1}
\part{Part 2}
\invisiblelocaltableofcontents\label{parttoc:2}
%\clearpage
\section{Section}
\lipsum[1-20]
\section{Section}
\lipsum[21-40]
%
\etocsetnexttocdepth{3}
\tableofcontents\ref{parttoc:2}
\part{Part 3}
\invisiblelocaltableofcontents\label{parttoc:3}
%\clearpage
\section{Section}
\lipsum[1-20]
\section{Section}
\lipsum[21-40]
%
\etocsetnexttocdepth{3}
\tableofcontents\ref{parttoc:3}
\end{document}


It requires manually adding some \label/\ref but this could be abstracted into macros using the part counter.

Remarks:

1. I switched document class to scrartcl because the example has no chapters,

2. On preparing this answer I have noticed that Emacs AUCTeX wrongly says there are compilation errors. This is triggered indirectly by etoc who induces LaTeX into writing some message to the log, and here for example the message will include the string parttoc:1:<space> and this kind of string provokes the wrong report by AUCTeX.

Minimal example:

\documentclass{article}
\begin{document}
\typeout{Hello:1: }% with a space!
\end{document}


With such a document, AUCTeX claims there were LaTeX errors.

Tested with AUCTeX 11.90.2.2017-07-25 (which is actually 11.91.0 I think but there was an issue in release string)

This bites us here because the label parttoc:1 already has a colon. etoc will get un update to workaround this AUCTeX problem.

3. There is at least another way which is to use "depth tags" which are explained in documentation, but this would a tad bit more cumbersome here.

4. It goes without saying that etoc here modifies what \ref usually means. But it does not modify in anyway the \ref macro itself, it simply reacts to its presence at certain locations.

TOC for last part:

• workaround for the Emacs/AUCTeX issue at etoc 1.08l 2017-10-23. – user4686 Oct 24 '17 at 11:05