[texhax] Insert chapter and section heading into document header

David Gatwood dgatwood at mac.com
Mon Dec 17 17:03:08 CET 2012

I'm pretty sure it is doable, but it might not be straightforward.  If nothing else, you could save a reference to each chapter as you create the chapter mark, then in your heading, compare the current page number to each chapter start page in the list and then decide which chapter number(s) to show.

That said, since your change won't ever affect the number of lines, you might also be able to do something clever like overwriting the existing line when you hit a chapter mark, or moving the chapter mark drawing code into AddToShipoutPicture so that it gets processed at the end of the page (after you have changed the chapter number).

Incidentally, if you're starting chapters in the middle of a page, I'd be tempted to show both chapter numbers on the first page of the chapter unless the heading falls at the start of a page.  The code for doing so is left as an exercise for the reader, but probably involves comparing the current drawing position to the top of the page....


Sent from my iPhone

On Dec 16, 2012, at 5:00 AM, texhax-request at tug.org wrote:

>> "The \leftmark contains the Left argument of the Last \markboth on
>> the page, the \rightmark contains the Right argument of the ?Rst
>> \markboth or the only argument of the ?Rst \markright on the page."
>> This is designed to be clever in twosided printing, for example, and
>> to show on a spread the information corresponding to the beginning on
>> the left page and the end on the right page (I think). The rest of
>> that section of the documentation shows how to re-define, e.g.,
>> \sectionmark (which is called when you issue a \section command) to
>> put the information you want, and format it as you want, into
>> \markboth or \markright. I'll stop here as I've hit the limit of my
>> ignorance, but suggest you play with these and replace your 
>> \fancyhead{r}{\chaptertitlename\ \thechapter\ \thesection
>> \thesubsection}
>> with something like
>> \fancyhead{r}{\rightmark}
>> In essence, your problem stems from the fact that the output from
>> things like \thechapter depends on WHEN in your latex run that
>> command is executed and the header put together by latex. 
> I am beginning to think it either cannot be done; or at the very least,
> it is beyond my skill level. Since I used code that forces all of the
> "chapters" to run together rather than each starting on a new page, it
> appears that I cannot accomplish my task. I just spend over two hours
> trying every thing I know without success.
> What pisses me off is that I can do this in MS Word.
> ------------------------------
> Subject: Digest Footer
> _______________________________________________
> texhax mailing list
> texhax at tug.org
> http://tug.org/mailman/listinfo/texhax
> ------------------------------
> End of texhax Digest, Vol 2012, Issue 312
> *****************************************

More information about the texhax mailing list