# Non-rectangular body geometry

I'd love to typeset a document where the inner margin follows a sinuous path. For example, like the one below (done in Scribus).

I tried wrapping the text around a curvy image set at the appropriate location, but that didn't work, obviously, since images are always rectangular, right?

I checked in the documentation of package geometry if one could define a \rightmargin that would be dependent on some other variable (like line-number), but I didn't find anything.

Google and tex.stackexchange searches for any number of combinations of relevant-sounding terms yielded nothing.

I'm ready to use luatex or whatever (ideally, I'd like to use microtype too). Any help much appreciated!

EDIT: Ideally the solution wouldn't require manual tuning, apart from giving the initial shape of the "curvy" margin. Indeed, I'd like to use it for a little book of about 60 pages. The problem with \shapepar (or \cutout, or even \parshape for that matter) is that it has to be fine-tuned for each individual paragraph, knowing beforehand the length of the text and the paragraph's position on the page (also, a paragraph split over two pages seems to be pretty tough to handle).

• Have a look at the \parshape macro, which lets you use nearly arbitrarily shaped margin shapes. If you search this site for \parshape, you'll get quite a few hits. – Mico Dec 7 '13 at 21:03
• Look up the shapepar package; here is an example tex.stackexchange.com/a/139744/21891. – jub0bs Dec 7 '13 at 21:08
• Okay, thanks, I'll check these out. However, from the shapepar package documentation, it doesn't seem to be able to flow text from one page to the next, actually only applying paragraph by paragraph. – Christoph B. Dec 10 '13 at 10:31
• "Relaunched" the question with a bounty since I'm not able to achieve any general layout with the above suggestions (see "EDIT" in message"). Thanks nevertheless for the pointers! – Christoph B. Jan 26 '14 at 14:45
• You might look at flowfram but you don't seem to be able to use shaped paragraphs with the kind of frame I think you probably need. (But I do not really understand the documentation very well and I've only tried using it for a bit this evening. Hence it is worth your looking, I think.) – cfr Jan 26 '14 at 21:02

This version tries to take into account the vertical spaces taken up by sections; might even work with figures, tables, etc... (untested).

\documentclass[a4paper]{article}

\def\LINESPERPAGE{45}
\usepackage[textheight=\LINESPERPAGE\baselineskip]{geometry}

\usepackage{lipsum}
\usepackage{xinttools}% requires version 1.09m or later

% \edef\MOCKSINE {%
% {0pt \the\dimexpr\textwidth-3em}%
% {0pt \the\dimexpr\textwidth-4em}%
% {0pt \the\dimexpr\textwidth-5em}%
% {0pt \the\dimexpr\textwidth-5.75em}%
% {0pt \the\dimexpr\textwidth-6em}%
% {0pt \the\dimexpr\textwidth-5.75em}%
% {0pt \the\dimexpr\textwidth-5em}%
% {0pt \the\dimexpr\textwidth-4em}%
% {0pt \the\dimexpr\textwidth-3em}%
% {0pt \the\dimexpr\textwidth-2em}%
% {0pt \the\dimexpr\textwidth-1em}%
% {0pt \the\dimexpr\textwidth-0.25em}%
% {0pt \the\dimexpr\textwidth-0em}%
% {0pt \the\dimexpr\textwidth-0.25em}%
% {0pt \the\dimexpr\textwidth-1em}%
% {0pt \the\dimexpr\textwidth-2em}%
% }

% let's divide by two the sizes of the undulation.
\edef\MOCKSINE {%
{0pt \the\dimexpr\textwidth-1.5em}%
{0pt \the\dimexpr\textwidth-2em}%
{0pt \the\dimexpr\textwidth-2.5em}%
{0pt \the\dimexpr\textwidth-2.875em}%
{0pt \the\dimexpr\textwidth-3em}%
{0pt \the\dimexpr\textwidth-2.875em}%
{0pt \the\dimexpr\textwidth-2.5em}%
{0pt \the\dimexpr\textwidth-2em}%
{0pt \the\dimexpr\textwidth-1.5em}%
{0pt \the\dimexpr\textwidth-1em}%
{0pt \the\dimexpr\textwidth-.5em}%
{0pt \the\dimexpr\textwidth-0.125em}%
{0pt \the\dimexpr\textwidth-0em}%
{0pt \the\dimexpr\textwidth-0.125em}%
{0pt \the\dimexpr\textwidth-.5em}%
{0pt \the\dimexpr\textwidth-1em}%
}

\makeatletter

\edef\MCK@LINESPERPAGE {\the\numexpr \LINESPERPAGE\relax }

\def\MCK@LINECOUNT {0}

\def\SETUPPARSHAPE {%
\xdef\MCK@tmpB {\the\numexpr \pagetotal/\baselineskip}%
\ifnum\MCK@tmpA>\MCK@tmpB
% assume we are on a new page. !!!Something more robust should be done here!!!
\xdef\MCK@LINECOUNT
{\the\numexpr\MCK@LINECOUNT+\MCK@tmpB-\MCK@tmpA+\MCK@LINESPERPAGE}%
\else
\xdef\MCK@LINECOUNT {\the\numexpr\MCK@LINECOUNT+\MCK@tmpB-\MCK@tmpA}%
\fi
\global\let\MCK@tmpA\MCK@tmpB
\edef\STARTINDEX {\the\numexpr\MCK@LINECOUNT+16-16*((\MCK@LINECOUNT+8)/16)}%
\parshape 16 \xintListWithSep { }{\xintTrim \STARTINDEX\MOCKSINE}
\xintListWithSep { }{\xintKeep \STARTINDEX\MOCKSINE} \relax
}

\def\STARTUNDULATIONS {\def\MCK@LINECOUNT {0}\def\MCK@tmpA {0}%
\def\par {\oldpar \SETUPPARSHAPE }\SETUPPARSHAPE }
\def\STOPUNDULATIONS {\let\par\oldpar }
\makeatother

\let\oldpar\par
\AtBeginDocument {\STARTUNDULATIONS }

\begin{document}

\newcount\cnta
\cnta1
\loop

\section{This is a section}
\lipsum [\cnta-\numexpr\cnta+3\relax]
\section{This is another section}
\lipsum [\numexpr\cnta+3\relax-\numexpr\cnta+7\relax]

\ifnum\cnta < 50
\repeat
\end{document}


First two pages:

This will be broken by almost anything I guess. And \everypar is un-usable as it will also be often overwritten I am afraid.

\documentclass{article}
% \usepackage[english]{babel}
% \usepackage{blindtext}
\usepackage{lipsum}
\usepackage{xinttools}% requires version 1.09m or later

\edef\MOCKSINE {%
{0pt \the\dimexpr\textwidth-3em\relax}%
{0pt \the\dimexpr\textwidth-4em\relax}%
{0pt \the\dimexpr\textwidth-5em\relax}%
{0pt \the\dimexpr\textwidth-5.75em\relax}%
{0pt \the\dimexpr\textwidth-6em\relax}%
{0pt \the\dimexpr\textwidth-5.75em\relax}%
{0pt \the\dimexpr\textwidth-5em\relax}%
{0pt \the\dimexpr\textwidth-4em\relax}%
{0pt \the\dimexpr\textwidth-3em\relax}%
{0pt \the\dimexpr\textwidth-2em\relax}%
{0pt \the\dimexpr\textwidth-1em\relax}%
{0pt \the\dimexpr\textwidth-0.25em\relax}%
{0pt \the\dimexpr\textwidth-0em\relax}%
{0pt \the\dimexpr\textwidth-0.25em\relax}%
{0pt \the\dimexpr\textwidth-1em\relax}%
{0pt \the\dimexpr\textwidth-2em\relax}%
}

\def\LINECOUNT {0}

\def\SETUPPARSHAPE {%
\xdef\LINECOUNT  {\the\numexpr\LINECOUNT+\prevgraf}%
\edef\STARTINDEX {\the\numexpr\LINECOUNT+16-16*((\LINECOUNT+8)/16)}%
\parshape 16 \xintListWithSep { }{\xintTrim \STARTINDEX\MOCKSINE}
\xintListWithSep { }{\xintKeep \STARTINDEX\MOCKSINE} \relax
}

\let\oldpar\par
\AtBeginDocument {\def\par {\oldpar \SETUPPARSHAPE }

\begin{document}
\SETUPPARSHAPE
\lipsum [1-20]
\end{document}

% problems with \blindtext
% \blindtext [10]
% I don't know why.

• Merci! This is quite good! I'm not at all familiar with xinttools, so maybe this is a really simple question, but is it possible to adapt this behaviour to twoside layout, with the right hand side pages being just a mirror of what's here? Also, when I add sectioning commands, it doesn't take into account the space taken up by the section title: would it be complicated to adapt your solution to the "vertical" position of the line in the text, rather than its number? – Christoph B. Mar 11 '14 at 14:08
• xinttools is used here essentially because I am familiar with it and needed a no hassle way to shift the paragraph shape specification modulo 16, depending on the line count, thus xinttools is just a layer of utility macros for TeX programming having nothing to do a priori with page layout. For two side layout, page 2 should match page1 by transparency? For vertical position the TeX primitive \pagetotal could help. I will give a try when I find time. I assume you still ask for continuity from one page to the next, not assuming the page contains a whole number of undulations. – user4686 Mar 11 '14 at 16:57
• Matching by transparency would be great! Thanks for your time and efforts. – Christoph B. Mar 12 '14 at 13:07