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

allnocited or new nocitedstar? #319

Closed
moewew opened this issue Jun 7, 2020 · 5 comments
Closed

allnocited or new nocitedstar? #319

moewew opened this issue Jun 7, 2020 · 5 comments

Comments

@moewew
Copy link
Contributor

moewew commented Jun 7, 2020

I'd like to apply write a sourcemap that entrynulls an entry only if it was only cited via \nocite{*}. In particular I don't want to null entries cited via an explicit \cite{<key>} or via \nocite{<key>}.

First I thought that allnocited would do that, since it is documented as applying to entries included via \nocite{*}. (What I actually want is something that applies to entries included solely because of \nocite{*}.) But allnocited applies to all entries as soon as \nocite{*} is used. (So allnocited only detects if the user had \nocite{*} in their document? Is that right?)

With nocited I can almost get there, but this filter also applies to entries that were explicitly \nocite'd with \nocite{<key>}.

\documentclass[british]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{csquotes}

\usepackage[style=authoryear, backend=biber]{biblatex}

\DeclareSourcemap{
  \maps[datatype=bibtex, overwrite]{
    \map{
      \pernottype{book}
      \step[nocited=true, final]
      \step[entrynull]
    }
  }
}


\begin{filecontents}[force]{\jobname.bib}
@book{book1,
  author  = {{Book A}},
  title   = {Book Title 1},
  date    = {1981},
}
@book{book2,
  author  = {{Book B}},
  title   = {Book Title 2},
  date    = {1982},
}
@book{book3,
  author  = {{Book C}},
  title   = {Book Title 3},
  date    = {1983},
}
@book{book4,
  author  = {{Book D}},
  title   = {Book Title 4},
  date    = {1984},
}
@misc{misc1,
  author  = {{Misc A}},
  title   = {Misc Title 1},
  date    = {1991},
}
@misc{misc2,
  author  = {{Misc B}},
  title   = {Misc Title 2},
  date    = {1992},
}
@misc{misc3,
  author  = {{Misc C}},
  title   = {Misc Title 3},
  date    = {1993},
}
@misc{misc4,
  author  = {{Misc D}},
  title   = {Misc Title 4},
  date    = {1994},
}
\end{filecontents}
\addbibresource{\jobname.bib}


\begin{document}
\autocite{book1,misc1,book4,misc4}
\nocite{book2,misc2,book4,misc4}
\nocite{*}
\printbibliography
\end{document}

The desired result should show

Book A (1981). Book Title 1.
Book B (1982). Book Title 2.
Book C (1983). Book Title 3.
Book D (1984). Book Title 4.
Misc A (1991). Misc Title 1.
Misc B (1992). Misc Title 2.
Misc D (1994). Misc Title 4.

I.e. would only skip misc3, which appears in the bibliography only because of \nocite{*} and not for any other reason.

I guess I'd need a nocitedstar that only applies to entries that were added solely because of \nocite{*} i.e. is false if an entry was \cited or explicitly \nocite'd with \nocite{<key>}.

@moewew
Copy link
Contributor Author

moewew commented Jun 7, 2020

A related issue I just noticed is that the order of \cite and \nocite{*} can matter. Consider

\documentclass{article}         

\usepackage[backend=biber, style=authoryear]{biblatex}


\DeclareSourcemap{
  \maps[datatype=bibtex]{
    \map{
      \perdatasource{\jobname-resource1.bib}
      \step[nocited=true, final]
      \step[entrynull]
    }
  }
}

\begin{filecontents*}[force]{\jobname-resource1.bib}
@article{A2014,
  author  = {First Author},
  journal = {Journal A},
  title   = {First Paper},
  note    = {should appear in bib, because it was cited},
  year    = {2014}
}
@article{D2014,
  author  = {First Author},
  journal = {Journal A},
  title   = {First Paper},
  note    = {should not be seen in bib},
  year    = {2014}
}
\end{filecontents*}
\begin{filecontents*}[force]{\jobname-resource2.bib}
@article{B2014,
  author  = {Another Author},
  journal = {Journal B},
  title   = {Second Paper},
  note    = {should appear in bib, b/c it is in \jobname-resource2 and nocite was issued},
  year    = {2014}
}
@article{C2014,
  author  = {Next Author},
  journal = {Journal C},
  title   = {Third Paper},
  note    = {should appear in bib, b/c it is in \jobname-resource2 and nocite was issued},
  year    = {2014}
}
\end{filecontents*}
\addbibresource{\jobname-resource1.bib}
\addbibresource{\jobname-resource2.bib}


\begin{document}
  \nocite{*}
  This is a citation \cite{A2014}
  %\nocite{*}
  
  \printbibliography
\end{document}

with

\begin{document}
  %\nocite{*}
  This is a citation \cite{A2014}
  \nocite{*}

  \printbibliography
\end{document}

plk added a commit that referenced this issue Jun 7, 2020
@plk
Copy link
Owner

plk commented Jun 7, 2020

I've added the map verb starnocited to catch entrykeys only \nocite{*}ed - seems to get the right results on your example. There is also citedornocited but this is basically the opposite of starnocited. DEV is updated, along with biblatex doc.

@moewew
Copy link
Contributor Author

moewew commented Jun 7, 2020

startnocited seems to work as desired in my first tests. Thank you. I'll do some more testing and will complain if something comes up.

But there is still the issue of order dependency.
Compare

\documentclass{article}

\usepackage[backend=biber, style=authoryear]{biblatex}


\DeclareSourcemap{
  \maps[datatype=bibtex]{
    \map{
      \step[nocited=true, final]
      \step[entrynull]
    }
  }
}

\addbibresource{biblatex-examples.bib}
\begin{document}
  Lorem \autocite{sigfridsson}
  \nocite{*}

  \printbibliography
\end{document}

and

\documentclass{article}

\usepackage[backend=biber, style=authoryear]{biblatex}


\DeclareSourcemap{
  \maps[datatype=bibtex]{
    \map{
      \step[nocited=true, final]
      \step[entrynull]
    }
  }
}

\addbibresource{biblatex-examples.bib}
\begin{document}
  \nocite{*}
  Lorem \autocite{sigfridsson}

  \printbibliography
\end{document}

A similar effect can be observed with cited instead of nocited.

plk added a commit that referenced this issue Jun 7, 2020
@plk
Copy link
Owner

plk commented Jun 7, 2020

Well spotted - this was a bug - it was an assumption from a long time ago before the extra logic was put in for the cite/nocite sourcemaps. Hopefully fixed in DEV biber (no biblatex change).

@moewew
Copy link
Contributor Author

moewew commented Jun 9, 2020

All tests seem to be working well now. Thank you. There are a few real-world use cases I want to check out, so I'll get back to you if there is an issue with one of those.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants