Highlight current chapter in list
Hi! How do I highlight the current chapter in the table of contents? The TOC is displayed on each page. For illustration I misused the interaction colour, which of course only works for the first page of a chapter. \setupheadertexts [\setups{headlist}] \startsetups [headlist] \framed[align=normal, frame=off] {\placelist [chapter] [alternative=f, criterium=all]} \stopsetups \setupinteraction [state=start, color=lightgray, contrastcolor=darkgreen] \starttext \startchapter [title=alpha] \stopchapter \startchapter [title=beta] \page\input knuth \stopchapter \startchapter [title=gamma] \stopchapter \stoptext Marco
Am 08.11.2012 um 00:29 schrieb Marco Patzer
Hi!
How do I highlight the current chapter in the table of contents? The TOC is displayed on each page. For illustration I misused the interaction colour, which of course only works for the first page of a chapter.
\setupheadertexts [\setups{headlist}]
\startsetups [headlist] \framed[align=normal, frame=off] {\placelist [chapter] [alternative=f, criterium=all]} \stopsetups
\setupinteraction [state=start, color=lightgray, contrastcolor=darkgreen]
\starttext \startchapter [title=alpha] \stopchapter \startchapter [title=beta] \page\input knuth \stopchapter \startchapter [title=gamma] \stopchapter \stoptext
You can use the marking mechanism to get the title of the current chapter. The problem for the solution below is to get a expandable version of the list entry because \currentlistentrytitle itself isn’t expandable and can’t be used in \doifelse. Instead of using \ctxcommand better ask Hans for a raw/expandable version of the tile/pagenumber commands. \setupheadertexts [\setups{headlist}] \startsetups [headlist] \framed[align=normal, frame=off] {\placelist [chapter] [alternative=highlight, criterium=all]} \stopsetups \definelistalternative [highlight] [renderingsetup=list:highlight] \startsetups [list:highlight] \par \startlinealignment[middle] \doifelse{\fetchmark[chapter][first]}{\currentlistentrytitle} %\doifelse{\fetchmark[chapter][first]}{\ctxcommand{listtitle("\currentlist",\currentlistindex)}} {\color[red] {\currentlistentrytitle}} {\color[blue]{\currentlistentrytitle}} \stoplinealignment \par \stopsetups \setupinteraction [state=start, color=lightgray, contrastcolor=darkgreen] \starttext \startchapter [title=alpha] \stopchapter \startchapter [title=beta] \page\input knuth \stopchapter \startchapter [title=gamma] \stopchapter \stoptext Wolfgang
2012-11-08 Wolfgang Schuster: Hi Wolfgang!
\startsetups [headlist] \framed[align=normal, frame=off] {\placelist [chapter] [alternative=highlight, criterium=all]} \stopsetups
\definelistalternative [highlight] [renderingsetup=list:highlight]
I like the flexibility of renderingsetups for \defineheadalternative, but frankly, I didn't know they can be used for lists as well and I was clueless about the best place to hook into.
\startsetups [list:highlight] \par \startlinealignment[middle] \doifelse{\fetchmark[chapter][first]}{\currentlistentrytitle} %\doifelse{\fetchmark[chapter][first]}{\ctxcommand{listtitle("\currentlist",\currentlistindex)}} {\color[red] {\currentlistentrytitle}} {\color[blue]{\currentlistentrytitle}} \stoplinealignment \par \stopsetups
That's a neat and clean solution. Thanks Wolfgang. Marco
On 11/8/2012 11:06 AM, Marco Patzer wrote:
2012-11-08 Wolfgang Schuster:
Hi Wolfgang!
\startsetups [headlist] \framed[align=normal, frame=off] {\placelist [chapter] [alternative=highlight, criterium=all]} \stopsetups
\definelistalternative [highlight] [renderingsetup=list:highlight]
I like the flexibility of renderingsetups for \defineheadalternative, but frankly, I didn't know they can be used for lists as well and I was clueless about the best place to hook into.
\startsetups [list:highlight] \par \startlinealignment[middle] \doifelse{\fetchmark[chapter][first]}{\currentlistentrytitle} %\doifelse{\fetchmark[chapter][first]}{\ctxcommand{listtitle("\currentlist",\currentlistindex)}} {\color[red] {\currentlistentrytitle}} {\color[blue]{\currentlistentrytitle}} \stoplinealignment \par \stopsetups
That's a neat and clean solution. Thanks Wolfgang.
Wolfgang: Say that we have: \installcorenamespace{internalreference} \def\structureheadlocation#1% {\csname\??internalreference\ifcsname\??internalreference#1\endcsname#1\else\s!default\fi\endcsname} \letvalue{\??internalreference\s!default}\!!zerocount \def\storeinternalreference#1#2% {\setxvalue{\??internalreference\currentstructurename}{#2}} and in \strc_sectioning_register add: \storeinternalreference\currentstructurename\nextinternalreference then we can say: \startsetups [list:highlight] \par \startlinealignment[middle] \doifelse\currentlistentrylocation{\structureheadlocation{chapter}} {\color[red] {\currentlistentrytitle}} {\color[blue]{\currentlistentrytitle}} \stoplinealignment \par \stopsetups which is just comparing numbers (so one can also say: \startsetups [list:highlight] \par \startlinealignment[middle] \ifnum\currentlistentrylocation=\structureheadlocation{chapter}\relax \color[red] {\currentlistentrytitle} \else \color[blue]{\currentlistentrytitle} \fi \stoplinealignment \par \stopsetups but that's for low level coders) Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
On 11/8/2012 12:06 PM, Hans Hagen wrote:
On 11/8/2012 11:06 AM, Marco Patzer wrote:
2012-11-08 Wolfgang Schuster:
Hi Wolfgang!
\startsetups [headlist] \framed[align=normal, frame=off] {\placelist [chapter] [alternative=highlight, criterium=all]} \stopsetups
\definelistalternative [highlight] [renderingsetup=list:highlight]
I like the flexibility of renderingsetups for \defineheadalternative, but frankly, I didn't know they can be used for lists as well and I was clueless about the best place to hook into.
\startsetups [list:highlight] \par \startlinealignment[middle] \doifelse{\fetchmark[chapter][first]}{\currentlistentrytitle}
%\doifelse{\fetchmark[chapter][first]}{\ctxcommand{listtitle("\currentlist",\currentlistindex)}}
{\color[red] {\currentlistentrytitle}} {\color[blue]{\currentlistentrytitle}} \stoplinealignment \par \stopsetups
That's a neat and clean solution. Thanks Wolfgang.
the next beta has: \namedstructureheadlocation{name} so that you can compare \currentlistentrylocation with \namedstructureheadlocation{chapter} (todo: also store locations elsewhere?) Best document this before we forget about it. Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
2012-11-08 Hans Hagen:
the next beta has: \namedstructureheadlocation{name}
so that you can compare
\currentlistentrylocation
with
\namedstructureheadlocation{chapter}
Thanks Hans.
Best document this before we forget about it.
I assume that's my part, right? I'll extend or add a wiki page the weekend after the beta is released. Marco
2012-11-08 Marco Patzer:
Best document this before we forget about it.
I assume that's my part, right? I'll extend or add a wiki page the weekend after the beta is released.
http://wiki.contextgarden.net/Command/definelistalternative Marco
On 11/8/2012 6:32 PM, Marco Patzer wrote:
2012-11-08 Marco Patzer:
Best document this before we forget about it.
I assume that's my part, right? I'll extend or add a wiki page the weekend after the beta is released.
fyi: more commands will support a redering setup approach Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
Hans wrote:
the next beta has: \namedstructureheadlocation{name} so that you can compare \currentlistentrylocation with \namedstructureheadlocation{chapter} (todo: also store locations elsewhere?) Best document this before we forget about it.
Is this a good description of the command's behavior? All structure heads, regardless of level, get a location number in the order in which they appear. Like so (see also MWE at bottom of this e-mail): \section{Alpha} % location number: 1; type: section; section number: 1 \section{Beta} % location number: 2; type: section; section number: 2 \subsection{Aap} % location number: 3; type: subsection; subsection number: 1 \subsection{Noot} % location number: 4; type: subsection; subsection number: 2 \section{Gamma} % location number: 5; type: section; section number: 3 \namedstructureheadlocation{X} then returns the location number of the current X, where X is the name of a structure level (e.g. 'chapter', 'section', etc.) If you ask for e.g. \namedstructureheadlocation{chapter}, and you are not in a chapter, then 0 is returned. Anything missing? @Marco: sweet job on http://wiki.contextgarden.net/Command/definelistalternative. I have taken the lazy liberty of redirecting Command/currentlistentrylocation Command/structureheadlocation Command/currentlistentrynumber etc to that page for the now, so that they at least appear in the list of commands. --Sietse \starttext \startsection [title=alpha] \stopsection \startsection [title=beta] \startsubsection[title=aap] \namedstructureheadlocation{section} \namedstructureheadlocation{subsection} \startsubsection[title=noot] \namedstructureheadlocation{section} \namedstructureheadlocation{subsection} \stopsubsection \stopsection \startsection [title=gamma] \namedstructureheadlocation{section} \stopsection \stoptext
On 11/9/2012 5:53 PM, Sietse Brouwer wrote:
Hans wrote:
the next beta has: \namedstructureheadlocation{name} so that you can compare \currentlistentrylocation with \namedstructureheadlocation{chapter} (todo: also store locations elsewhere?) Best document this before we forget about it.
Is this a good description of the command's behavior?
All structure heads, regardless of level, get a location number in the order in which they appear. Like so (see also MWE at bottom of this e-mail):
\section{Alpha} % location number: 1; type: section; section number: 1 \section{Beta} % location number: 2; type: section; section number: 2 \subsection{Aap} % location number: 3; type: subsection; subsection number: 1 \subsection{Noot} % location number: 4; type: subsection; subsection number: 2 \section{Gamma} % location number: 5; type: section; section number: 3
\namedstructureheadlocation{X} then returns the location number of the current X, where X is the name of a structure level (e.g. 'chapter', 'section', etc.)
If you ask for e.g. \namedstructureheadlocation{chapter}, and you are not in a chapter, then 0 is returned.
Anything missing?
a location number is some kind of unique internal reference, a pretty old feature btw, dating from the early days of context, when complex interactivity was added, but it comes in handy here Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
2012-11-08 Wolfgang Schuster:
\setupheadertexts [\setups{headlist}]
\startsetups [headlist] \framed[align=normal, frame=off] {\placelist [chapter] [alternative=highlight, criterium=all]} \stopsetups
\definelistalternative [highlight] [renderingsetup=list:highlight]
Why does the custom list alternative succeed in a header but fails in a layer? A predefined alternative works perfectly in a layer. \setupfootertexts [\setups{footlist}] \setupbackgrounds [page] [background=layer:chapter] \definelayer [layer:chapter] [state=repeat] \setlayer [layer:chapter] {\placelist [chapter] [alternative=f, criterium=all]} %% works %% {\placelist [chapter] [alternative=highlight, criterium=all]} %% fails \definelistalternative [highlight] [renderingsetup=list:highlight] \startsetups [list:highlight] \currentlistentrytitle \stopsetups %% works \startsetups [footlist] \placelist [chapter] [alternative=highlight, criterium=all] \stopsetups \starttext \startchapter [title=Alpha] \stopchapter \startchapter [title=Beta] \stopchapter \startchapter [title=Gamma] \stopchapter \stoptext Marco
2012-11-08 Marco Patzer: I just realized when I presses “send”:
Why does the custom list alternative succeed in a header but fails in a layer? A predefined alternative works perfectly in a layer.
\setupfootertexts [\setups{footlist}]
\setupbackgrounds [page] [background=layer:chapter]
\setupbackgrounds [page] [background=layer:chapter, setups=setups:headlayer]
\setlayer [layer:chapter] {\placelist [chapter] [alternative=f, criterium=all]} %% works %% {\placelist [chapter] [alternative=highlight, criterium=all]} %% fails
\startsetups [setups:headlayer] \setlayer [layer:chapter] {\placelist [chapter] [alternative=highlight, criterium=all]} \stopsetups Well, we have dynamic content, so wrap it in a setup. Marco
Am 08.11.2012 um 22:37 schrieb Marco Patzer
2012-11-08 Wolfgang Schuster:
\setupheadertexts [\setups{headlist}]
\startsetups [headlist] \framed[align=normal, frame=off] {\placelist [chapter] [alternative=highlight, criterium=all]} \stopsetups
\definelistalternative [highlight] [renderingsetup=list:highlight]
Why does the custom list alternative succeed in a header but fails in a layer? A predefined alternative works perfectly in a layer.
Header and footers are added and calculated after the page is finished but when you put a text in a layer it is fixed at this moment. The problem in your example with the custom list alternative is that you haven’t defined it when it is needed, when you put \definelistalternative and \startsetups … \stopsetups before \setlayer you can see it. For a dynamic layer take a look at this wiki page: http://wiki.contextgarden.net/Layers#Use_dynamic_content Wolfgang
On 11/8/2012 10:48 PM, Wolfgang Schuster wrote:
Am 08.11.2012 um 22:37 schrieb Marco Patzer
: 2012-11-08 Wolfgang Schuster:
\setupheadertexts [\setups{headlist}]
\startsetups [headlist] \framed[align=normal, frame=off] {\placelist [chapter] [alternative=highlight, criterium=all]} \stopsetups
\definelistalternative [highlight] [renderingsetup=list:highlight]
Why does the custom list alternative succeed in a header but fails in a layer? A predefined alternative works perfectly in a layer.
Header and footers are added and calculated after the page is finished but when you put a text in a layer it is fixed at this moment.
The problem in your example with the custom list alternative is that you haven’t defined it when it is needed, when you put \definelistalternative and \startsetups … \stopsetups before \setlayer you can see it.
For a dynamic layer take a look at this wiki page: http://wiki.contextgarden.net/Layers#Use_dynamic_content
here is another variant: \defineoverlay[pagenumber:preset][\texsetup{pagenumber:preset}] \startsetups pagenumber:preset PRESET \stopsetups \defineoverlay[pagenumber:action][\texsetup{pagenumber:action}] \startsetups pagenumber:action ACTION \stopsetups \setupbackgrounds [page] [background={pagenumber:preset,pagenumber:action}] \starttext \dorecurse{4}{\page[empty]} \stoptext (just to illustrate that an overlay can be used for anything) ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
On Thu, 8 Nov 2012, Hans Hagen wrote:
(just to illustrate that an overlay can be used for anything)
This prompted me to finish testing what I had been thinking about for a while. In most cases, metapost is sufficient for drawing backgrounds, but occasionally using tikz is nicer. For example, when tikz provides a solution that is not available in metapost (e.g., drawing "snake" paths), or extremely difficult to get right in metapost (drawing shadows). As Hans said, overlays can be used for anything, including tikz background. Here is a proof of concept implementation: \usemodule[tikz] \usetikzlibrary[decorations.pathmorphing] \def\TIKZdecorationoverlay {\starttikzpicture \expanded{\draw[\overlaylinecolor, line width=\overlaylinewidth, decorate, decoration={\framedparameter{decoration}}] (0,0)--(\overlaywidth,0) -- (\overlaywidth,\overlayheight) -- (0,\overlayheight) -- cycle;} \stoptikzpicture} \defineoverlay[decoration][\TIKZdecorationoverlay] \setupframed [decoration=snake] \starttext \framed[frame=off, rulethickness=3bp, background=decoration, backgroundoffset=3mm, framecolor=red, align=normal] {\input ward \endgraf} \blank[2*big] \externalfigure [cow] [frame=off, frameoffset=5pt, backgroundoffset=frame, background=decoration, decoration={coil, amplitude=4pt, segment length=5pt}] \stoptext Aditya
On 11/9/2012 1:43 AM, Aditya Mahajan wrote:
\externalfigure [cow] [frame=off, frameoffset=5pt, backgroundoffset=frame, background=decoration, decoration={coil, amplitude=4pt, segment length=5pt}]
how about a namespace: decoration:spec={coil, amplitude=4pt, segment length=5pt}] or so, i.e. avoid a clash with (potentially new) keys Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
participants (5)
-
Aditya Mahajan
-
Hans Hagen
-
Marco Patzer
-
Sietse Brouwer
-
Wolfgang Schuster