TeX과 친구들

부 (part) 차례 만들기

Hoze 2020. 9. 3. 14:21

 

\documentclass[chapter]{oblivoir}
\usepackage{fapapersize}
\usefapapersize{*,*,30mm,*,30mm,*}
\hypersetup{hypertexnames=false, bookmarksdepth=chapter}
\newcounter{tocmarker} 
\let\normalchangetocdepth\changetocdepth
\renewcommand\mempreaddparttotochook{\cftinserthook{toc}{end-\thetocmarker}}
\renewcommand\mempostaddparttotochook{
  \stepcounter{tocmarker}
  \cftinserthook{toc}{start-\thetocmarker}
}
\makeatletter
\def\@endpart{
    \begingroup
    \setcounter{@memmarkcntra}{\value{tocdepth}}
    \let\changetocdepth\@gobble
    \normalchangetocdepth{-10}
    \cftinsertcode{start-\thetocmarker}{\normalchangetocdepth{0}}
    \cftinsertcode{end-\thetocmarker}{\normalchangetocdepth{-10}}
    \let\printtoctitle\@gobble
    \tableofcontents*
    \endgroup
    \setcounter{tocdepth}{\value{@memmarkcntra}}
    % \partpageend    
}
\makeatother
\title{Part 차례 만들기}
\author{yihoze}
\date{\today}
\begin{document}
\maketitle
\part{가}
\chapter{가A}
\section{가Aa}
뜨겁게 불타오르는 가슴엔 사랑이 차고
\chapter{가B}
\section{가Ba}
싱그런 이야기로 펼치는 내일이여
\part{나}
\chapter{나A}
\section{나Aa}
장밋빛 젊은 영혼이 만나는 간이역마다
\chapter{나B}
\section{나Ba}
고독한 너와 나는 오늘도 꿈을 꾼다
\part{다}
\chapter{다A}
\section{다Aa}
어디쯤 가야만 하나 끝없이 이어진 이 길
\chapter{다B}
\section{다Ba}
아직은 우리 서로 서툴고 낯설지만
\end{document}

toc 파일이 이와 같이 만들어진다.

\cftinsert{start-1}
\contentsline ...
\contentsline ...
\cftinsert{end-1}
\contentsline ...

\cftinsert{start-2}

여기에서 깊이 따져봐야 할 것이 있는데, 자세히 논하기는 귀찮고, 간단히 풀이하자면 이렇다.

\cftinsert{start-1}은 \def\ctfinsertstart-1{\setcounter{tocdepth}{1}}로 정의된다. 그런데 여기에서 문제가 있다.  part 2에서, 앞서 정의된 start-1이 무시되게 만들어야 한다. memoir 매뉴얼이 이에 대해 친절하게 설명한다.

we need to make sure that (1) all entries are disabled,
(2) at start-1 we reenable TOC entries, and (3) at end-1 disable TOC entries again.

% make changes local, remember counters a global
\begingroup
% store current value, to be restored later
\setcounter{@memmarkcntra}{\value{tocdepth}}

간단히 말해, tocdepth를 로컬 값으로 바꾸어 조작했다가 다시 원래 글로벌 값으로 되돌리는 것이다. 여기에서 \let\changetocdepth\@gobble은 꼭 필요해 보이지 않지만 \settocdepth가 사용되는 경우를 대비하기 위한 것 같다.

결론적으로 start-1은 지역적으로 정의되고 확장되기 때문에 남지 않게 되고, 따라서 Part 2에서는 그것이 알맹이 없는 매크로 이름에 불과하다.