2

Background

When typesetting drop-caps, if the opening sentence starts with a quotation mark, apostrophe, or single quotation mark, the leading character is typically rendered in a smaller font. For example:

https://i.ibb.co/7rJYBS6/initial-Matching-Quotes.gif

https://i.ibb.co/Hz8v5w4/atlantips-drop-caps-and-quotation-marks-10.png

Problem

I have a document written in plain Markdown, which is converted to XHTML, then typeset using ConTeXt's XML processing functionality. As part of this conversion, straight quotes are converted automatically to curly quotes. The user may not insert ConTeXt-specific macros into the source document. When writing text, the user may start a chapter with a quotation:

"We expected the machines to take control.

When typeset using ConTeXt, the default behaviour is to only to make the quotation mark drop caps:

drop caps with quotation mark

Note that there are many ways to open a quotation:

  • " -- straight quote
  • -- opening curly double quote
  • -- opening curly single quote (or apostrophe)
  • « -- opening double quote (French, Spanish, etc.)
  • -- opening single quote
  • -- opening Japanese quote

Code

Here's the general form of what I'm imagining:

\setupinitial[
  % Matches any character in the set.
  leadingset={"'},
  % Applies the given font to only the matched character.
  leadingfont=\QuotationMarkFont,
  % Applies the given colour to only the matched character (optional).
  leadingcolour=\QuotationMarkColour,
]

Here's a longer example:

\setupinitial[
  leadingset={"'},
  leadingfont=\QuotationMarkFont,
  leadingcolour=\QuotationMarkColour,
]

\starttext
\startchapter
  % The quotation mark is detected and applies the smaller font size.
  \placeinitial
  "We held ConTeXt in high esteem."
\stopchapter

\startchapter
  % Applies drop caps to the first letter because no quotation mark is present.
  \placeinitial
  \input knuth
\stopchapter
\stoptext

Mailing list

From the mailing list, Hans provided the following code:

\protected\def\typo_initial_handle_indeed#1#2%
   {\dontleavehmode
    \begingroup
    \cdef\currentinitial{#1}%
    \setupcurrentinitial[#2]%
    \resetfontfeature % might be needed in more places
    \ifempty{\initialparameter\c!style}%
      \definedfont[\initialparameter\c!font]%
    \else
      \useinitialstyleparameter\c!style
    \fi
    \ifempty{\initialparameter\c!color}%
      \c_attr_color       \attributeunsetvalue
      \c_attr_transparency\attributeunsetvalue
    \else
      \useinitialcolorparameter\c!color
    \fi}

\starttext
  \setupbodyfont[dejavu,9pt]
  \defineinitial[two][m=1,method=auto]

  \setupquotation[symcolor=red]

  \setinitial[two]             Knuth   :\ignorespaces\input knuth \par
  \setinitial[two] \symbol[leftquotation]Knuth\symbol[rightquotation] :\ignorespaces\input knuth \par
\stoptext

However, this produces:

https://i.ibb.co/P5hDLH5/opening-quote.png

What I'm looking to produce is:

https://i.ibb.co/6PPGxxY/opening-quote-small.png

Using \quotation instead of \symbol[leftquotation] or produces a red closing quote:

https://i.ibb.co/VY1wqZ1/closing-quote-red.png

Questions

As a follow up to my earlier question, I am wondering:

  • When using \placeinitial, how would you detect whether the first character is in a given set of characters, and, if so, override the \setupinitial to use m=2?

  • When using m=2 to capture a specific character, how would you change the font size of only the quotation mark, leaving the font size for the remaining characters the same?

  • Can such a configuration be accomplished using \setupinitial alone?

I've asked on the mailing list, no response so far.

1 Answer 1

1

We can use \futureexpandisap to look ahead in the input stream for an opening quotation mark, then a local box to typeset the quotation mark:

\setuplocalboxes[leftmargin][
    style=\bfd,
    color=darkred,
    distance=0pt,
]

\unprotect
\define\quoteinitial{%
    \futureexpandisap“\quoteinitial_true\quoteinitial_false%
}

\define\quoteinitial_true{%
    \localmargintext[leftmargin]{“}%
    \expandafter\placeinitial%
    \gobbleoneargument%
}

\let\quoteinitial_false\placeinitial
\protect

\starttext
    \quoteinitial “We held ConTeXt in high esteem.” \samplefile{bryson}

    \quoteinitial We held ConTeXt in high esteem.   \samplefile{bryson}
\stoptext

output

4
  • Hi Max. Thank you! This is a good answer, although not quite the "ConTeXt way". I've updated my question with a code snippet from Hans. What do you think of Hans' idea? Commented Jul 11 at 19:27
  • @DaveJarvis Well, \futureexpandisap and local boxes are both new LuaMetaTeX engine additions, so in some ways it's as ConTeXt-y as it gets :). But I definitely agree, token lookahead like this isn't a great way to solve it when there are builtin mechanisms. Regarding Hans's idea: it definitely seems like the better approach, and it looks just like all of the other core ConTeXt code (unsurprisingly), but I think all that this snippet does is adds/resets the style/color keys for \setupinitial. Commented Jul 11 at 20:31
  • @DaveJarvis (I've been following the mailing list thread too) But why can't you add markup for the quotations to the XML? You're already remapping the straight quotes (") to curly opening/closing quotes (/), so why can't you remap the quotes to <q>/</q> instead? <q> is valid XHTML, and if you were to map it to the ConTeXt \quotation command it seems like it would solve a lot of your problems here. Commented Jul 11 at 20:37
  • There are a few reasons. On the same page, there can be many different styles of quotes (e.g., Spanish, American English, and Japanese). Not all quotes are guaranteed to have a terminating quotation mark. For example, quotations that span paragraphs and books that end mid-sentence. Commented Jul 11 at 22:55

You must log in to answer this question.

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