2

Background

Looking to emphasize the first letter of the index chapter title.

Code

The following code does not work as expected:

\defineframed[StyleChapterFramed][
  frame=off,
]

\define[1]\StyleChapter{%
  \StyleChapterFramed{%
    \framed[align=right, frame=off]{%
      \startoverlay {
          \getfirstcharacter{#1}%
          \firstcharacter%
        }
      \stopoverlay
    }
  }
}

  \setuphead[chapter][
    deeptextcommand=\StyleChapter,
  ]

\starttext

\startfrontmatter
  \completecontent
\stopfrontmatter

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

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

  \startsubsection[
    title={Equipment},
    reference=sec:equipment,]
    \input knuth
  \stopsubsection

  \stopsection
  \stopchapter
\stopbodymatter

\startbackmatter
  \completeindex
  %\placeindex
\stopbackmatter

\stoptext

This produces the following compile error:

structure       > sectioning > chapter @ level 2 : 0.1 -> \headtext {index}
! Use of \csname\endcsname doesn't match its definition.

system          > tex > error on line 51 in file ex.tex: Use of  ...

Problem

The problem seems to be the following line:

  \completeindex

The document compiles when replaced with:

  \chapter{Index}
  \placeindex

Update

The code also fails when using:

\setupregister[index][%
  alternative=A,%
]

Although it seems to be a different problem.

Output

I have achieved the following for chapter titles (inset to bottom-right, followed by a page break):

Chapter TItle

Yet what I cannot seem to accomplish is override the chapter style to create a different index style title such as (at the top of a page, without a page break):

Index Title

This might be related to: Include custom index chapter title in table of contents in ConTeXt

Question

How would you use a deeptextcommand and a custom register in ConTeXt?

2
  • 1
    It would be helpful to know what exactly you want to achive. You might not need the overlay or deeptextcommand to achive that. But it's hard to tell without knowing how it's supposed to look like. – Marco Sep 21 '13 at 8:07
  • 1
    The error is caused by your use of \getfirstcharacter, which is a wrapper around getfirstcharacter() in syst-aux.lua. The label of the index heading is generated dynamically, so it expands to \headtext {index}. Calling getfirstcharacter() on that extracts the backslash which leads to an instant fail. – Philipp Gesang Sep 21 '13 at 19:11
2

From the ConTeXt mailing list, a work-around was proposed:

\cldcontext{string.sub("#1",1,1)}%

This becomes:

\define[1]\StyleChapter{%
  \StyleChapterFramed{%
    \framed[align=right, frame=off]{%
      \startoverlay
        \color[blue]{%
          \StyleFontChapterCharacter%
          \cldcontext{string.sub("#1",1,1)}%
        }
        \vskip-1.9em\hskip1.2em#1
      \stopoverlay
    }
  }
}
2
  • \cldcontext{string.sub("#1", 1, 1)}. Strings indices start from 1. – Philipp Gesang Sep 21 '13 at 20:23
  • @phg: It appears both 0,1 and 1,1 work in this case. – Dave Jarvis Sep 22 '13 at 0:22

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.