views:

51

answers:

1

Hi LaTeX enthusiasts and TeX programmers!

I'm currently developing a single-page document class for some kind of flyers which should be generated automatically. Unfortunately the limited amount of space doesn't make it possible to display everything on the page, so I need to skip some articles completely (I don't want only one half of a article printed on the flyer).

In pseudo code, thats the command I am looking for:

\if_sufficient_vspace_left
    {<big block/minipage with an article>}
    {<otherwise do nothing or something else>}

And the use cases are:

  • If there is enough vertical space for the following article left on the page, print the article completely. Otherwise add only the headline to an »Other Articles« list.
  • If there is enough vertical space left, add a big advertisement, otherwise add a smaller one or do nothing.

I am quite sure that there will be a way to obtain this. For example, the TeX command \leaders, which works in vertical and horizontal mode, only inserts the leader if there is enough space left. Unfortunately I don't want to repeat anything, and an else action might be great too.

Any keywords and tips to useful commands will be appreciated. You don't have to post complete solutions (but you can of course).

Many thanks,
Christoph

+1  A: 

The 'needspace' package may give you what you're looking for, although if there is not enough space it inserts a pagebreak:

http://ctan.org/pkg/needspace

You would use it something like this:

\needspace{5\BaseLineSkip}    %  assume you need 5 lines for minipage
    {<big block/minipage with an article>}

If you don't want a page break when there isn't enough space, instead want more content but with the minipage saved until next page, then you will need to investigate how LaTeX handles "floats":

http://en.wikibooks.org/wiki/LaTeX/Floats,_Figures_and_Captions

Herbert Sitz
I don't think that the `needspace` package will be any use for me, because I don't want to generate a second page under all circumstances.Anyway, the two macros `\pagetotal` and `\pagegoal` which are used by the `needspace` package are looking promising. I think I will look at them first. Thanks for the tip.
tux21b
@tux21b: Sorry, I didn't read your question closely enough. You're probably doing it already, but using Tex's conditionals or the 'ifthen' package in LaTeX (which also does if/then/else) may help with base structure of implementing what you want. OH, ALSO, best place to ask for help is probably in a forum at http://www.latex-community.org .
Herbert Sitz
Hehe, you are right. I have now solved the problem with the ifthen package and the two macros '\pagetotal` and `\pagegoal`. So, thank you for your help and the link.
tux21b
@tux21b: I'd be curious to see your code if you're willing to post it as an answer to your own question.
Herbert Sitz
I now have dropped the `\pagegoal - \pagetotal` approach, because `\pagetotal` is only incremented when the page builder is called (e.g. at a paragraph, but not inside other vboxes). Now I am just creating a vbox and split it with `\vsplit` to the desired height. Every article inside that outer vbox is in a vbox too, and so unbreakable. Anyway, I'vent find a way to modify the remaining vbox later, to only display the section heading, yet.
tux21b