I made a template that
- splits text into first letter and the rest
- creates a path to an image on disk based on the first letter
I'm having issues with the next step:
- I'm trying to use
\lettrine
to display the text with an image as the initial letter (drop cap style).
Here's what I have so far:
\documentclass[12pt]{article}
\usepackage[paperwidth=5in, paperheight=3in, margin=0.2in]{geometry}
\usepackage{graphicx, lettrine, xcolor, background, dirtytalk}
% split text into the first letter and the rest
\newcommand{\splittext}[1]{%
\def\firstletter{\expandafter\splitfirst#1\empty}%
\def\resttext{\expandafter\splitrest#1\empty}%
}
\def\splitfirst#1#2\empty{#1}
\def\splitrest#1#2\empty{#2}
\begin{document}
\pagecolor{white}
\vspace*{\fill}
\splittext{text and even more text}
\firstletter
\par
\resttext
% dynamically construct the image path from \firstletter
\edef\imagepath{/path/to/alphabet/\MakeUppercase{\firstletter}.png}
\imagepath
\end{document}
the above works displaying:
t
ext and even more text
/path/to/alphabet/T.png
if I add (right before \end{document})
\expandafter\lettrine\expandafter[image=true, lines=3, findent=3pt, nindent=0pt]{\imagepath}{}\resttext
I get this error:
Missing \endcsname inse rted. let l.30 ...s=3, findent=3pt, nindent=0pt]{\imagepath}{} \resttext 1269 words of node memory still in use: 9 hlist, 2 rule, 4 disc, 3 local_par, 2 dir, 22 glue, 5 kern, 4 penalty, 73 glyph, 15 attribute, 49 glue_spec, 15 attribute_list, 1 temp, 2 if_stack, 1 wri te, 4 pdf_colorstack nodes avail lists: 2:9,3:2,5:1,7:1 /path/to/latextemplates/.initial.tex.swp:30: ==> Fatal error occurr ed, no output PDF file produced! Transcript written on .initial.tex.log.
While if I pass the actual path, everything works
\lettrine[image=true, lines=3, findent=3pt, nindent=0pt]{/path/to/alphabet/T.png}{}\resttext
How should I pass a dynamically constructed path? Is there a better package than lettrine for this?
Please explain your solution.
here's T.png
\expandafter\lettrine\expandafter[i
expandsi
which isn't expandable so the\expandafter
are doing nothing (it's not clear what effect you intended them to have?)