Open fauno opened 10 years ago
Good suggestion. I assume that \markboth is a standard LaTeX command, not something defined in fancyhdr (which people won't always be using)? Can you explain why \markboth{Bibliografía}{} and not \markboth{Bibliografía}{Bibliografía} or \markright{Bibliografía}?
+++ fauno [Sep 16 14 15:47 ]:
When using # References at the end of a document as recommended by the citations extension, the LaTeX output creates an unnumbered chapter and adds it to the table of contents like this:
\chapter*{Bibliografía}\label{bibliografuxeda} \addcontentsline{toc}{chapter}{Bibliografía}
But in combination with fancyhdr, it doesn't set the \markboth command so headings carry the value of previous chapters instead of the references title:
Instead of:
Which is fixed by adding \markboth to the output:
\chapter*{Bibliografía\markboth{Bibliografía}{}\label{bibliografuxeda} \addcontentsline{toc}{chapter}{Bibliografía}
I'm using pandoc 1.12 but I don't see anything on the LaTeX writer that hints \mark* is being added.
Reply to this email directly or view it on GitHub: https://github.com/jgm/pandoc/issues/1632
Yes, it is, I tested it without fancyhdr also. Searching for ways to put starred sections in header everyone recommends this. Sometimes the \markboth{Section}{}
can be put on a newline but this didn't work for me.
I did some tests and \markboth{Section}{Section}
would be correct for putting the references title in both even and odd pages. This can be customized later with fancyhdr.
@fauno can you submit a pull request with this fix?
mpickering notifications@github.com writes:
@fauno can you submit a pull request with this fix?
i don't know anything about haskell but i can try :)
it's basically adding this command to the string that adds the starred chapter/section, right?
fwiw, i ended up putting this on --include-in-header=header.tex
% https://tex.stackexchange.com/a/233271
\usepackage[explicit]{titlesec}
\titleformat{name=\chapter,numberless}[hang]{}{}{0cm}{%
\Huge #1\markboth{#1}{#1}%
}
which redefines unnumbered sections such as the bibliography to include \markboth
.
The reservation I have about hardcoding \markboth{Foo}{Foo}
is that some authors may be using a style where e.g. left hand pages have the chapter name and right hand pages the section number. For this reason @fauno's suggestion above seems better to me, though I'm not sure I'd want to include this in the default header because it brings in titlesec
. More comments welcome, though.
Sorry to resurrect an old issue, but I'm trying to figure out how to solve this problem of having incorrect running headers because of unnumbered chapters (or sections).
I tried to use the code from https://github.com/jgm/pandoc/issues/1632#issuecomment-186824753 but it didn't seem to have any impact.
Is there any chance this issue will be resolved in some manner, or can anybody help me figure out how to get the code above working?
Thanks in advance!
There have been a lot of changes to the LaTeX output with --citeproc
since this issue was discussed.
Note that unless you're using a book class or --top-level-division=chapter
, then your references heading will be \section*
not \chapter*
. So for the workaround above you probably want
% https://tex.stackexchange.com/a/233271
\usepackage[explicit]{titlesec}
\titleformat{name=\section,numberless}[hang]{}{}{0cm}{%
\Huge #1\markboth{#1}{#1}%
}
I notice that this happens with Quarto, so it is likely a KOMA class that's being used. KOMA and titlesec should not be used together, AFAIK. I'm trying to find the proper KOMA command for this.
I can't seem to find a good KOMA solution, so here's a Lua filter instead:
function Header (h)
if h.level <= 2 and h.classes:includes 'unnumbered' then
local secmark =
{pandoc.RawInline('latex', '\\markboth{')} ..
h.content ..
{pandoc.RawInline('latex', '}{')} ..
h.content ..
{pandoc.RawInline('latex', '}')}
return {h, pandoc.Plain(secmark)}
end
end
@tarleb we could incorporate this logic directly in the LaTeX writer; I just don't know if it's a good idea. (It removes some flexibility authors might want in determining what goes in the headers.)
I'm not sure either. I'll take a closer look at the ltmarks documentation. Maybe that will offer some insights.
I am using a book class, and oddly, although that code using "section" has an effect, "chapter" doesn't. Anyway, in this particular book, the sections are actually what I really want in the header, so this works perfectly. Thanks! If I need the chapters in another book, I'll try out the Lua filter.
Appreciate all the help, and so fast too!
I believe the best course of action would be to add \markboth{title}{title}
to \chapter*
and \markright{title}
to \section*
(modulo the top-level-headings setting). This would recreate the usual pattern of listing chapter names on the left page, and section on the right. There is no \markleft
in the LaTeX kernel, hence the need for those two commands.
I'm still nervous about that idea though, as it might be too opinionated. I have my hopes in the new hook system that's being developed for LaTeX, so there may be better options in the future.
Here's a filter that implements the change that I have in mind.
--- Removes notes and links
local function clean (inlines)
return inlines:walk {
Note = function (_) return {} end,
Link = function (link) return link.content end,
}
end
--- Creates an Inlines singleton containing the raw LaTeX.
local function l(text)
return pandoc.Inlines{pandoc.RawInline('latex', text)}
end
function Header (h)
if h.level <= 2 and h.classes:includes 'unnumbered' then
local title = clean(h.content)
local secmark = h.level == 1
and l'\\markboth{' .. title .. l'}{' .. title .. l'}'
or l'\\markright{' .. title .. l'}' -- subsection, keep left
return {h, secmark}
end
end
I'm still on the fence whether adding this would be a good idea.
I note that this is a simple workaround for this issue:
# Chapter Title {.unnumbered}
\markboth{Chapter Title}{Chapter Title}
I think we ought to update the writer, though, to add \markboth
in this case as @tarleb suggests above.
Note also that
\chapter*[My Chapter Title]{My Chapter Title}
works in memoir, but not with standard book class.
When using # References at the end of a document as recommended by the citations extension, the LaTeX output creates an unnumbered chapter and adds it to the table of contents like this:
But in combination with fancyhdr, it doesn't set the \markboth command so headings carry the value of previous chapters instead of the references title:
Instead of:
Which is fixed by adding \markboth to the output:
I'm using pandoc 1.12 but I don't see anything on the LaTeX writer that hints \mark* is being added.