45

in some (very rare) cases, it might be desirable to have the type area, particularly the text width, be different on even and odd pages. Let's say we're typesetting a textbook that's supposed to have small illustrations or annotations in the margin of the odd pages -- so we'd need a narrower type area on these. Like this:

different type areas even/odd Here's an attempt at a solution I came up with. It isn't as smart as I thought it was. I thought we might just combine everyshi and an \ifthispageodd test to change the typearea at every shipout. Obviously, that's not how it works:

\documentclass[paper=a5,pagesize,10pt,DIV=12,twoside=true]{scrreprt}
\usepackage{everyshi,blindtext}
\EveryShipout{%
\ifthispageodd{\areaset{6cm}{12cm}}{\areaset{9cm}{12cm}}}

\begin{document}
\Blinddocument
\end{document}

this results in:

! Bad space factor (0).
<recently read> \@savsf 

l.7 \Blinddocument

Is there a way to improve this? Or something entirely different?

14
  • 6
    At the very least, this is highly non-trivial because of the asynchronous manner in which TeX works. Page breaking happens separately from paragraph building, and feeding information from the latter into the former will require some very advanced TeX hackery indeed. I am not saying it can't be done, however … Maybe I should say so, to provoke someone into proving me wrong. Commented Feb 20, 2013 at 15:32
  • 12
    It is massively complicated to do this in TeX, you need to save the entire paragraph (for each paragraph) then you need to detect how far into the paragraph the page break happens and then re-set the paragraph with a parshape that uses wide lines for n-lines and short lines for the rest. It gets more complicated still if you allow paragraphs longer than a page as then you need a \parshape that chages the length at each break. Commented Feb 20, 2013 at 15:40
  • 2
    I've asked that kind of question many times myself, in reply to people asking if x is possible in *TeX: »why do you want that in the first place? You might as well stop wanting it and be a happier wo/man«. But then again, if DE Knuth had been given that answer in the 70s when he asked if x is possible in phototypesetting, and if he had followed that advice and kept the things he wanted within the constraints of what's possible, we'd probably still be using Linotrons. As for my angst: it isn't that bad. It's a fictitious scenario, fortunately. I'd like know if it were possible and at what cost.
    – Nils L
    Commented Feb 20, 2013 at 16:35
  • 1
    That's so true... Commented Feb 20, 2013 at 20:11
  • 10
    Frank Mittelbach in the TeX.sx chat: “I'm going to answer this one during the next days […]” Commented Apr 6, 2013 at 23:48

1 Answer 1

13
+500

This only works for simple cases, but could be extended and generalised a bit.

enter image description here

\documentclass{article}
\makeatletter

\def\a{Cat dog goat sheep pig rabbit cow kangeroo. }
\def\b{One two three four five six. }
\def\c{\a\a\b\a\b\b\a\a\a\a\b\b\a\b}
\def\d{\c\par\a\b\c\par\b\b\b\b\b\b\par}
\def\e{\par\d\d\b\b\b\b\b\d\a\a\a\a\a\a\a\d}


\def\shp#1{%
\@tempcnta\z@
\loop
\advance\@tempcnta\@ne
\edef\pshape{\pshape 0pt #1 }
\ifnum\@tempcnta<46
\repeat
\advance\@tempcntb46
}
\begin{document}

{
\@tempcntb\z@
\def\pshape{}
\shp{5in}\shp{3in}
\shp{5in}\shp{3in}
\shp{5in}\shp{3in}
\def\par{\ifhmode\\\fi\hspace*{\parindent}\ignorespaces}
\show\pshape
\parshape\@tempcntb\pshape
\e\e
\endgraf
}

\end{document}
10
  • It seems like the number of pages and lines per page are hardwired. Is this correct? Could you use something like the lastpage package to automate the number of pages and the lineno package to get the lines per page?
    – StrongBad
    Commented May 24, 2013 at 8:07
  • @DanielE.Shub lines per page is hardwired to 46 that could be set in the preamble by dividing \textheight by \baselineskip as written it only allows 6 pages before you have to have a real paragraph break and new page then start again. You could add as many \shp commands as you need but depending on the page size you can not have more than 20 or so as otherwise you will exceed the capacity of TeX's paragraph builder. Really each paragraph should be set as a new TeX primitive paragraph with a parshape depending on the position on the current page, but that can be hard to do Commented May 24, 2013 at 8:13
  • Small suggestion: If you load the lipsum package, you could change your \e\e to \lipsum[1-26]. Commented May 24, 2013 at 8:43
  • @JohnWickerson I'm having a one man crusade against the lipsum package:-) Commented May 24, 2013 at 8:44
  • Lorem ipsum.... Commented May 27, 2013 at 6:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .