Open denismaier opened 6 years ago
Thank your for that suggestion.
Unfortunately, I have no idea how to safely execute code at every paragraph (there is \everypar
, but that seems to be a bit dangerous). Will look into this, but I can't promise anything.
I don't really like the idea of \iffirstinparagraph
, but maybe citereset=paragraph
is possible.
Yeah, \everypar
is exactly what I use now, but I thought it might be safer and cleaner to have a biblatex solution. Is adding something to \everypar
safe this way: \AtBeginDocument{\appto\everypar{\mancite}}
?
Why don't you like \iffirstinparagraph
?
Not sure about \everypar
at the moment. Will have to do more research. At the moment it seems that \everypar
is used in many places and is possibly redefined by other packages as well, so I'm not sure if we can use it.
I don't like \iffirstinparagraph
since we don't have \iffirstinsection
, \iffirstinchapter
and friends either. We only have \iffirstonpage
and that is different in that a page is an arbitrary unit of text and not defined in the code unlike a paragraph (\par
or blank line) or \section
and friends.
\everypar
is used in too many places. We could patch it, but I'm not sure it is really safe and the reset might be too eager. Everything I find on \everypar
warns against redefining it. csquotes
does it, but the effects are only local, we would need a global effect for the entire document. I'm not seeing that at the moment.
Check out
\usepackage{xcolor}
\makeatletter
\newtoks\blx@ltx@everypar
\let\blx@new@everypar\everypar
\blx@ltx@everypar=\expandafter{\the\everypar}%
\blx@new@everypar={\the\blx@ltx@everypar \textcolor{red}{\textbf{X}}}%
\let\everypar\blx@ltx@everypar
\makeatother
and see where a red X
appears in your document. That would be all places where the tracker would be reset.
See also http://www.tex.ac.uk/cgi-bin/texfaq2html?label=subverttoks
Well, I have just tried it in a MWE, and here it looks just fine. Of course, in a real document where many other packages are loaded things might not so simple.
Edit: I have changed your code to:
\usepackage{xcolor}
\makeatletter
\newtoks\blx@ltx@everypar
\let\blx@new@everypar\everypar
\blx@ltx@everypar=\expandafter{\the\everypar}%
\blx@new@everypar={\the\blx@ltx@everypar \mancite\textcolor{red}{\textbf{X}}}%
\let\everypar\blx@ltx@everypar
\makeatother
Now, I have the red X at the beginning of every paragraph, and the next "ibid" is a short citation.
Of course, in a real document where many other packages are loaded things might not so simple.
That is exactly my concern at the moment. Many packages and document classes modify and use \everypar
. Since it is in general not considered safe to modify everypar
, I simply can't be sure that this would not break anything.
Plus I think everypar
might be a bit too eager, but that may be a matter of taste. It certainly does not only get used at the beginning of what I would consider a paragraph.
Matters of taste aside, would patching \par
be easier?
I don't think so. \par
is redefined regularly as well.
\AtBeginDocument{%
\let\oldpar=\par
\def\par{\textcolor{blue}{X}\oldpar}}
works brilliantly until after the first enumerate
environment in your document. So \everypar
seems to be more persistent, but still...
The original developer of biblatex
also developed csquotes
. In csquotes
he used \everypar
(as I mentioned in a more local/controlled manner), but he did not implement a citereset=par
value that uses \everypar
in biblatex
. Of course it is hard to prove a negative, but I don't want to exclude the possibility that he had technical reasons to not implement a citereset=par
.
For the time being I would not like to include citereset=par
in the biblatex
core. \everypar
does almost what we want, but I think it can be a bit too radical (that might be up for discussion, though) and I can't guarantee that it will always work as expected.
If users want per-paragraph resets, they can try
\documentclass[british]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{csquotes}
\usepackage[style=authoryear-ibid, backend=biber]{biblatex}
\addbibresource{biblatex-examples.bib}
\usepackage{lipsum}
\makeatletter
\newtoks\blx@ltx@everypar
\let\blx@new@everypar\everypar
\blx@ltx@everypar=\expandafter{\the\everypar}%
\blx@new@everypar={\citereset\the\blx@ltx@everypar}%
\let\everypar\blx@ltx@everypar
\makeatother
\begin{document}
\section{foo}
\cite{sigfridsson} \lipsum[1]
\cite{sigfridsson} lorem ipsum \cite{sigfridsson}
\lipsum[2]
\cite{sigfridsson} lorem ipsum \cite{sigfridsson}
\section{goo}
\lipsum[1-2]
\subsection{huu}
\lipsum[2]
\cite{sigfridsson} lorem ipsum \cite{sigfridsson}
\lipsum[3]
\cite{sigfridsson} lorem ipsum \cite{sigfridsson}
\lipsum[4]
\cite{sigfridsson} lorem ipsum \cite{sigfridsson}
\lipsum[5]
\paragraph{hallo} ipsum
\end{document}
as explained above (cf. http://www.tex.ac.uk/cgi-bin/texfaq2html?label=subverttoks).
If it turns out that this is a much sought-after feature, or that \everypar
is a safe way to do this, we can reconsider this and re-open this issue.
LaTeX 2021-06-01 adds new paragraph hooks that we could use here (http://mirrors.ctan.org/macros/latex/base/ltpara-doc.pdf), so I'll reopen this.
The following should work
\documentclass[british]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{csquotes}
\usepackage[backend=biber, style=authoryear-ibid]{biblatex}
\usepackage{lipsum}
\AddToHook{para/before}{\citereset}
\addbibresource{biblatex-examples.bib}
\begin{document}
\section{foo}
\autocite{sigfridsson} \lipsum[1]
\autocite{sigfridsson} lorem ipsum \autocite{sigfridsson}
\lipsum[2]
\autocite{sigfridsson} lorem ipsum \autocite{sigfridsson}
\section{goo}
\lipsum[1-2]
\subsection{huu}
\lipsum[2]
\autocite{sigfridsson} lorem ipsum \autocite{sigfridsson}
\lipsum[3]
\autocite{sigfridsson} lorem ipsum \autocite{sigfridsson}
\lipsum[4]
\autocite{sigfridsson} lorem ipsum \autocite{sigfridsson}
\lipsum[5]
\paragraph{hallo} ipsum
\end{document}
But some more testing might be good before we fall into a trap here.
Cool that these new hooks are coming!
FWIW, your example does not show the new behaviour as there's new paragraph break between the citations... `\subsection{huu} happens to be on a new page anyway, so the ibid. is being suppressed there even without the new option...
\documentclass[british]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{csquotes}
\usepackage[backend=biber, style=authoryear-ibid]{biblatex}
\usepackage{lipsum}
\AddToHook{para/before}{\citereset}
\addbibresource{biblatex-examples.bib}
\begin{document}
\section{foo}
\autocite{sigfridsson} \lipsum[1]\par
\autocite{sigfridsson} lorem ipsum \autocite{sigfridsson}
\lipsum[2]\par
\autocite{sigfridsson} lorem ipsum \autocite{sigfridsson}
\section{goo}
\lipsum[1-2]
\subsection{huu}
\lipsum[2]
\autocite{sigfridsson} lorem ipsum \autocite{sigfridsson}
\lipsum[3]
\autocite{sigfridsson} lorem ipsum \autocite{sigfridsson}
\lipsum[4]
\autocite{sigfridsson} lorem ipsum \autocite{sigfridsson}
\lipsum[5]
\paragraph{hallo} ipsum
\end{document}
Ach! Sorry, I sent this example off before I actually had a chance to test it with the new LaTeX kernel on my machine (MikTeX only got me the update today). I'm now wondering whether the example had always been bad or whether \lipsum
used to always end its output on a \par
... (I know there were some changes to lipsum
).
Anyway, here is a more useful example
\documentclass[british]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{mathtools}
\usepackage{csquotes}
\usepackage[backend=biber, style=authoryear-ibid]{biblatex}
\usepackage{hyperref}
\usepackage{lipsum}
\AddToHook{para/before}{\citereset}
\addbibresource{biblatex-examples.bib}
\begin{document}
\section{foo}
\autocite{sigfridsson} \lipsum[1][1-2]
\autocite{sigfridsson} lorem ipsum \autocite{sigfridsson}
\lipsum[2][1-2]
\autocite{sigfridsson} lorem ipsum \autocite{sigfridsson}
\section{goo}
\lipsum[1]
\subsection{huu}
\lipsum[2][1-2]
\autocite{sigfridsson} lorem ipsum \autocite{sigfridsson}
\lipsum[3][1-2]
\autocite{sigfridsson} lorem ipsum \autocite{sigfridsson}
\lipsum[4][1-2]
\autocite{sigfridsson} lorem ipsum \autocite{sigfridsson}
\lipsum[5][1-2]
\paragraph{hallo} ipsum \autocite{sigfridsson}
\lipsum[6][1-2] \autocite{sigfridsson}
\[
x^{2}+y^{2} = z^{2}
\]
dolor \autocite{sigfridsson} \lipsum[7][1-2]
\lipsum[8] \autocite{sigfridsson}
\begin{align}
\int f(x) \mathrm{d}(x)
&= \int f(x) \mathrm{d}\lambda(x)\\
&= \sum_{i=0}^{n} a_{i} \lambda(A_i)
\end{align}
sit \autocite{sigfridsson} \lipsum[9][1-2]
\lipsum[10]
\autocite{sigfridsson} \lipsum[11][1]
\begin{enumerate}
\item lorem
\item ipsum
\item dolor
\end{enumerate}
sit \autocite{sigfridsson}
\lipsum[11][2] \autocite{sigfridsson}
\lipsum[12]
\autocite{sigfridsson} \lipsum[13][1]
\begin{table}[hbtp]
\begin{tabular}{ll}
a & b\\
c & d\\
\end{tabular}
\end{table}
dolor \autocite{sigfridsson} \lipsum[14][1]
\lipsum[15-16]
\autocite{sigfridsson} \lipsum[16][1]
\begin{figure}[hbtp]
A
\end{figure}
dolor \autocite{sigfridsson} \lipsum[17][1]
\end{document}
Things look mostly good so far. I could observe two quirks so far.
enumerate
start a new paragraph for every \item
and end in a paragraph. If one considers the list to be part of the surrounding paragraph the hook would be executed too many times.
The style authortitle-ticomp is very concise, which is nice. However, I want a "short citation" rather than "ibid" at the beginning of new paragraph.
Right now, it is possible to check if a citation is the first on a page with
\iffirstonpage
. Why not introduce a similar test\iffirstinparagraph
?Another option would be a new option:
ibidreset
. Options would be the same as withcitereset
, and also paragraph.This might be helpful for many styles, e.g. MLA or Chicago Author Date.