2

Usually, in .bib entry for a publication for instance by IEEE, ACM, a field can be added called "copyright" to include copyright information. Then, in the LaTeX document being prepared using book class and BibTeX, if a figure from previously published work is used as it is, how do you make an entry of something like:

Figure XX reproduced with permission from \cite{key}{copyright}?

P.S. I am trying to avoid usage of biblatex package. Is there a quick fix just by using BibTeX?

moewe
  • 175,683
  • I'm not aware of a BibTeX solution that lets you extract arbitrary content from a .bib file. I guess you would have to write your own .bst file (or modify an existing one) to write the contents of the copyright field to the .bbl and fiddle with a few internal commands that implement \cite and friends to obtain the data from the .bbl file and print it. I'm not saying that this is impossible, but I am saying it is going to be a bit of work. And you will have to decide whether the effort is worth it. – moewe Jun 13 '18 at 07:45
  • The exact implementation of course depends on the bibliography package (cite, natbib, ...) and style you use. – moewe Jun 13 '18 at 07:46
  • @moewe The tool exists… – egreg Jun 13 '18 at 13:34
  • @egreg In the back of my mind I kind of remembered a package written by you, but I could not remember the name and only found bibentry (which is neither yours, nor does it help a lot here) ... – moewe Jun 13 '18 at 13:42

2 Answers2

6

This is not impossible, but it requires a bit of fiddling with your .bst file. As it turns out I had forgotten about usebib (see egreg's answer) which already provides an interface for reading fields from .bib files. usebib uses a different method, it parses the .bib file directly with key-value syntax.


What makes this difficult is the fact that LaTeX does not read the .bib file directly itself. Instead BibTeX reads the .bib file and produces a sorted and formatted bibliography in the .bbl file. This .bbl file is then read by LaTeX and becomes the bibliography. (You can read more about this in Question mark or bold citation key instead of citation number.)

Since LaTeX itself never reads the .bib file one way to get the copyright information to LaTeX is to instruct BibTeX to include it in the .bbl file - not in a way visible in the output, just in a way that LaTeX can use. There is one difficulty with this approach: the .bbl file is read and processed when you write \bibliography in your .tex file. In all likeliness this is after the point where you want to cite the copyright data. We can try to work around this limitation by doing what natbib does to obtain the author and year data for author year citations: We add a command in the .bbl file that when executed writes the data to the .aux file. Upon the next LaTeX run the copyright data is available in the .aux file and will be processed at the beginning of the document, before any copyright citation is issued. The data is then available whenever you want to cite the copyright info.

The first step is to modify your .bst file to pass on the copyright data. The exact modifications needed depend on the .bst file, but the process should be almost identical for most styles.

Under https://gist.github.com/moewew/0fefe855a269f5eed06a5b6260f23bfd you can find a modified version of plain.bst called plain-copy.bst that includes the copyright data in the .bbl. The necessary changes were

  1. Add copyright to the list of known fields in the first argument of ENTRY
  2. Make sure that the data is written out. In plain.bst that was achieved by modifying the function output.bibitem from

    FUNCTION {output.bibitem}
    { newline$
      "\bibitem{" write$
      cite$ write$
      "}" write$
      newline$
      ""
      before.all 'output.state :=
    }
    

    to

    FUNCTION {output.bibitem}
    { newline$
      "\bibitem{" write$
      cite$ write$
      "}\makeatletter\cc@bbl@citecopyright{" write$
      cite$ write$
      "}{" write$
      copyright write$
      "}\makeatother" write$
      newline$
      ""
      before.all 'output.state :=
    }
    

The patch for the change is

--- plain.bst   2010-12-09 04:18:56.000000000 +0100
+++ plain-copy.bst  2018-06-13 10:10:10.732783800 +0200
@@ -1,12 +1,11 @@
-% BibTeX standard bibliography style `plain'
-   % Version 0.99b (8-Dec-10 release) for BibTeX versions 0.99a or later.
+% BibTeX standard bibliography style `plain-copy'
+   % based on `plain.bst' version 0.99b (8-Dec-10 release)
    % Copyright (C) 1984, 1985, 1988, 2010 Howard Trickey and Oren Patashnik.
    % Unlimited copying and redistribution of this file are permitted as long as
    % it is unmodified.  Modifications (and redistribution of modified versions)
    % are also permitted, but only if the resulting file is renamed to something
    % besides btxbst.doc, plain.bst, unsrt.bst, alpha.bst, and abbrv.bst.
    % This restriction helps ensure that all standard styles are identical.
-   % The file btxbst.doc has the documentation for this style.

 ENTRY
   { address
@@ -31,6 +30,7 @@
     type
     volume
     year
+    copyright
   }
   {}
   { label }
@@ -86,7 +86,11 @@
 { newline$
   "\bibitem{" write$
   cite$ write$
-  "}" write$
+  "}\makeatletter\cc@bbl@citecopyright{" write$
+  cite$ write$
+  "}{" write$
+  copyright write$
+  "}\makeatother" write$
   newline$
   ""
   before.all 'output.state :=

Then you need to add a few macros to your document preamble.

\usepackage{etoolbox}
\makeatletter
\newcommand*{\cc@bbl@citecopyright}[2]{%
  \if@filesw
    \write\@auxout{\string\cc@aux@citecopyright{#1}{#2}}%
  \fi}

\newcommand*{\cc@aux@citecopyright}[2]{%
  \csgdef{cc@data@citecopyright@#1}{#2}}

\newcommand*{\citecopyright}[1]{%
  \ifcsundef{cc@data@citecopyright@#1}
    {\textbf{?}%
     \PackageWarning{'citecopyright'}{%
       Copyright field for #1 not found}}
    {\csuse{cc@data@citecopyright@#1}}}
\makeatother

\cc@bbl@citecopyright is the command for the .bbl file and writes its argument to the .aux file and calls \cc@aux@citecopyright on them. \cc@aux@citecopyright simply saves the data for later use, so that \citecopyright can access it.

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

%\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@book{appleby,
  author  = {Humphrey Appleby},
  title   = {On the Importance of the Civil Service},
  year    = {1980},
  copyright = {IEEE},
}
\end{filecontents}

\usepackage{etoolbox}
\makeatletter
\newcommand*{\cc@bbl@citecopyright}[2]{%
  \if@filesw
    \write\@auxout{\string\cc@aux@citecopyright{#1}{#2}}%
  \fi}

\newcommand*{\cc@aux@citecopyright}[2]{%
  \csgdef{cc@data@citecopyright@#1}{#2}}

\newcommand*{\citecopyright}[1]{%
  \ifcsundef{cc@data@citecopyright@#1}
    {\textbf{?}%
     \PackageWarning{'citecopyright'}{%
       Copyright field for #1 not found}}
    {\csuse{cc@data@citecopyright@#1}}}
\makeatother

\begin{document}
\begin{figure}
\centering
\includegraphics{example-image-duck}
\caption{A duck}\label{fig:duck}
\end{figure}
Figure~\ref{fig:duck} reproduced with permission from \citecopyright{appleby} \cite{appleby}

\bibliographystyle{plain-copy}
\bibliography{\jobname}
\end{document}

This file needs to be compiled at least with

pdflatex test
bibtex test
pdflatex test
pdflatex test

enter image description here


You say that you don't want to switch to biblatex, but just for fun here is the biblatex solution.

Here we "only" need to tell Biber about our new field copyright. This is done via the datamodel file copyright.dbx. We declare copyright as literal list and make it known to all data types.

Then you can use \citelist{<key>}{copyright} to obtain the copyright information. But I find it nicer to define a dedicated macro \citecopyright and use that.

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

%\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@book{appleby,
  author  = {Humphrey Appleby},
  title   = {On the Importance of the Civil Service},
  year    = {1980},
  copyright = {IEEE},
}
\end{filecontents}

\begin{filecontents}{copyright.dbx}
\ProvidesFile{copyright.dbx}[2018/06/13 Copyright field for biblatex]
\DeclareDatamodelFields[type=list, datatype=literal]{copyright}
\DeclareDatamodelEntryfields{copyright}
\end{filecontents}
\usepackage[backend=biber, style=numeric, datamodel=copyright]{biblatex}

\addbibresource{\jobname.bib}

\DeclareCiteCommand{\citecopyright}
  {\boolfalse{citetracker}%
   \boolfalse{pagetracker}%
   \usebibmacro{prenote}}
  {\printlist{copyright}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\begin{document}
\begin{figure}
\centering
\includegraphics{example-image-duck}
\caption{A duck}\label{fig:duck}
\end{figure}
Figure~\ref{fig:duck} reproduced with permission from \citecopyright{appleby} \cite{appleby}

\printbibliography
\end{document}

enter image description here

moewe
  • 175,683
6

This is a job for usebib. You can define a new bib field copyright and then you can print the field's content with

\usebibentry{<bib key>}{copyright}

Full example (picture like in moewe's answer).

\begin{filecontents}{\jobname.bib}
@book{appleby,
  author  = {Humphrey Appleby},
  title   = {On the Importance of the Civil Service},
  year    = {1980},
  copyright = {IEEE},
}
\end{filecontents}

\documentclass{article}
\usepackage{usebib} % the main one

% the next two are just for the picture
\usepackage{graphicx}
\usepackage{duckuments}

% load the bib file
\newbibfield{copyright}
\bibinput{\jobname}

\begin{document}

\begin{figure}
\centering
\includegraphics{example-image-duck}
\caption{A duck}\label{fig:duck}
\end{figure}
Figure~\ref{fig:duck} is \textcopyright\usebibentry{appleby}{copyright}.

\bibliographystyle{plain}
\bibliography{\jobname}

\end{document}

In your document, use the name of the right .bib file instead of \jobname.

enter image description here

egreg
  • 1,121,712