Forum How do I...?

Different page headers on first pages?

kmmv
I'm trying to convert one more of my latex documents to XML+CSS (and subsequently putting together a Prince tips/hints sheet) and have run into a small snag that was easy in latex, but no so much with CSS.

@page chapter {
  @top-right {
    content: "test";
  }
}
@page chapter:first {
  @top-right {
    content: "";
  }
}
document > chapter {
  page: chapter;
}


Basically I'm trying to have the first page of a chapter have no header. It works wonderfully for the first chapter! However, subsequent chapters have the "test" in their header.

My document is structured like this:

<document>
  <chapter />
  <chapter />
  <chapter />
</document>


Any ideas?
mikeday
The reason for this is that every page in your document will end up being a "chapter" page, so only the first page of the first chapter will count as a first page. A way around this problem is to specify two values for the page property, like this:
chapter { page: chapter auto }

This means that it will switch back to an auto page before the next chapter, so that there will be a transition on the first page of the next chapter and you can match it with the :first page pseudo-class. We're still looking for ways to make named pages a bit more intuitive.
tarquinwj
Perhaps an alternative ... I assume the first page in each chapter will have a heading of some kind - a chapter title or whatever. Assuming you use something like this:

<chapter>
  <heading>foo</heading>
  ...
</chapter>


If so, you should be able to make named pages based on whatever page the heading turns up in have a different name (I think, though I have not tested if my understanding of named pages is correct).

heading { page: chapterstart; }
@page chapterstart {
  @top-right { 
    content: ""; 
  }
}
kmmv
Just a follow up... tarquinwj's idea works for some things but didn't quite work in this case. It may be my stylesheet, but the TITLE element ended up on its own page, which may work for some, but not in my case.

@page chapter {
    @top-left {
        content: counter(chapter) ". " string(chapter-name);
        font-family: accent-text;
    }
}
@page chapter:first {
    @top-left {
        content: "";
    }
}
document > chapter {
    page: chapter auto;
}


works happily in Prince 6r1. Surprisingly enough, it even works on 1 page long chapters, despite there not being an intervening page to reset back to "auto". Also note that despite being named "auto", it still carries the named page styles ("chapter" in the above case). You don't have to define the desired "auto" styles in the default @page rule.
somnath
Hi folks,
I'm a new bud working with CSS.

My problem is that, below page application does not work for first page when I set page break for each chapter on odd/right page.

document > chapter {
page: chapter auto;
}

Even my doc structure is the same
<document>
<chapter>
<chapter>
<chapter>
</document>


Did someone come across this problem or I'm doing something weird?

Help me.

Thanks,
SOM
mikeday
This looks like a bug, caused by an interaction between named pages and left/right page breaks. I've added this issue to the roadmap and we will try to fix it in the next maintenance release.
rologica
mikeday wrote:
This looks like a bug, caused by an interaction between named pages and left/right page breaks. I've added this issue to the roadmap and we will try to fix it in the next maintenance release.


Hi,

This is my first newbee post :)

It looks like I have the same problem with forced first pages to the right, and removing their top heading in favor of the title on this first page.
I have tried to find the bug description on the roadmap page, but couldn't find it.

Could you please confirm that it's on there for the next maintenance release? :? And do you maybe have a work-around for the time being?

Cheers,
Rogier[/i]
mikeday
We've reproduced the problem here and are hoping to fix it for the next maintenance release (it's on the roadmap as "Fix bug affecting interaction between named pages and left/right page breaks.").

At the moment the only real workaround is to use page break always rather than left/right.
somnath
HI,

I have another problem regarding a named page application. As mentioned earlier, my doc structure is
<document>
<chapter>
<chapter>
</document>

To generate different header/footer for the first page for above structure, I had used "document > chapter { page: chapter auto;}", which generated the bug caused between interaction between named pages when page-break set to right or odd.

My problem statement is:- When my doc structure is as below,
<document>
<chapter>
portrait page (@page:first)
portrait page (@page:left or @page:right)
landscape page (@page landscape)
portrait page (should have @page:left or @page:right)
</chapter>
</document>

The "portrait page" followed by the "landscape page" has the ":first" page properties applied to it.
How do I apply "@page:left" or "@page:right" properties to it?

Also, can I float this landscape page so that the text on previous and after pages are continued.

Is there any work-around or so? Please let me know.

Thanks,
Somnath
mikeday
You can combine named pages and page selectors, like this:
@page chapter { ... }
@page chapter:first { ... }
@page chapter:left { ... }
@page chapter:right { ... }

Or am I completely misunderstanding your question? :)
somnath
Hi Mike, I guess you have misunderstood my question or may be I was not clear in my first instance.
I do have named pages and page selectors as you mentioned.
@page chapter { ... }
@page chapter:first { ... }
@page chapter:left { ... }
@page chapter:right { ... }
Apart from above, I have an additional named page, @page landscape { ... }, for big tables.

I apply named page to my chapter as "chapter {page: chapter auto;}".

But problem comes when a big table flows in a chapter, to which I apply "big_table {page: landscape;}". The page "after" the big table takes properties of the named page "chapter:first" which should not be the case. Either "chapter:left" or "chapter:right" should be applied, as the page after the big table is not the first page of the chapter.

I hope I'm clear enough this time :)

Please let me know if any.


Thanks,
Somnath
mikeday
Oh I see, you are temporarily interrupting the chapter with a landscape page, and then the chapter continues. However, the page following the landscape page is picking up the :first style. That's actually a tricky issue, as it seems like it would require nested page sequences of some kind. We will need to think about this and come up with a solution. :)
mikeday
Today we have released Prince 6.0 rev 5, which fixes the bug reported by somnath regarding the interaction between named pages and left/right page breaks.
somnath
Hi Mike,

The new rev 5 works perfectly fine for the interaction between named pages and left/right page breaks. Thanks for fixing this.

Is the "nested page sequences" issue to be fixed next or its in your roadmap?


Regards,
Somnath
mikeday
I've added nested page sequences to the roadmap, but it may end up getting pushed back to Prince 7.0, as it will require some major rethinking of the named page mechanism.
jean
Hi there

@page book-toc:not(:first) {
    @top { content: "Table of Contents" }
}
@page book-toc {
    @bottom {
        content: counter(page, lower-roman)
    }
}


This results in no header at all .. still rereading the rest of this thread to see if I missed something.

By the way, why isn't :first on the http://www.princexml.com/doc/6.0/selectors/ page?
mikeday
Page selectors are different from element selectors, and don't support :not(), although perhaps they should.
jean
mikeday wrote:
... although perhaps they should.


Oh yes, they should, they should :P
williamle8300
Does this solution work for HTML docs also? Or only XML?

I am using the same CSS that kmmv wrote (with the 'auto' value). The only difference is that I'm "naming" the pages using using a .class name–not an XML element.

For example:
@page content {
    @top-left {
        content: "Encyclopedia Book One";
        font-family: accent-text;
    }
}
@page content:first {
    @top-left {
        content: "";
    }
}
document > .content {
    page: content auto;
}


My HTML is structured like this:
<body>
<div class="content" id="ch01">...</div>
<div class="content" id="ch02">...</div>
<div class="content" id="ch03">...</div>
<div class="content" id="ch04">...</div>
</body>


For some reason, kmmv's suggestion does not seem to do anything.. I actually don't get any headers.
mikeday
Sorry, things have changed since then: now the page property only takes one page name again, and there is a new prince-page-group property to indicate that this the start of a new page group.
.content {
    page: content;
    prince-page-group: start
}
williamle8300
Mikeday. You are a beautiful man! Thanks!!
_savage
Hmm... I thought this should work but it doesn't. My xhtml is structured something like that
<body>
  <chapter>..</chapter>
  <chapter>..</chapter>
  ..
</body>
and the CSS has various page styles before the actual named chapter styles
@page { .. }
@page:left { 
  ..
  @top { content: string(booktitle); }
}
@page:right {
  ..
  @top { content: string(chaptertitle); }
}
@page:blank {
  @top { content: none; }
}
@page chapter:first {
  @top { content: none; }
}
chapter {
  page: chapter auto;
}
However, the first page of a chapter still has the @top header showing? What am I doing wrong here, am I missing something?
mikeday
The page property no longer takes two values, you need to do this:
chapter {
    page: chapter;
    prince-page-group: start
}

The prince-page-group is our workaround mechanism for indicating that this element begins a new chapter page group, and that the :first page class will apply. The old mechanism was too fragile and difficult to explain.
_savage
That worked, thanks! :)