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}%
\addtolength{\myshortline}{-\myindent}%
% 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}{%
% adjust vertical position (tables!)
\settoheight{\htdiff}{#1}%
\addtolength{\htdiff}{-\ht\strutbox}%
\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:
