Hello PengCZ,

This is not exactly what you want, because it took me very long to
remember to look at SideToc.pdf. But it is close, and I have tried to
put in a lot of comments. Hopefully you can solve it from here?

Cheers, and good luck,
Sietse

% * We use \Topic to set the current topic, and to
%   record it in the topic list

% * \setuptexttexts places the topic list in the left margin
%   on every page
%   http://wiki.contextgarden.net/Command/setuptexttexts
%   (needs improving)

% * \setupbackgrounds sets the backgrond color of the left
%   margin on every page: this highlights the TOC area
%   http://wiki.contextgarden.net/Command/setupbackgrounds

% * the entry typesetting command (called \FancyTopic) typesets
%   entries inside a \framed block as wide as the margin is.
%   This allows highlighting the background of the current topic,
%   and also allows linebreaks etc.
%   http://wiki.contextgarden.net/Command/framed

\setuppapersize[A6,landscape][A6,landscape]
\setuplayout [leftmargin=5cm,
              backspace=6cm,
              width=6cm,
          ]
% Color for the margin (topic list area)
\definecolor[colMyTopics][r=1,g=0.7,b=0.7] % pink

% Color for the current topic (in the topic list)
% I like white, because it attaches the current topic to the
%   main area; but perhaps you prefer pale yellow?
% \definecolor[colCurrentTopic][r=1,g=1,b=0.7] % pale yellow
\definecolor[colCurrentTopic][r=1,g=1,b=1] % white

% When \placelist[MyTopics] is called, it calls this \FancyEntry
% function to typeset each individual entry.
% #1: entry (i.e. topic name) to typeset
% \MyMark: section (i.e. topic name) we are currently in (set by
%     \Topic).
\define[3]\FancyEntry {
    \ifnum\structurelistrealpagenumber=\realpageno\relax SAME \else
OTHER \fi PAGE
    \blank[medium]
    \doifelse \rawstructurelistfirst \MyMark
      {\framed[frame=off,
               align=normal,
               width=5cm, % same as leftmargin in \setuplayout
               background=color,
               backgroundcolor=colCurrentTopic]{%
        --- current mark's entry \par
        \color[red]{--- arg (entry): #1}\par
        \color[red]{--- mark: \MyMark}
      }}
      {\framed[frame=off, align=normal]{%
        --- other entry \par
        \color[blue]{--- arg (entry): #1}\par
        \color[blue]{--- mark: \MyMark}
      }}
    \blank[medium]
}

% Show the margin areas, headers, footers, etc.
\showframe

% Color the margin area. \setupbackgrounds must be called after
% \showframe, or \showframe will 'overwrite' \setupbackgrounds.
\setupbackgrounds[text][leftmargin][
    background=color,
    backgroundcolor=colMyTopics]
\definelist[MyTopics][criterium=all]

\def\MyMark{}

% \Topic takes one optional argument: #1, the topic name.
\def\Topic%
  {\dosingleargument\doTopic}

\def\doTopic[#1]{%
  % let it be known that we are in section #1 (used by \FancyTopic)
  \def\MyMark{#1}%
  % let topic #1 appear in the TOC (well, the MyTopics list)
  \writetolist[MyTopics]{#1}{}%
}

\setuplist[MyTopics]
          [pagenumber=no,
           alternative=command,
           command=\FancyEntry]

% On every page, place the TOC in the margin, plzkthx
\setuptexttexts[margin][\vbox{\placelist[MyTopics]}][]

\starttext

\Topic[First]
First Topic

\page

\Topic[Second]
Second Topic

\page

\Topic[Third]
Third Topic

\stoptext
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

Reply via email to