Tell me more ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I would like to produce a document where I can display the first and last items of each two page spread in the headers of both the left and right pages. I know I can use \markboth{}{} to collect the usual form of marks that feed \leftmark and \rightmark. But that is limited to the text of one page at a time.

There doesn't appear to be a natural way to use the forward reference mechanism to do this, but there must be a trick, right?

share|improve this question

2 Answers

The fancyhdr manual (Section 10 — Dictionary style headers, p.11) introduces exactly such a page style.

share|improve this answer
That is close to what I want, but for a single page at a time not a two-page spread. I've started there, but I want to know the first and last entries of the right-hand page to include some part of them in the header or footer of the left-hand page, and vice-versa. – RBerteig Feb 4 '11 at 11:21
In case any one is interested in the page style described by Thorsten, the fancyhdr manual suggests the use of fix2col.sty with marks in two-column tables, but the package is a little hard to find. CTan currently has distributions for two installations at ctan.org/pkg/fix2col . I found more general information, including the actual package manual, at ftp.math.purdue.edu/mirrors/ctan.org/macros/latex ./contrib/fix2col/ . – brannerchinese Apr 25 '11 at 21:20
up vote 2 down vote accepted

An approach that seems to be working for me is to switch to LuaTeX, specifically the LuaLaTeX package, both from the current MiKTeX distribution for Windows.

This has allowed me to write a Lua module that I load with \directlua{require"dictfun"} in my document's preamble. When the dictfun module loads, it tries to initialize a table of the headers for every page from a file named after the \jobname, found in the global tex.jobname. I used \makeevenhead and \makeoddhead to hook into the page header and call a Lua function from dictfun to update the index of header info and construct the text that belongs on this page's header. The text of the header is placed from the Lua side with a call to tex.print().

Finally, after the main body is finished, I make one more call into the Lua module to write out the current content of the index table.

This solution requires that the text be processed by lualatex at least twice with the pagination stable, but that isn't an unreasonable requirement.

I'm sure it could be done in pure TeX, but building data structures is something that native Lua does very well.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.