TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This is a follow-up question to Javier's answer on a solution for working topmarks here: How to add “cont.” section title to the top of pages?

@Javier: could you please elaborate on your idea of how you implemented topmarks in titleps? I used titleps and it does work except for two things:

  • I need the literal contents of \topshortmark\indexthumb for use in \int_from_alph:n { \topshortmark\indexthumb }, for instance, but instead I get the switching mechanism with \@namedef. If I use etex's \newmarks directly, then I get the true contents but the \topmark is wrong.

  • Also, when using the \xspace macro in the mark contents, \ifsamemark breaks with an "Undefined control sequence" error.

So I want to implement the titleps \topmarks without the switching mechanism.


Following a hint from Javier, I tried the following setup, however, that didn't quite work yet:


\NewDocumentCommand \indexsection {m} {

    \hskip 0pt plus 1fil { #1 } \hskip 0pt plus 1fil


    \fancytab{#1}{\int_from_alph:n {#1}}


    \typeout{INT:~ \topextramarks{indexmark} \int_from_alph:n { \indexthumb } }
share|improve this question
The basic mechanism is that explained in the TeXbook. (1) Use the "normal" extramarks, and then write \topextramarks \int_from_alph:n { \indexthumb } (untested). (2) It seems a bug - I'll have a look at it. – Javier Bezos Mar 13 '12 at 14:38
Well, no, that wasn't my question because this is LaTeX, not TeX. The output routine is what messes up the topmarks and that is why I wanted to know how you found your way around that, making topmarks possible anyway. Sadly, I also wasn't able to get (1) to work, could you please show me the exact command? I tried \topextramarks{indexmark} \int_from_alph:n {\indexthumb} but that is interpreted as two separate commands and gives me the current \indexthumb, not the topmark one. – MiB Mar 14 '12 at 19:11
up vote 1 down vote accepted

Ok, so I did the research myself. The answer to my question is SO simple that I am wondering if I didn't pose it well enough. It suddenly struck me like lightning: if \firstmark works in LaTeX and \topmark doesn't, then one just has to keep a list of all marks, enter it at \firstmark and then move back one item. Or, which is equivalent, keep the predecessor of each mark in the mark itself and use that when accessing the mark with \topmark.

I have now read ttlps.def and that is exactly what it is doing. I wasn't able to fix the two problems in titleps that I mentioned above, so I just rewrote and minimized it the way I need it:

%%%                           extra marks                                 %%%


\cs_generate_variant:Nn \tl_if_eq:nnTF { xxTF }


    \tl_if_eq:xxTF { #1#2 } { \firstshortmark#2 }
        { \expandafter\use_i:nn }
        { \expandafter\use_ii:nn }

% ttl@mkc@\a = the (macro)name for the e-tex counter for markset \a
% ttl@mks@\a = contents of a markset \a
% ttl@premks@\a = contents of the previous item of markset \a

% arg: macro, containing the current section etc.
    \extramark{\string#1}       % initialize empty mark

% arg: macro or name to identify the markset
% \newmarkset
%    defines the ttl@mkc@#1 counter with \newmarks
%    defines \ttl@mks@#1 (to be empty)
%    defines ttl@premks@#1 to be \ttl@mks@#1
    % define a counter for a new markset called ttl@mkc@#1
    \expandafter\newmarks\csname ttl@mkc@#1\endcsname

    % \def \ttl@mks@#1 {}


% #1: markset name (macro as string: \string\macro)
% #2: \macro
    % def \ttl@a to be the macro name (without the \)

    % call \ttl@newmk@ii {\ttl@a} {#1}

% #1: markset name (macro as string without \)
% #2: macro as string
    \expandafter\let\csname ttl@mks@#2\endcsname\ttl@a

% #1: markset name
        % the usual \mark
        \marks\csname ttl@mkc@#1\endcsname{
        \expandafter\xdef\csname ttl@premks@#1\endcsname {\@nameuse{ttl@mks@#1}}

        \marks\csname ttl@mkc@#1\endcsname{%
        {\csname ttl@mks@#1\endcsname}%
        {\csname ttl@premks@#1\endcsname}}%



% #1: the markset name (or macro)
    \expandafter\use_ii:nn\firstmarks\csname ttl@mkc@#1\endcsname

    \expandafter\use_i:nn\firstmarks\csname ttl@mkc@#1\endcsname

I wanted to do it completely in LaTeX3 (I love the syntax! So much easier!) but just didn't have time yet. The code can now be used like this:


which will add a (continued) to the header if a list of subitems or of page numbers is broken onto a new page. I would have loved to add another mainitem to the index but really, that output routine is beyond me...

And regarding the literal contents, I can now write:

    \tl_if_empty:xTF { \topshortmark\indexthumb }
        \fancytab{ \topshortmark\indexthumb }{ \int_from_alph:n { \topshortmark\indexthumb } }
share|improve this answer

Your Answer


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.