# What is the difference between \leftmark and \rightmark in fancyhdr?

I am having a hard time trying to figure out the difference between \leftmark and \rightmark in fancyhdr. At page 8 of the documentation, it says

The \leftmark contains the Left argument of the Last \markboth on the page, the \rightmark contains the Right argument of the fiRst \markboth or the only argument of the fiRst \markright on the page.

However, when I was trying to find the definition of \markboth, I ended up with nothing. Could anyone be kind and teach me of the difference or definition of \leftmark and \rightmark?

My though is, based on my use of fancyhdr, \leftmark writes chapter number and name if there is chapter, if not, it will write section number and name. For \rightmark, it will always write one level lower than that of \leftmark.

• Basically these control sequences contain the data that "should" end up on a left page or on a right page. The marking mechanism is intended to provide easy means to change what appears there. fancyhdr just positions the content. Most document classes provide defaults (what they think should go on left/right pages). – TeXnician Sep 7 '18 at 14:43
• Btw: \markboth: macro:#1#2->\begingroup \let \label \relax \let \index \relax \let \glossary \relax \unrestored@protected@xdef \@themark {{#1}{#2}}\@temptokena \expandafter {\@themark }\mark {\the \@temptokena }\endgroup \if@nobreak \ifvmode \nobreak \fi \fi – TeXnician Sep 7 '18 at 14:44

The primitive \mark stores one piece of data. The latex commands \markright and \markboth splits the argument of \mark to be able to store two things. So

\markboth{left 1}{right 1} does more or less \mark{{left 1}{right 1}}

\markright{right 2} retrieves the left part of the previous mark and then stores it together with the new right content. So it does (again more or less) \mark{{left 1}{right 2}}.

The stored contents can be retrieved (only in the header and footer, at other places the result is not reliable!) with \leftmark and \rightmark.

As the names indicates the commands retrieve the left and right part respectivly: \leftmark gets the left part of the last mark on the page, \rightmark the right part of the first mark on the page (or the last on the previous page).

With normal setups you get these marks

 ==== page break, new chapter:
chapter:     {{chapter}    {   }}
section1:    {{chapter}    {section1}}
section2:    {{chapter}    {section2}}
==== page break: leftmark: chapter, rightmark: empty

section3:    {{chapter}    {section3}}
section4:    {{chapter}    {section4}}
==== page break: leftmark: chapter, rightmark: section3