Horizontal Table of Contents

From Wiki
Revision as of 14:38, 8 June 2020 by Garulfo (talk | contribs)
Jump to navigation Jump to search

This is an example which displays horizontal aligned table of contents from luigi:

\startluacode
    document.yue = document.yue or {}
    document.yue.chapter = document.yue.chapter or {}
    document.yue.section = document.yue.section or {}
    document.yue.chcount =  0
    document.yue.seccount = 0
\stopluacode


\def\ListSectionCommand#1#2#3{#1 #2 #3}

\setupcolors[state=start]
\def\ListChapterCommand#1#2#3%
{\startluacode
document.yue.chcount = document.yue.chcount +1
document.yue.chapter[document.yue.chcount] = "{\\red\\switchtobodyfont[55pt]\\os #1} {\\blue\\switchtobodyfont[34pt] #2}"
\stopluacode%
}


\def\PlaceContent%
{\startluacode
tprint = function(s) tex.sprint(tex.ctxcatcodes,s) end
format = string.format
local tab
tab = ""
if document.yue.chcount > 0
 then
   for i=1,document.yue.chcount do
    tab = tab.."\|p"
   end
   tab = tab.."\|"
   tprint("\\starttabulate["..tab.."]")
   for i=1,document.yue.chcount do
     tprint("\\NC
"..document.yue.chapter[i].."\\vskip8pt"..format("\\placelist[section][criterium=chapter,number=\%i,before=,after=\\vskip2pt]",i))
   end
   tprint("\\NC\\NR")
   tprint("\\stoptabulate")
end
\stopluacode
}

\setuplist[section][alternative=none,command=\ListSectionCommand]
\setuplist[chapter][alternative=none,command=\ListChapterCommand]

\setuppapersize [A4,landscape][A4,landscape]
\starttext
\setupbackgrounds[page][backgound=color,backgroundcolor=darkyellow]
%% Do nothing except store chapters

\framed[height=6cm,frame=off,align=middle,top=\vss,bottom=]{\switchtobodyfont[ss, 55pt] \darkgreen Table of Contents}
{ \magenta
\switchtobodyfont[ss,21pt]
\placelist[chapter]%
\PlaceContent
}

\chapter{first}  \section{AA}\dorecurse{10}{\input tufte} \section{BB} \dorecurse{10}{\input knuth}
\chapter{second} \section{CC} \dorecurse{10}{\input zapf}\section{DD} \dorecurse{10}{\input bryson}
\chapter{third}  \section{EE} \dorecurse{10}{\input ward}
\stoptext


Later, Yue Wang wrote a new implementation of the horizontal table of contents as follows:

\newcount\chapcounter \chapcounter=0
\def\tocchap#1#2#3{\hskip0pt plus 0.02\textwidth minus 0pt\advance\chapcounter by 1
  \framedtext[height=\textheight,frame=off,width=.48\textwidth,offset=none]%
    {\framedtext[height=.7\textheight,frame=off,width=.48\textwidth,offset=none,top=\vss,bottom=]{{\red\BigFont\setupinterlinespace#1\par}{\tfb\setupinterlinespace #2\par}}%
     \framedtext[height=.3\textheight,width=.48\textwidth,offset=none,frame=off,top=,bottom=\vss,align=right]%
      {\placelist[section][criterium=chapter,number=\chapcounter,alternative=command, command=\tocsec]}}}
\def\tocsec#1#2#3{{\black #2~(#3)}\par}
\def\placecontent{\placelist[chapter][alternative=command,command=\tocchap]}

--58.35.85.255 06:37, 2 September 2008 (CEST)yue wang