4

Background

Looking to reproduce the following text layout (ignore the slight curve to the text, it's a magazine scan of a Robert Frost's Fire and Ice, first published in 1920):

Fire and Ice, Robert Frost

The first letter is ornate and the first word is all caps.

Problem

Using \definefirstline with an alternative style that sets the first word to capital letters is proving elusive. I suspect the implementation is incomplete because changing the style to use different colours or fonts works.

Code

Here's the styling code so far (main.tex):

\setupindenting[yes, 0.75em]

\setupinitial[
  state=start,
  n=2,
  distance=\zeropoint,
]

\definealternativestyle[PoemFirstWord][\WORD][]

\definefirstline[PoemFirstLine][
  alternative=word,
  style=PoemFirstWord,
  n=1,
]

\definestartstop[poem][
  before={\startlines \setfirstline[PoemFirstLine] \placeinitial},
  after={\stoplines},
]

\setuplines[indenting=odd]

\starttext
  \input poem.tex
\stoptext

Here's the poem.tex file:

\startpoem

Some say the world will end in fire,
Some say in ice.
From what I've tasted of desire
I hold with those who favor fire.
But if it had to perish twice,
I think I know enough of hate
To say that for destruction ice
Is also great,
And would suffice.

\stoppoem

Output

Running the code produces:

ConTeXt Output

The word "Some" is not in all caps, even though PoemFirstWord is an alternative style that should work with the style option of definefirstline.

Questions

  • How would you create an alternative style that works with \placeinitial and \startlines within a custom start/stop macro?
  • Bonus. How would you indent the second line to avoid overlapping the initial, ornate S? (Is there something like definesecondline?)
  • Bonus. How would you prevent indenting the third line?

Constraints

  • The file poem.tex cannot be modified (it is autogenerated).
  • Cannot use the lettrine module because it requires changing poem.tex.

Related

Version

$ context --version
mtx-context     | current version: 2019.12.06 19:45

1 Answer 1

2

From the mailing list, the following lines register uppercase as a font feature, which allows styling the text presented by the \definefirstline macro:

\startluacode
  fonts.handlers.otf.addfeature {
    name    = "uppercasing",
    type    = "substitution",
    prepend = true,
    data    = characters.uccodes
  }
\stopluacode

\unexpanded\def\uppercasing{\feature[+]{uppercasing}}

Save the above as uppercase.tex that can be imported and used as follows:

\input uppercase

\setupinitial[n=2, distance=-2pt]

\definealternativestyle[poem:UppercaseFirst][{\tfa\bf\uppercasing}][]

\definefirstline[poem:FirstLine][%
  alternative=word,
  style=poem:UppercaseFirst,
  n=1,
]

\definestartstop[poem][
  before={\startlines \setfirstline[poem:FirstLine] \placeinitial},
  after={\stoplines},
]

\newcount\LineCount
\define\AdvanceLineCount{\global\advance\LineCount 1\relax}

\setuplines[
  before={\global\LineCount 0\relax},
  indenting=odd,
  command={%
    \AdvanceLineCount
    \ifnum\LineCount=2 \setupindenting[yes, 4em]\fi
    \ifnum\LineCount=3 \setupindenting[no]\fi
    \ifnum\LineCount=5 \setupindenting[yes, 0.75em]\fi
  },
]

\starttext
  \input poem
\stoptext

Including the bonus questions, this produces:

Fire and Ice in ConTeXt

For more details see:

This site is temporarily in read-only mode and not accepting new answers.

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