Text FormattingWhere is \leftmark defined?

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
gkl
Posts: 28
Joined: Sat Jan 17, 2009 12:21 am

Where is \leftmark defined?

Post by gkl »

Dear All,

I am trying to change the definition of \leftmark so that if you are on a page that has text from Chapter 1 and the start of Chapter 2 it will print Chapter 1 and Chapter 2 rather than just Chapter 2.

I looked at article.cls and fancyhdr.sty but found only uses of it, no definitions.

Could somebody shed some light on that?

Regards,
George

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
User avatar
localghost
Site Moderator
Posts: 9201
Joined: Fri Feb 02, 2007 12:06 pm

Where is \leftmark defined?

Post by localghost »

You have to look at the LaTeX2e kernel (file »latex.ltx«). You can find out on the command line where it is located in your TeX installation tree.

Code: Select all

kpsewhich latex.ltx

Thorsten
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes[/size]

¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1
gkl
Posts: 28
Joined: Sat Jan 17, 2009 12:21 am

Where is \leftmark defined?

Post by gkl »

OK, I found this line:

Code: Select all

\def\leftmark{\expandafter\@leftmark\botmark\@empty\@empty}
which I think is what assigns a value to the variable leftmark.

Does anyone know where is the code that actually works out what the value of \@leftmark is?

Finally, could you please suggest any books containing information about macro programming in LaTeX (that would presumably explain the \expandafter and all the other concepts).

Regards,
George
User avatar
localghost
Site Moderator
Posts: 9201
Joined: Fri Feb 02, 2007 12:06 pm

Where is \leftmark defined?

Post by localghost »

gkl wrote:[…] Finally, could you please suggest any books containing information about macro programming in LaTeX (that would presumably explain the \expandafter and all the other concepts). […]
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes[/size]

¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1
User avatar
Stefan Kottwitz
Site Admin
Posts: 10290
Joined: Mon Mar 10, 2008 9:44 pm

Where is \leftmark defined?

Post by Stefan Kottwitz »

LaTeX.org admin
EmilioLazo
Posts: 15
Joined: Sat Jul 16, 2011 1:59 am

Where is \leftmark defined?

Post by EmilioLazo »

This article [1] about \expandafter is really interesting.

Maybe you know that, but I'll explain some tips about what I understand about these marks:
  • When you issue a \chapter, the macro \chaptermark is invoked with the name of the chapter as its argument; the same applies to \section with \sectionmark.
  • The definition of \chaptermark and \sectionmark depends on the page style and on the 'oneside' or 'twoside' option to make TeX handle these marks "correctly".
  • \chaptermark issues \markboth to set the "right" mark (not exactly "right" but the mark corresponding to chapter information) and blanks the "left" (section) mark to prevent last section of previous chapter still being displayed after a new chapter is issued.
  • \markboth sets \leftmark and \rightmark; and \markright sets \rightmark. These \{left,right}mark variables are the text rendered at headers, so if you renew \leftmark are you redefining the current page headers not the command that produces it. What you need to redefine may be \markboth and \markright. (You may test wherever in the document text putting \rightmark to see what happens).
But why are you needing this? \chapter generally makes a new page, so I can't figure out how you can have two chapters in the same page without redefining also \chapter command or without using some other class. Instead you can have two sections on the same page.

My recommendation is that you may start with fancyhdr and try to redefine \markboth to not clear the previous \rightmark if \markboth is invoked twice at the same page.

Regards

[1] http://www.tug.org/TUGboat/tb09-1/tb20bechtolsheim.pdf
[2] http://www.ntg.nl/maps/16/29.pdf
gkl
Posts: 28
Joined: Sat Jan 17, 2009 12:21 am

Re: Where is \leftmark defined?

Post by gkl »

Dear All,

Many thanks for the prompt replies. Emilio you are right, I am looking for the case where you have two sections running in the same page. My idea was to look into the leftmark variable, see if it is empty and if not append the value of the section's name. I haven't tried it yet, hopefully over the weekend.

I will look at your suggestion as well and report back.

Regards,
George
EmilioLazo
Posts: 15
Joined: Sat Jul 16, 2011 1:59 am

Re: Where is \leftmark defined?

Post by EmilioLazo »

Hello!

As far as I can remember, \leftmark can't be void/blank unless a new chapter is defined and no sections are defined yet.

Always \leftmark has a value when a section is defined; but when a new chapter is defined, \leftmark has no text and \rightmark takes the chapter name (this behaviour changes with 'twoside'), i.e. when \section occurs at page 3 of your document, this page will display the section name as its header because \leftmark is defined, and this variable stays defined until a new section is invoked, so page 4, 5 and 6 will have the same section header because no new section is issued and \leftmark remains with its value.

I guess you need to redefine \markboth to baptize some new counter or variable to hold the page number (this will hold the page number of the last \section), and you may compare it with the page number when next \markboth is called, that is to say when new section is issued...

Regards.
Post Reply