2

I need to print my document without the mainmatter, but the table of contents must contain all titles of chapters and sections and the appendix must have the good number page without the mainmatter pages.

Have you a tip to do that ?

\documentclass[11pt,a4paper,DIV=12,oneside]{scrbook}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{scrlayer-scrpage}
\usepackage[french]{babel}
\usepackage{hyperref}
\usepackage{bookmark}

%name of toc \addto\captionsfrench{\renewcommand*\contentsname{Plan}}

\begin{document}

\frontmatter
\input{tex/titlepage}
\input{tex/introduction}

    \setcounter{tocdepth}{1} \tableofcontents

    \mainmatter
\input{tex/chapter1}
\input{tex/chapter2} %etc.

    \appendix
\input{tex/appendix1}
\input{tex/appendix2}

    \backmatter
\chapter{Bibliography}

\end{document}
  • Welcome to TeX.SX! How about compiling fully and setting the page range in the printing dialog? – TeXnician Apr 18 '18 at 15:40
  • Thanks for your answer (and your edition). It doesn't work because I need a correct number for my appendix pages. – Scryptus Apr 18 '18 at 15:42
  • 1
    Ah, that's "good number page". It will be hard to achieve this using \input as this (in contrast to \include) does not write auxiliary files that may help here. – TeXnician Apr 18 '18 at 15:44
0

I do not understand what "good number page" means. Maybe you are looking for something like

enter image description here

\documentclass[11pt,a4paper,DIV=12,oneside]{scrbook}[2017/04/13]% needs at least version 3.23
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[automark]{scrlayer-scrpage}
\usepackage[french]{babel}
\usepackage{bookmark}% loads hyperref too

\usepackage{xpatch}
\usepackage{blindtext}% only for dummy text

\setcounter{tocdepth}{1}

\newif\ifsetmtoc
%\setmtoctrue% uncomment for one run to renew the mtoc file
\newif\ifusemtoc
\usemtoctrue

\newcommand*\printmtoc{}
\xapptocmd\mainmatter
  {%
    \addtocontents{toc}{\protect\begingroup\protect\printmtoc}%
    \ifusemtoc
      \begingroup\renewcommand*{\blinddocument}{}% redefine \blinddocument to avoid the output
    \fi
  }{}{\mainmatterPatchFailed}
\xpretocmd\appendix
  {%
    \ifusemtoc\endgroup\fi
    \addtocontents{toc}{\protect\endgroup}%
  }{}{\appendixPatchFailed}

\makeatletter
\ifusemtoc
  \IfFileExists{\jobname.mtoc}
    {%
      \renewcommand*\printmtoc{%
        \RedeclareSectionCommands[
          tocpagenumberformat=\@gobble,
          toclinefill=\hfill
        ]{chapter,section}%
        \hypersetup{linktoc=none}%
        \input{\jobname.mtoc}
      }
    }{\setmtoctrue}%
\fi
\ifsetmtoc
  \DeclareNewTOC[
    owner=\jobname
  ]{mtoc}
  \AtBeginDocument{\listoftoc{mtoc}}%
  \xapptocmd\mainmatter
    {\renewcommand*\ext@toc{mtoc}}
    {}{\mainmatterPatchFailed}%
  \xapptocmd\appendix
    {\renewcommand*\ext@toc{toc}}
    {}{\appendixPatchFailed}%
  \usemtocfalse
\fi
\makeatother

\begin{document}
\frontmatter
Titelpage
\clearpage
\chapter{Introduction}
\Blindtext[3]

\tableofcontents
\mainmatter
\blinddocument
\blinddocument
\blinddocument

\appendix
\blinddocument
\blinddocument
\end{document}

If there are any changes in the mainmatter, either the file with extension mtoc have to be removed or there must be one run with \setmtoctrue to renew the contents of the mtoc file.

If you comment \usemtoctrue the content of main matter is printed as usual.

Note that I have used \blinddocument instead the \input macros in your MWE. Therefore I have redefined \blinddocument for the main matter while you have to redefine \input.

  • Excellent ! When I redefine \input, the path of my files stay. Have you a suggestion to hide them ? – Scryptus Apr 19 '18 at 19:49
  • I start to understand a little bit your code. Because it create a .mtoc file, I can comment all of my \input until we find a better solution ! – Scryptus Apr 19 '18 at 20:14
  • \renewcommand{\input}[1]{}? – esdd Apr 19 '18 at 20:24
  • Oh, so simple... I realize I should learn more... ;-) Thanks ! – Scryptus Apr 19 '18 at 20:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.