2

Problem

Trying to get the first letter of a word for a chapter heading. The chapter style is being applied as follows:

  \setuphead[chapter][
    command=\StyleChapter,
    % Hide the header's chapter name.
    header=empty,
    % Hide the footer's page number.
    footer=empty,
  ]

To emphasize the first character of the word (e.g., "Bread"), I've written:

\define[2]\StyleChapter{%
  \framed[
    frame=off,
    width=local,
    align={flushright,low,nothyphenated,verytolerant},
    width=\dimexpr\textwidth+\rightmargindistance,
    height=\dimexpr\textheight-\footerheight,
  ]{\substring{#2}{1}{1}}{#2}
}

As well as:

  ]{\substring{#2}{1}{1}{#2}}

And:

  ]{{#2}{\substring{#2}{1}{1}}}

And:

\defineframed[StyleChapterFramed][
  frame=off,
  width=local,
  align={flushright,low,nothyphenated,verytolerant},
  width=\dimexpr\textwidth+\rightmargindistance,
  height=\dimexpr\textheight-\footerheight,
]

\define[2]\StyleChapter{%
  \StyleChapterFramed{%
    {\getfirstcharacter{#2}\firstcharacter #2}
  } 
} 

And variations thereof. It seems \substring is not a macro available in ConTeXT? The effect I'm trying to produce:

Lunch

The effect I've achieved so far:

Soup

Using the following yields the letter H, but I'm trying to use the chapter title, which is parameter #2:

{\getfirstcharacter{Hello}\firstcharacter #2}

Any ideas how to obtain a substring in ConTeXt?

2
  • BTW, you can also define a new framed with specific parameters, \defineframed[ChapterFramed][....] and then directly use \ChapterFramed{...} instead of overloading \framed[....].
    – Aditya
    Aug 20, 2013 at 4:32
  • 1
    \substring is a macro in the stringstrings package for one, though I'm not sure if that is the reference to which your source referred. Based on your syntax, it could be that reference. Aug 20, 2013 at 14:23

1 Answer 1

3

To get the first character of a string use \getfirstcharacter. For example:

\getfirstcharacter{Hello} \firstcharacter -- \remainingcharacters

Thus to duplicate the first character in the chapter, you would use:

\defineframed
  [StyleChapterFramed]
  [
    frame=off,
    width=local,
    align={flushright,low,nothyphenated,verytolerant},
    width=\dimexpr\textwidth+\rightmargindistance\relax,
    height=\dimexpr\textheight-\footerheight\relax,
  ]

\define[1]\StyleChapter
  {\getfirstcharacter{#1}\StyleChapterFramed{\firstcharacter #1}}

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

You must log in to answer this question.

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