1

Background

Looking to reproduce custom registers that resembles:

Custom Index

Index entries are added using:

   \setregisterentry[index][entries={Kenji Fujimoto}][
     title={Maguro},
     author={Kenji Fujimoto},
     authorurl={http://bit.ly/1fNWF0Y},
   ]{Maguro}

This produces a reasonably close representation:

Current Code

Problem

The main problem is that, due to being a register, there is an extra line between alphabetically distinct entries.

Code

The code to reproduce the issue:

\setupinteraction[state=start,]

\define[2]\href{\begingroup\goto{\color[blue]{#1}}[url(#2)]\endgroup}

\define[1]\TextCommand{%
  * \Word{\currentregisterpageuserdata{title}}, }
\define[1]\PageCommand{%
  #1. {\href{\currentregisterpageuserdata{author}}{\currentregisterpageuserdata{authorurl}}}.}

\starttext
  \startsection[title={Ikura}] 
   \setregisterentry[index][entries={Jiro Ono}][
     title={Ikura},
     author={Jiro Ono},
     authorurl={http://www.sushi-jiro.jp},
   ]{Ikura}
  \stopsection
  \startsection[title={Maguro}]
   \setregisterentry[index][entries={Kenji Fujimoto}][
     title={Maguro},
     author={Kenji Fujimoto},
     authorurl={http://bit.ly/1fNWF0Y},
   ]{Maguro}
  \stopsection
  \page
  \placeregister[index][
    n=1,
    indicator=no,
    textcommand=\TextCommand,
    pagecommand=\PageCommand,
    pagestyle=normal,
    distance=\zeropoint,
  ]
\stoptext

Questions

I am wondering (in order of importance):

  1. How do you remove the vertical space between alphabetically distinct register items?
  2. What is a more ConTeXt-like approach to register customization?
  3. How would you reference the register's page number in the \TextCommand?
  4. How can both periods have hyperlinking removed (or suppressed)?

Idea

I tried using \items to apply an itemized list to the index, but could not remove the vertical space from the itemized list.

Related Links

2
  • 1
    Regarding items, you could use \startitemize[packed] or nowhite to remove vertical space from itemized lists.
    – Aditya
    Commented Mar 9, 2014 at 4:58
  • @Aditya: I had to modify \startregisterentries (see answer). Is there a more concise way to achieve this layout? Commented Mar 15, 2014 at 19:39

1 Answer 1

1

There are a number of issues that could not be resolved using a regular index. The solution below performs a number of tasks:

  • Overrides \startregisterentries to add conditional setting for \endgraf. The \endgraf was causing the section titles to be separated from the photographer names.
  • Uses Lua to compare the author name with the index entry title. A substring match is required because comparing the strings for equality failed due to an extra {.
  • Applies a custom \pagereference that can be passed into the Lua code. This was necessary to shift the page number to the requisite location in the final output.

One possible solution that addresses all the questions:

\setupinteraction[
  state=start,
  color=red,
  contrastcolor=red,
]

\setuphead[section][aftersection=\page,]

% Sections have a register defined for citing the photographer. In ConText,
% the registers are set up with a hanging indent for items defined with
% a + (e.g., Section+Author}. To prevent the Section title from being
% split, the \endgraf must be eliminated.

\define\RegularIndexStyle{\endgraf}
\define\PhotographIndexStyle{\empty}

\unprotect
  \unexpanded\def\startregisterentries#1{
% Put the first-level items on the same line as the second-level items.
\IndexStyle
  \begingroup
  \scratchcounter\ifnum#1>\c_strc_registers_maxlevel\c_strc_registers_maxlevel\else#1\fi\relax
  \dostarttagged\t!registerentries\empty
  \let\savedcurrentregister\currentregister
  \edef\currentregister{\currentregister:\number\scratchcounter}%
  \useregisterstyleandcolor\c!textstyle\c!textcolor
  \ifnum\scratchcounter>\plusone
    \advance\leftskip\d_strc_registers_distance\relax
  \fi
  \hangindent\registerparameter\c!distance\relax
  \hangafter\plusone
  \let\currentregister\savedcurrentregister}
\protect

\startluacode
  userdata = userdata or {}

  function userdata.photographer(s, author, url)
    i = string.find( s, author )

    if i == nil then
      context( "* \\bold{" .. s .. "}, \\currentregisterpageuserdata{pagenumber}." )
    else
      context( "\\href{" .. author .. "}{" .. url .. "}." )
    end
  end
\stopluacode

\define[2]\href{\begingroup\goto{\color[blue]{#1}}[url(#2)]\endgroup}
\define[1]\TextCommand{%
\ctxlua{userdata.photographer([==[#1]==], [==[\currentregisterpageuserdata{author}]==], [==[\currentregisterpageuserdata{authorurl}]==])}}
\define[1]\PageCommand{}

% #1 - Author; #2 - Author URL; #3 - Section title
\define[3]\PhotographCitation{%
  \pagereference[#1#3]%
  \setregisterentry[PhotographerIndex][entries={#3+#1}][
    title={#3},
    author={#1},
    authorurl={#2},
    pagenumber={\at[#1#3]},
  ]{}
}

\defineregister[PhotographerIndex][
  n=1,
  indicator=no,
  distance=\zeropoint,
  before=\empty,
  compress=no,
  textcommand=\TextCommand,
  pagecommand=\PageCommand,
]

\starttext
  \startsection[title={Maguro}]
    Text
    \PhotographCitation{Kenji Fujimoto}{http://bit.ly/1fNWF0Y}{Maguro}
    \index{maguro}{maguro}
  \stopsection
  \startsection[title={Unagi}]
    Text
    \PhotographCitation{Kenji Fujimoto}{http://google.com}{Unagi}
    \index{unagi}{unagi}
  \stopsection
  \startsection[title={Tamago}]
    Text
    \PhotographCitation{Chen Kenichi}{http://www.sisen.jp/}{Tamago}
    \index{tamago}{tamago}
  \stopsection
  \define\IndexStyle\PhotographIndexStyle
  \placePhotographerIndex
  \page
  \define\IndexStyle\RegularIndexStyle
  \completeindex
\stoptext

Produces:

Registers Output

You must log in to answer this question.

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