3

Background

Each recipe in a recipe book has ingredients, and those ingredients can be common for different recipes throughout the book. For example:

Ingredient Index

Code

I've added the comma and colours as follows:

\definealternativestyle[reg:bigbold][\sansserif\bold][]

\setupregister[index][
  style=reg:bigbold,
  alternative=A,
  color=ColourPrimary,
  pagecolor=ColourPrimary,
  distance=0pt,
  symbol=n,
  pagecommand={\color[ColourBody]{,}\hskip1ex},
]

This produces a similar result:

Ingredient List

Problem

The difficulty is collecting all the section names for a given ingredient and collating them with their respective page number.

Question

How would you include the list of section titles indented under the ingredient name?

Example

Here is an example that illustrates the problem:

\definealternativestyle[reg:bigbold][\sansserif\bold][]

\setupregister[index][
  style=reg:bigbold,
  alternative=A,
  distance=0pt,
  symbol=n,
  pagecommand={\color[black]{,}\hskip1ex},
]

\starttext

\startfrontmatter
  \completecontent
\stopfrontmatter

\startbodymatter
  \startchapter[
    title={Chapter 1},
    reference=sec:chapter-1,
  ]

  \startsection[
    title={Section 1},
    reference=sec:section-1,
  ]

  \startsubsection[
    title={Ingredients},
    reference=sec:ingredients-1,]

      \index{chocolate milk}{chocolate milk}
      \index{milk}{milk}
      \index{butter}{butter}

  \stopsubsection
  \stopsection
  \stopchapter

  \startchapter[
    title={Chapter 2},
    reference=sec:chapter-2,
  ]

  \startsection[
    title={Section 1},
    reference=sec:section-1,]

      \index{milk}{milk}
      \index{egg}{egg}
      \index{ham}{ham}

  \stopsection

  \stopchapter
\stopbodymatter

\startbackmatter
  \chapter{Index}
  \placeindex[compress=yes]
\stopbackmatter

\stoptext
  • Is using the + operator sufficient? E.g. \index{dairy+milk}, \index{dairy+butter} etc. (Remove or adjust the line distance=0pt to get a hanging indent.) – Philipp Gesang Sep 21 '13 at 18:53
  • @phg: Are you suggesting \index{milk+\currentsectiontitle}{milk}? – Dave Jarvis Sep 21 '13 at 19:04
  • Yes, after the scheme: \index {<ingredient>+<sectiontitle>}. Of course you would have to add each section explicitly. – Philipp Gesang Sep 21 '13 at 19:18
  • 2
    Here’s a complete example of what I mean: gist.github.com/phi-gamma/6653790 – Philipp Gesang Sep 21 '13 at 20:19
2

I am not sure about the question, so I don't know if this answer's your question or not.

\define[2]\Index
    {\expanded{\index{#1+\currentstructuretitle}{#2}}}

\starttext

\startsection[title={Everything Buns}]

  \Index{all-purpose flour}{all-purpose flour}
  \Index{olive oil}{olive oil}

  Instructions on how to make buns.

\stopsection

\startsection[title={Butternut Squash Soup}]

  \Index{olive oil}{olive oil}
  \Index{bacon}{bacon}

  Instructions on how to make butternut squash soup.

\stopsection

\placeindex

\stoptext

which gives

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.