[tex-eplain] Creating table of contents using htstart and hlend

Fred Gilham fmgilham at gmail.com
Sat Oct 12 19:38:13 CEST 2024



I use the following definitions. They are mangled from the "gentle introduction to tex" book. I hope this is not too confusing.

The eplain stuff for TOC seems quite flexible.

Note that \brm, \bbrm, \chapfont, \subsecfont etc. are font specifiers.

I have a macro file with the following in it:

\newcount\secnum \secnum=-1       %%%% counter for section numbers %%%% 
\newcount\subsecnum
\newcount\subsubsecnum % \subsubsection not given in this example since subsubsections don't appear in the table of contents.

%% Note that sections are really chapters.
\def\section#1{ 
            \vfill\eject %%%%% new section starts on a new page 
            \ifodd\pageno \else\ \vfill\eject \fi %start on an odd page
            \advance\secnum by 1 \subsecnum=0 \footno=0
            \ifnum \secnum = 1 \pageno=1 \fi
            \definexref{sec-#1}{\folio}{page}
            \def\sectiontitle{#1}
            \ifnum \secnum > 0 
                \leftline{\chapfont \sectionname \the\secnum} 
                \vskip 3pt
                \leftline{\secfont #1}
            \else
                \leftline{\chapfont #1}
            \fi
            \vskip\baselineskip 
            \writetocentry{chapter}{#1}
            \titlepagetrue
            \brm
            \vskip .5cm
            } 


%%
%% Subsections are really sections in a chapter.
\def\subsection#1{%
        \advance\subsecnum by 1 \global\tnno=0
        \subsubsecnum=0
        \vskip \baselineskip %% \vskip 30pt 
        \leftline{\subsecfont #1}
        \vskip 5pt
        \nobreak
        \definexref{subsec-\the\secnum-#1}{\folio}{page}
        \writenumberedtocentry{section}{#1}{\the\secnum}
        \brm}


%
%% The following formats the TOC entries. It can be tailored as desired.
\def\tocchapterentry#1#2{\vskip\baselineskip\breakline\goodbreak\noindent%
\bbrm{#1} \dotfill \brm{\xref{sec-#1}}\breakline}

\def\tocsectionentry#1#2#3{{\noindent\fem{#1}~$\ldots$~\fem{\xref{subsec-#2-#1}}%
\hskip 10pt}}



In my master document file I have the following near the beginning:

The following allows making colored hyperlinks without the (IMHO) ugly boxes around them:

\beginpackages
% |url.sty| provides the |\url| command which we will use to typeset
% a URL.  We request that |url.sty| be the version from June~27,
% 2005, or later, because earlier versions had problems interacting
% with plain \TeX.
\usepackage{url}[2005/06/27]
%%% The following allows creating colored hyperlinks without ugly
%%% boxes.
% |color.sty| provides support for colored text; all hyperlinks are
% automatically colored by Eplain when this package is loaded.  We give
% the |dvipsnames| option because we want to use named colors from the
% |dvips| graphics driver.
\usepackage[dvipsnames]{color}
% Finally, we load |graphicx.sty|, for the macros |\includegraphics|
% and |\rotatebox|.
\usepackage{graphicx}
\endpackages

%% This works for giving colored links without ugly boxes.
\enablehyperlinks[dvipdfm]
\hlopts{bwidth=0}
\hlopts[url]{colormodel=named,color=BlueViolet}

%%
%% Table of contents formatting. This reads the TOC entries produced
%% by \writetocentry and \writenumberedtocentry and \tocchapterentry
%% and \tocsectionentry. See fmg-macros.tex.
\def\sectiontitle{Contents}
\noindent{\chapfont Contents}\breakline
\def\xrefpageword{\thinspace}
\readtocfile
\def\xrefpageword{p.\thinspace}


The result looks like this. The page numbers in the entries are hyperlinks to the pages they reference.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: pg5-image.jpg
Type: image/jpeg
Size: 281278 bytes
Desc: not available
URL: <https://tug.org/pipermail/tex-eplain/attachments/20241012/2fb1f152/attachment-0001.jpg>
-------------- next part --------------




-- 
Pastor Fred Gilham                               fmgilham at gmail.com
			 Oh Wind, do not stop
		 Until my little boat has been blown
		       To the Immortal Islands
			 In the Eastern Sea.
			    -- Li Qingzhao


More information about the tex-eplain mailing list.