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
Text Formatting ⇒ Where is \leftmark defined?
- localghost
- Site Moderator
- Posts: 9201
- Joined: Fri Feb 02, 2007 12:06 pm
Where is \leftmark defined?
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.
Thorsten
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
Board Rules
Avoidable Mistakes[/size]
¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1
Where is \leftmark defined?
OK, I found this line:
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
Code: Select all
\def\leftmark{\expandafter\@leftmark\botmark\@empty\@empty}
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
- localghost
- Site Moderator
- Posts: 9201
- Joined: Fri Feb 02, 2007 12:06 pm
Where is \leftmark defined?
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
Board Rules
Avoidable Mistakes[/size]
¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1
- Stefan Kottwitz
- Site Admin
- Posts: 10290
- Joined: Mon Mar 10, 2008 9:44 pm
-
- Posts: 15
- Joined: Sat Jul 16, 2011 1:59 am
Where is \leftmark defined?
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:
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
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).
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
Re: Where is \leftmark defined?
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
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
-
- Posts: 15
- Joined: Sat Jul 16, 2011 1:59 am
Re: Where is \leftmark defined?
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.
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.