Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refsection=chapter does not work with KOMA-Script 3.26a #857

Open
komascript opened this Issue Jan 18, 2019 · 12 comments

Comments

3 participants
@komascript
Copy link

komascript commented Jan 18, 2019

I've got a bug report about an issue using refsection=chapter with KOMA-Script 3.26a. With this example:

\listfiles
\documentclass{scrbook}
\usepackage[backend=biber, refsection=chapter]{biblatex}
\begin{filecontents}{\jobname.bib}
  @misc{B1,
    title = {Bib1}
  }
  @misc{B2,
    title = {Bib2}
  }
\end{filecontents}
\addbibresource{\jobname.bib}

\begin{document}
\chapter{Ch1}
\nocite{B1}
\printbibliography
\chapter{Ch2}
\nocite{B2}
\printbibliography
\end{document}

Both chapters show the complete bibliography not only the cites of the chapter. A look into the aux-file (and comparing it with the same file using book instead of scrbook) shows, that refsection is not increased and the \newlabel commands are missing. I do not know enough about the biblatex code to find out the reason. I only found comments about code changes for KOMA-Script 3.26.

Please have a look into it. If I can help to fix the issue, e.g. adding another hook, please tell me.

@moewew moewew added the bug label Jan 18, 2019

@moewew

This comment has been minimized.

Copy link
Collaborator

moewew commented Jan 18, 2019

Thank you for reporting this.

This is probably related to #713 and https://komascript.de/node/2168. I (wrongly, as it now turns out) assumed that I could also use the new \At@startsection to patch \chapter as well. The earlier code (\pretocmd\@makechapterhead and \pretocmd\@makeschapterhead) seems to do the right thing, so we could go back to that. But if there is an official hook to patch into chapter headings I would of course prefer to use that.

@komascript

This comment has been minimized.

Copy link
Author

komascript commented Jan 18, 2019

I see.

\chapter (and \part) do not use \scr@startsection. So (for me) it is clear, that the hook of \At@startsection is not executed. Before I add corresponding commands \At@startchapter and \At@startpart and hooks for chapter and part style commands, I have to have a look into the code, whether or not there are already hooks, because there are a lot of hooks in the headings mechanism, because several wrapper class and package authors asked for hooks. I really cannot keep all of them in mind. :(

But currently I need some time.

@moewew moewew added this to To Do in biblatex 3.13 Jan 18, 2019

@e-kwsm

This comment has been minimized.

Copy link

e-kwsm commented Jan 18, 2019

Just in case, the version of biblatex is 2018/11/02 v3.12 (sorry for cross post).

@moewew

This comment has been minimized.

Copy link
Collaborator

moewew commented Jan 19, 2019

@komascript While \pretocmd\@makechapterhead and \pretocmd\@makeschapterhead seem to work in the MWE, a superficial look at the code in scrbook.cls suggests to me that it might be a slightly better idea to use \scr@makechapterhead and \scr@makeschapterhead instead. That should make things work with chapter preambles better. I didn't find any obvious code that modifies \scr@makechapterhead and \scr@makeschapterhead which would imply that it is not completely bonkers to patch into those commands.

Of course an official ruling as to what should be done here would be very much appreciated.

@e-kwsm A temporary work-around could be to restore the old behaviour of patching \@makechapterhead and \@makeschapterhead

\listfiles
\documentclass{scrbook}
\usepackage[backend=biber, refsection=chapter]{biblatex}
\addbibresource{biblatex-examples.bib}

\makeatletter
\def\blx@refpatch@chapter#1{%
  \ifundef\chapter
    {\blx@err@nodocdiv{chapter}}
    {\pretocmd\@makechapterhead{#1}
       {}
       {\blx@err@patch{\string\@makechapterhead}}
     \pretocmd\@makeschapterhead{#1}
       {}
       {\blx@err@patch{\string\@makeschapterhead}}}}
\makeatother

\begin{document}
\chapter{Ch1}
\nocite{sigfridsson}
\printbibliography
\chapter{Ch2}
\nocite{worman}
\printbibliography
\end{document}
@moewew

This comment has been minimized.

Copy link
Collaborator

moewew commented Feb 2, 2019

@komascript Can I bother you about this again?

I had another look at the code again, but did not manage to find a hook for our purposes. Patching \@makechapterhead and \@makeschapterhead still works, but I don't know if it is considered safe or OK from the KOMA side. At the moment and purely from gut instinct I would prefer patching \scr@makechapterhead, but I would like to hear your opinion on that matter before I do anything.

@komascript

This comment has been minimized.

Copy link
Author

komascript commented Feb 2, 2019

@komascript Can I bother you about this again?

I have not forgotten this. But currently it was hard to find time to work on it. There were (and still are) problems with new versions of other packages too and I had to made a new bugfix release of KOMA-Script itself.

Patching \@makechapterhead and \@makeschapterhead still works

Indeed, but this would not patch other headings made with headings style chapter, e.g., if someone uses \RedeclareSectionCommand[style=chapter]{section} to make \section starts a new page.

So patching \scr@makechapterhead and \scr@makeschapterhead or \scr@@makechapterhead and \scr@@makeschapterhead would be better if they exist (and if you need a patch before the initial \clear(double)page even \scr@startchapter). But as KOMA-Script author I cannot recommend it, because I cannot promise that patching internal macros would be functional forever.

So best would be to have a hook and to use a patch only if the hook does not exist.

AFAIR the problem is, that you have to add labels automatically?

Can you tell me, where in the execution of \chapter (and \part) you would need to add code and whether or not such code could influence the page or paragraph breaking?

BTW: Depending whether or not you need the page information of the labels, even the hook of \At@startsection could be wrong for \section etc. because the code execution is before the initial vertical skip and so could be before the page break.

@moewew

This comment has been minimized.

Copy link
Collaborator

moewew commented Feb 2, 2019

We want to be able to execute some initialisation at the beginning of chapters (or sections, ...) in such a way that the code has been executed when the first text-bit (heading or paragraph or ...?) that belongs to the new chapter/section is processed.

At the moment we need this for the three options refsection, refsegment and citereset. Two of those (refsection via \newrefsection and refsegment via \newrefsegment) indeed set \labels, but those labels are never used and I suspect they are only a clever way to provoke a LaTeX rerun warning in case the commands are moved. The page number is not relevant and the reference the label would return is also irrelevant as long as things settle down after enough LaTeX runs. Of course it would feel nicer if the code was executed on the page where the new chapter/section starts (and would return the chapter number), but that is not a requirement as far as I can tell (nor do I have high hopes that everything that 'feels nice' be achieved at the same time).

The code we insert should only do internal biblatex housekeeping. In particular it should not influence any parameters for page and paragraph breaking or produce visible output itself. (Of course the commands do influence output by biblatex commands later on, which could change the text in a paragraph, but that I guess that is not what you intended with your question.)

@komascript

This comment has been minimized.

Copy link
Author

komascript commented Feb 2, 2019

I've added a complete new hook mechanism to KOMA-Script, that can be used. Here is an example of the usage:

\documentclass{scrbook}

\newcommand*{\typeoutandshow}[2]{\typeout{TRACE: heading/#1 #2
    \ifx\IfUseNumber\UseNumberUsageError\else
    \IfUseNumber{with}{without} number\fi}}
\AddtoDoHook{heading/begingroup}{\typeoutandshow{begingroup}}
\AddtoDoHook{heading/endgroup}{\typeoutandshow{endgroup}}


\usepackage{blindtext}

\begin{document}
\tableofcontents
\blinddocument

But be careful, nobody should add an additional hook execution:
\ExecuteDoHook{heading/begingroup/section/fake}
\end{document}

with the result:

TRACE: heading/begingroup chapter without number
TRACE: heading/endgroup chapter without number
TRACE: heading/begingroup chapter with number
TRACE: heading/endgroup chapter with number
TRACE: heading/begingroup section with number
TRACE: heading/endgroup section with number
TRACE: heading/begingroup subsection with number
TRACE: heading/endgroup subsection with number
TRACE: heading/begingroup subsubsection without number
TRACE: heading/endgroup subsubsection without number
TRACE: heading/begingroup paragraph without number
TRACE: heading/endgroup paragraph without number
TRACE: heading/begingroup section with number
TRACE: heading/endgroup section with number
TRACE: heading/begingroup subsection with number
TRACE: heading/endgroup subsection with number
TRACE: heading/begingroup subsubsection without number
TRACE: heading/endgroup subsubsection without number
TRACE: heading/begingroup subsection with number
TRACE: heading/endgroup subsection with number
TRACE: heading/begingroup subsubsection without number
TRACE: heading/endgroup subsubsection without number
TRACE: heading/begingroup subsection with number
TRACE: heading/endgroup subsection with number
TRACE: heading/begingroup subsubsection without number
TRACE: heading/endgroup subsubsection without number
TRACE: heading/begingroup section/fake 

I do not really understand your code in biblatex.sty, but I hope, this will help you. Sorry, I urgently need some sleep now.

You can find some documentation of the new mechanism in scrkernel-basics.dtx or in German at https://komascript.de/node/2225

@moewew

This comment has been minimized.

Copy link
Collaborator

moewew commented Feb 2, 2019

Thanks. I'll have a look and report back. Good night!

moewew added a commit to moewew/biblatex that referenced this issue Feb 4, 2019

Patch KOMA sectioning cmds with \AddtoDoHook (plk#857)
\AddtoDoHook should be available from KOMA script version 3.27 onwards.
Thank you to Markus Kohm for implementing the new interface.
@moewew

This comment has been minimized.

Copy link
Collaborator

moewew commented Feb 4, 2019

@komascript The new hook mechanism looks really promising. Thank you very much. I played around with v3.27.3072 from the SourceForge SVN. Do you expect any interface changes to what you have implemented so far? Or is the bit described in https://komascript.de/node/2225 so stable that we don't have to allow for a buffer before merging the changes at our end?

moewew@a189dad in dev...moewew:komachap is a first attempt to use the new hooks for our purposes. heading/begingroup/... seemed to give good results.

@moewew moewew moved this from To Do to In Progress in biblatex 3.13 Feb 4, 2019

@komascript

This comment has been minimized.

Copy link
Author

komascript commented Feb 4, 2019

@moewew The mechanism is currently two days old. I hope that the command \AddtoDoHook and hook heading/begingroup/... are stable. But I cannot promise. Sometimes ideas seem to be good at the beginning but are not.

I would remove the c in \blx@ifkoma@AddtoDocHook.

@moewew

This comment has been minimized.

Copy link
Collaborator

moewew commented Feb 4, 2019

Ah, thanks for catching that typo. At some point I started to call the command AddtoDocHook in my head, I only noticed that when I tried to use the command and it turned out it was undefined. I must have missed \blx@ifkoma@AddtoDocHook in the renaming process.

I guess I'll wait for bit before I merge the change, a new release of biblatex is probably not going to happen in the near future, so there is no need to rush things and we can see how the hooks develop on your side.


Link back to relevant https://komascript.de/node/2168

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.