0

I want to get the following output:

enter image description here

In words:

  1. insert a table of contents for the current part (works fine)
  2. Be able to put some text before the ToC (doesn't work)

As I understand it, it is partly because the \par is the argument of a non \long macro, and also because I still type text inside the label.

So how do I get out of the label and type whatever text I want below it?

MWE

\documentclass{book}
\usepackage{titlesec,titletoc}
\titleformat{\part}[display]
  {}
  {\centering\huge\bfseries\partname~\thepart}
  {0pt}
  {\centering\huge}
  [Here is the TOC:\par%
  {\normalsize\startcontents[parts]%
  \printcontents[parts]{}{0}[2]{}}
  ]

\begin{document} \part{Introduction} \chapter{ch one} \section{sec one} \end{document}

tush
  • 1,115

1 Answers1

3

Use \endgraf.

\documentclass{book}
\usepackage{titlesec,titletoc}
\titleformat{\part}[display]
  {}
  {\centering\huge\bfseries\partname~\thepart}
  {0pt}
  {\centering\huge}
  [{\normalsize \hspace{-\leftskip}Here is the TOC:\endgraf
    \startcontents[parts]%
    \printcontents[parts]{}{0}[2]{}%
  }]

\begin{document} \part{Introduction} \chapter{ch one} \section{sec one} \end{document}

TOC


moved from comments:

In short, how could I know (and how YOU knew) that endgraf is the macro needed in this case? – tush

answers:

  • long time TeX user; \endgraf is inherited by LaTeX from the Plain TeX format, but as you discovered it is transmogrified by LaTeX into something very complicated which however is same very complicated LaTeX \par in general text.
  • I looked now in TeXBook source and for example you see it mentioned in an answer to an exercice The only tricky part about this answer is the use of\/ ^|\endgraf|, which is a substitute for |\par| because |\loop| is not a ^|\long| macro. on lines 13530-13531
  • other extract The meaning of\/ |\par| is changed so that it does more than usual: First it does ^|\endgraf|, which is \TeX's ordinary |\par| operation; then it sets... so you see this \par/\endgraf business is very familiar to people who first learned how to use TeX and only later LaTeX.
  • it was a choice of LaTeX to keep the \endgraf but this is not mandated by TeX: it is a construct of Plain TeX which is imitated by other formats.
user691586
  • 1,988
  • latex.ltx says \let\endgraf=\par but \show\endgraf gives a much longer definition. Why? – tush May 23 '23 at 11:57
  • \show\par will give you the same. This is due to the "para hooks" added by LaTeX since October 2020 release. But \par is modified by LaTeX list environments and there the sync with \endgraf is lost. – user691586 May 23 '23 at 12:10
  • when you do \let\foo\bar, then \show\foo shows you the full meaning of \bar at time of the \let. In Plain TeX,\par is a primitive so texdef endgraf will show you \endgraf:<on next line>\par as it has no meaning like a macro; with LaTeX, the TeX \par is saved as \@@par and \par becomes a macro, especially since "para hooks" have been added, but already earlier inside lists. – user691586 May 23 '23 at 12:14
  • BTW, Why adding \endgraf here: {\centering\huge\endgraf} (at the end of the begin-code) is not helpful? – tush May 23 '23 at 12:30
  • I suppose the \endgraf is then executed too early, this \centering\huge is before Introduction (edited) is typeset. To be honest ask someone who actually is willing to read titleformat source code... (I have little experience with package titlesec and none with titletoc) – user691586 May 23 '23 at 12:35