1

I'm setting a novel using memoir and markdown with simple Markdown supplied by the author. This workflow is working surprisingly well and yields professional results.

Now, as the icing on the cake, I'd like to automatically \lettrine the first word of a chapter. There are recipes to be found here on this site, but none of them fits my problem. What I'm basically looking for is a way to feed the first word of a chapter to a command. From there I can use some Lua code to decide on when and how to employ a drop cap.

Here is a stripped-down example of the environment I use:

\documentclass{memoir}

\chapterstyle{thatcher}

\usepackage{fontspec} \setmainfont{TeX Gyre Pagella}

\usepackage[english]{babel}

\usepackage[babel, strict]{csquotes} \MakeOuterQuote{"} \MakeInnerQuote{´}

\usepackage[inlineFootnotes, smartEllipses, fencedCode]{markdown} \markdownSetup{ renderers = { ellipsis = {\dots}, tilde = ~ } }

\begin{document}

\markdownInput{test.md}

\end{document}

And this is an example test.md:

# First chapter

Some italic text as often seen in introductions.

Lorem ipsum dolor sit amet, consectetur adipisici elit, sed eiusmod tempor incidunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquid ex ea commodi consequat. Quis aute iure reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint obcaecat cupiditat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Lorem ipsum dolor sit amet, consectetur adipisici elit, sed eiusmod tempor incidunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquid ex ea commodi consequat. Quis aute iure reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint obcaecat cupiditat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Second chapter

"This one starts with a quote." That's where the Lua code will decide how to set it~...

Lorem ipsum dolor sit amet, consectetur adipisici elit, sed eiusmod tempor incidunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquid ex ea commodi consequat. Quis aute iure reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint obcaecat cupiditat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Third chapter

Just normal text.

Lorem ipsum dolor sit amet, consectetur adipisici elit, sed eiusmod tempor incidunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquid ex ea commodi consequat. Quis aute iure reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint obcaecat cupiditat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

I'm not that familiar with Tex, unfortunately, and would appreciate any help. If this should not be solvable, it is also not so bad. As said, it would just be the icing on the cake.

Thanks, Flössie

  • I have never used markdown but nevertheless it seems to me that you are asking for LaTeX to recognise a "word". What is a word? Is it a group of alphabetic characters followed by a space or punctuation mark. What if the characters are preceeded by something, perhaps like " or, say #? – Peter Wilson Jan 14 '22 at 18:37
  • 1
    @PeterWilson Exactly. That's why I'd feed that word to a Lua function to solve the odd cases programmatically... – Flössie Jan 17 '22 at 18:20
  • can you provide an MWE showing the answer you propose in your comment? – Peter Wilson Jan 20 '22 at 20:04
  • 1
    @PeterWilson Like, the Lua function doing the \lettrine? As I've not come this far yet I can't provide you with an implementation, but it would basically be a first a check, if the first letter is a quotation mark which is either omitted or set as ante in lettrine, and then a table lookup of the first (if it wasn't a quotation mark) or second (if it was) letter as key and lettrine parameters as value, because each letter might have a different slope or image etc. – Flössie Jan 23 '22 at 09:47
  • @PeterWilson The word is transferred to a Lua function via \directlua which is defined in a seperate file. I've sample code for that, if that's what you're asking for? Thanks for your interest in my problem, by the way! – Flössie Jan 23 '22 at 09:53

1 Answers1

1

As this problem seems to be hardly solvable with LaTeX alone, I've written my own \markdownInput to convert the author's Markdown to LaTeX on the fly using Lua. This works quite well including the auto drop caps and auto quoting (done with csquotes before). It's sure not as powerful as the markdown package but fits my needs much better and is of course easier to customize for me.

You can find the code here.

Best, Flössie

  • You may find something similar to you problem here: https://tex.stackexchange.com/questions/290563/automatic-lettrine-to-input-file?rq=1 – Iacobus1983 Mar 01 '22 at 21:52