2

Following on from this question, I am now trying to achieve the same effect (drawing with metafun in the TOC, from the section number to the edge of the page) using positional overlays instead.

However, positional variables (i.e., \hpos) that I define dynamically using structurelistuservariable do not seem to work.

A minimal example:

\setuppapersize[letter][letter]


\define[1]\TOCDynamic{ 
  \hpos{X-\structurelistuservariable{short}}{X-\structurelistuservariable{short}} 
}
\define[1]\TOCStatic{ 
  \hpos{X-A}{X-A} 
}

\setuplist[chapter][number=yes, width=1em,  numbercommand=\TOCDynamic,  width=5em, alternative=c]
\setuplist[section][number=yes, width=1em,  numbercommand=\TOCStatic,  width=7em, alternative=c]


\startMPpositiongraphic{ExampleFromManual}
  initialize_box(\MPpos{\MPvar{self}}) ;
  path p ; p := llxy..lrxy..urxy..ulxy..cycle ;
  pickup pencircle scaled 1pt ;
  fill p withcolor .800white ;
  draw p withcolor .625yellow ;
  anchor_box(\MPanchor{\MPvar{self}})
\stopMPpositiongraphic


\starttext

  \placecontent[criterium=all]
  \startpositionoverlay{TOClayer}
    \setMPpositiongraphic{X-A}{ExampleFromManual}
    \setMPpositiongraphic{X-What}{ExampleFromManual}
    \setMPpositiongraphic{X-Why}{ExampleFromManual}
  \stoppositionoverlay
  \defineoverlay [TOClayer] [\positionoverlay{TOClayer}]
  \setupbackgrounds [page] [background={TOClayer}]


\startchapter[title=A Vision of The Future][short=What]
  \input tufte
  \section{What will happen?}
  \section{What will cause it?}
\stopchapter

\startchapter[title=A Causal Account][short=Why]
  \input tufte
  \section{Why did it happen?}
  \section{Why wasn't it stopped?}
\stopchapter

\stoptext

enter image description here

This produces a figure at the last-defined "X-A", but nothing at the dynamically defined X-What and X-Why locations. We can see that the structurelistuservariable command does output the expected value in the scope due to values (e.g. "X-What") showing up in the TOC, so our positional variables should be named correctly. Is there some way to print the names of all defined positional variables to check this?

More generally, I'm really struggling to find an efficient workflow for solving these kinds of problems with metafun and ConTeXt. What would an experienced ConTeXt user do when they find themselves in this sort of situation? Where would you look for relevant information?

1
  • \structurelistuservariable is not expandable (it adds tags, which are included when exporting to XML). Better to use \rawstructurelistuservariable which is expandable. You get the desired output after changing to \raw....
    – Aditya
    Commented Feb 6, 2022 at 5:12

1 Answer 1

2

To understand what is happening, first look at the .tuc file:

 ["user"]={
    ...
  ["X-A"]={
   ["h"]=561204,
   ["n"]=6,
   ["p"]=1,
   ["r"]="textarea:1",
   ["w"]=1410084,
   ["x"]=4917992,
   ["y"]=40749956,
  },
  ["X-\\structurelistuservariable {short}"]={
   ["d"]=160344,
   ["h"]=545484,
   ["n"]=4,
   ["p"]=1,
   ["r"]="textarea:1",
   ["w"]=2436600,
   ["x"]=4917992,
   ["y"]=42647046,
  },
 },
}

This shows that the \hpos tag is not getting expanded. To see why this is the case, let's look at the definition in strc-lst.mklx:

\permanent\protected\def\structurelistuservariable#name%
  {\dostarttagged\t!listdata{#name}%
   \clf_listuserdata{\currentlist}\currentlistindex{#name}%
   \dostoptagged}

It is defined as a \protected macro, so it will not be expanded. Wrapping a \expanded{\hpos{...}{...}} doesn't help either. The reason that the macro is protected is due to the \dostarttagged ... \dostoptagged. There is a definition just below this:

\permanent\def\rawstructurelistuservariable#name%
  {\clf_listuserdata{\currentlist}\currentlistindex{#name}}

which is not \protected. So, if you just replace \structurelistuservariable with \rawstructurelistuservariable, everything works! You can confirm this by looking at the .tuc file, which now has:

 ["user"]={
  ...
  ["X-A"]={
   ["h"]=561204,
   ["n"]=6,
   ["p"]=1,
   ["r"]="textarea:1",
   ["w"]=1410084,
   ["x"]=4917992,
   ["y"]=40749956,
  },
  ["X-What"]={
   ["d"]=16506,
   ["h"]=545484,
   ["n"]=1,
   ["p"]=1,
   ["r"]="textarea:1",
   ["w"]=2736066,
   ["x"]=4917992,
   ["y"]=46204089,
  },
  ["X-Why"]={
   ["d"]=160344,
   ["h"]=545484,
   ["n"]=4,
   ["p"]=1,
   ["r"]="textarea:1",
   ["w"]=2436600,
   ["x"]=4917992,
   ["y"]=42647046,
  },
 },

The output looks as below. You'll probably need to tweak the MP code to avoid overlaps etc.

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .