# Drop caps and parshape in the same paragraph

I have this requirement to have dropped caps and also use a parshape. I'd have liked to use lettrine and something like picinpar or picins, but all of those seem to use \parshape internally and thus don't play nicely with each other.

An option seemed to be to redefine the \lettrine macro and modify the contents of \L@parshape before it is used, but that looks as if it is beyond my capabilities.

I then thought it should be possible to use the \hanging package and apply a parshape after doing \hangpara{2\baselineskip}{-2}, but still no luck, as that also doesn't play nicely with \parshape.

After fiddling a while, I came up with something that seemingly works, code and output see below. I used xetex to compile, the pdfLaTeX output looks slightly differently.

The main question is: I assume I comitted several crimes with this code. What are they and how should I change this?

MWE:

\documentclass[a4paper]{scrbook}
\usepackage[showframe]{geometry}
\usepackage{xparse}
\usepackage{xcolor}
\newlength{\myindent}
\newlength{\mywindow}
\newlength{\myline}
\newlength{\myshortline}
\newlength{\htdiff}
\NewDocumentCommand{\dropcap}{m m}{%
% #1: window text
% #2: dropped cap
% width to reserve for dropped cap
\setlength{\myindent}{2\baselineskip}%
% width of short part of parshape
\setlength{\myline}{.5\textwidth}%
% width of short part of parshape with dropped cap
\setlength{\myshortline}{\myline}%
% start
\leavevmode
% define parshape
\parshape 5 \myindent \myshortline \myindent \myshortline 0pt \myline 0pt \myline 0pt \textwidth
% "window" output
\smash{%
\hskip-\myindent
\hskip\textwidth
\llap{%
\setlength{\fboxsep}{0pt}%
\colorbox{green}{%
\settoheight{\htdiff}{#1}%
\raisebox{-\htdiff}{%
\vtop to 4\baselineskip{%
\hsize\myline
#1\vfill
}%
}%
}%
}%
\hskip\myindent
\hskip-\textwidth
}%
% dropped cap
\smash{%
\llap{%
\raisebox{-\baselineskip}{%
\hbox to \myindent{%
\fontsize{32pt}{30pt}%
\selectfont%
\null\hfill\textcolor{red}{#2}\hfill\null
}%
}%
}%
}%
}
\setlength{\parindent}{0pt}
\begin{document}
\dropcap{This is a test for a text that should appear in the window cut out by my fancy parshape. I made it work, but probably not without committing several crimes ...}{1}%
This is a paragraph that should start with a dropped capital. But it should also utilize \textit{parshape}, which is why the \textit{lettrine} package does not seem to be an option. And here's some more useless text. And still more text, and more, and more, and more, and more, and more, and more, and even more.

\

\

\dropcap{%
\begin{tabular*}{.4\textwidth}{r|l}
this & now after some fiddling\\
with & vertical position\\
also & works as I'd have expected.
\end{tabular*}}{2}%
This is a paragraph that should start with a dropped capital. But it should also utilize \textit{parshape}, which is why the \textit{lettrine} package does not seem to be an option. And here's some more useless text. And still more text, and more, and more, and more, and more, and more, and more, and even more.

\end{document}


Output:

• your code doesn't look too bad, but you might want to look at this possible duplicate question/answer tex.stackexchange.com/questions/119688/lettrine-and-wrapfig/… – David Carlisle Aug 28 '17 at 16:43
• @DavidCarlisle Thanks, getting a 'not too bad' from you almost feels like an accolade for me ;-) I missed that other answer, because I didn't search for wrapfig. I'll give it a go. – takrl Aug 28 '17 at 17:02
• the main complication of wrapfig's parshape handling is that it allows the parshape to be restarted if the paragraph does not have enough lines for the cutout, but if you know that's not an issue (and a 1-line paragraph would not really work with a drop cap) then the code can be a lot simpler as here – David Carlisle Aug 28 '17 at 17:12