7

Let us a say that I am preparing a course introduction slide and will want to add an image to each entry in the bibliography. (This will serve two purposes, the names will stick to the minds of the students, and that will save the presentation from being boring, specially in my first session of the course.)

So far, I had done this manually (copy-paste of pre-generated bibliography at appropriate places).

\documentclass{beamer}

\usepackage{graphicx}

\begin{document}

\begin{frame}
  \frametitle{References}
  \begin{columns}
    \begin{column}{0.4\textwidth}
      \begin{center}
        \includegraphics[width=\textwidth]{figures/lamport}
      \end{center}
    \end{column}
    \begin{column}{0.7\textwidth}
      \begin{itemize}
      \item L.~Lamport, {\em LaTeX - {A} Document Preparation System:
          User's Guide and Reference Manual, Second Edition}.  Pearson
        / Prentice Hall, 1994.
      \end{itemize}
    \end{column}
  \end{columns}
\end{frame}

\end{document}

The output was rather nice.

enter image description here

But I would like to get rid of the manual part (which is rather tedious and error-prone, and not very scalable) and was wondering whether it would be possible to do this automatically.

My attempts so far has been to use the note field of .bib entries.

\documentclass{beamer}

\bibliographystyle{ieeetr}

\def\bibimage#1#2{\includegraphics[#1]{figures/#2}}

\usepackage{filecontents}

\begin{filecontents}{\jobname.bib}
 @book{DBLP:books/daglib/0023602,
  author    = {Leslie Lamport},
  title     = {LaTeX - {A} Document Preparation System: User's Guide and Reference
               Manual, Second Edition},
  year      = {1994},
  publisher = {Pearson / Prentice Hall},
  note = {\bibimage{width=0.25\textwidth}{lamport}}}

\end{filecontents}

\usepackage{graphicx}

\begin{document}


\nocite{DBLP:books/daglib/0023602}

\begin{frame}
  \frametitle{Text Books and Other Resources}
  \bibliography{\jobname}
\end{frame}

\end{document}

However, I can not control the location of the image. My vision, as you have seen at the start of this post, is to place the texts of each entry at left or right, and the corresponding image on the other side in a balanced way.

1

3 Answers 3

5

It is error-prone, but I'm not sure hacking the .bst is the way to go: seems like a lot of work for a very specialized use. I might simplify your approach with something like:

\newcommand{\picnbib}[2]{%
% #1 = picture call ; #2 the bibliography reference (NB: I used biblatex)
   \begin{columns}
    \begin{column}{0.4\textwidth}
      \begin{center}
        \includegraphics[width=\textwidth]{#1}% 
      \end{center}
    \end{column}
    \begin{column}{0.7\textwidth}
      \begin{itemize}
      \item \fullcite{#2}
      \end{itemize}
    \end{column}
  \end{columns}
}

So, putting it together:

\documentclass{beamer}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
 @book{lamport1994,
  author    = {Leslie Lamport},
  title     = {LaTeX - {A} Document Preparation System: User's Guide and Reference
               Manual, Second Edition},
  year      = {1994},
  publisher = {Pearson / Prentice Hall},
  location  = {Wherever},
}
\end{filecontents}
%   note = {\bibimage{width=0.25\textwidth}{lamport}}

\usepackage{graphicx}
\usepackage[style=authortitle]{biblatex}
\addbibresource{\jobname.bib}

\newcommand{\picnbib}[2]{%
   \begin{columns}
    \begin{column}{0.4\textwidth}
      \begin{center}
        \includegraphics[width=\textwidth]{#1}
      \end{center}
    \end{column}
    \begin{column}{0.7\textwidth}
      \begin{itemize}
      \item \fullcite{#2}
      \end{itemize}
    \end{column}
  \end{columns}
}

\begin{document}

\begin{frame}
  \frametitle{References}
  \picnbib{figures/lamport}{lamport1994}
\end{frame}

\end{document}

You might want to tweak the above widths; I left them unchanged from your example.

Edit If you can't use biblatex, things are more difficult and more fragile. But here's an idea that relies on usebib:

\documentclass{beamer}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
 @book{lamport1994,
  author    = {Leslie Lamport},
  title     = {LaTeX - {A} Document Preparation System: User's Guide and Reference
               Manual, Second Edition},
  year      = {1994},
  publisher = {Pearson / Prentice Hall},
  location  = {Wherever},
  picture   = {\includegraphics[width=0.5\textwidth]{000.jpg}},% <-- change the image file!
}
\end{filecontents}
%   note = {\bibimage{width=0.25\textwidth}{lamport}}

\usepackage{graphicx}
\usepackage{natbib}
\usepackage{usebib}
\newbibfield{author}
\newbibfield{picture}
\newbibfield{publisher}
\bibinput{\jobname}


\newcommand{\picnbib}[1]{%
   \begin{columns}
    \begin{column}{0.4\textwidth}
      \begin{flushright}
%        \includegraphics[width=0.5\textwidth]{#1}
        \usebibentry{#1}{picture}
      \end{flushright}
    \end{column}
    \begin{column}{0.7\textwidth}
      \begin{itemize}
      \item \printbibentry{#1}%
      \end{itemize}
    \end{column}
  \end{columns}
}
\newcommand{\printbibentry}[1]{%
  \usebibentry{#1}{author},
  {\itshape \usebibentry{#1}{title}}
  (\usebibentry{#1}{publisher}, \usebibentry{#1}{year})
}

\begin{document}

\begin{frame}
%\printbibentry{lamport1994}
  \frametitle{References}
  \picnbib{lamport1994}
\end{frame}

\bibliographystyle{plain}
\bibliography{\jobname}

\end{document}

What you need to note is that you'll need to create a variation on the \picnbib command for each different entry type. Also, by hardwiring the picture into the bib file, you might need to be very careful about what \includegraphics is doing in each entry.

3
  • I do not use biblatex, rather I use bibtex. Rather too pressed to spend those couple of minutes to switch to the former. Is a solution possible with bibtex? Also, the image is not tagged to the bibliography entry. Any comment on this issue?
    – Masroor
    Commented Oct 18, 2014 at 10:55
  • 1
    @Masroor -- (1) regarding the BibTeX vs biblatex switch, I don't know what to say; the difference is about three lines in your .tex file unless you've hard-written funky BibTeX stuff into your file. This is much less work than creating a whole new .bst to do what you want. (2) For 'tagging', if you mean 'linking' the the 'bibitem' and the image, that would be easy in biblatex, and probably more difficult in traditional BibTeX. For both (1) and (2), it is possible to do something using usebib, but it will be very fragile. I'll add something.
    – jon
    Commented Oct 18, 2014 at 15:50
  • I posted another answer which is nothing but an extension of your answer. Before that, I made it a point to accept your answer. One additional benefit for me in the process was learning to use biblatex which seem to like immensely.
    – Masroor
    Commented Nov 6, 2014 at 15:14
4

Another approach to doing this is with Bibulous in place of BibTeX or Biblatex, and is worth noting because the implementation is straightforward. Using the example bib database file below

@Book{Lamport-1994,
  author = {Leslie Lamport},
  title = {LaTeX: A Document Preparation System: User's Guide and Reference Manual},
  edition = {2},
  year = {1994},
  image_filename = {lamport_image},
  publisher = {Pearson / Prentice Hall}
}

@Book{Knuth-1984,
  title = {TeXbook},
  year = {1984},
  author = {Donald Knuth},
  image_filename = {knuth_image},
  publisher = {Addison-Wesley}
}

@Book{Gratzer-2007,
  title = {More Math into LaTeX},
  year = {2007},
  author = {George Gr{\"a}tzer},
  edition = {4},
  image_filename = {gratzer_image},
  publisher = {Springer}
}

we can create a template for inserting images at the front of each bibliography entry as follows. (Note that the database file contains only books, and so the only template defined here is that for book entries.)

TEMPLATES:
book = \begin{minipage}{\linewidth}...
          \begin{minipage}{\makeopenbracket}c{\makeclosebracket}{0.15\linewidth}...
             \includegraphics{\makeopenbracket}width=\linewidth{\makeclosebracket}{<image_filename>}...
          \end{minipage}...
          \hfill...
          \begin{minipage}{\makeopenbracket}c{\makeclosebracket}{0.8\linewidth}...
             <au>, \textit{<title>}[, <edition.ordinal()> Edition]. <publisher>, <year>. ...
          \end{minipage}...
       \end{minipage}

The template creates a pair of minipages -- one for inserting the image, and one for the corresponding text, so that the two are centered relative to one another. The text is formatted with a template that closely follows the OP's example.

Using this template file with the above database, running PDFTeX on the main file

\documentclass{article}
\usepackage[pdftex]{graphicx}
\usepackage[paper=letterpaper, text={4in,5in},centering]{geometry}

\makeatletter
   \renewcommand{\@biblabel}[1]{}
   \newcommand{\citenum}[1]{\def\@cite##1##2{##1}\cite{#1}}
\makeatother

\begin{document}

References \citenum{Knuth-1984}, \citenum{Lamport-1994}, and \citenum{Gratzer-2007} are useful for learning {\TeX} and \LaTeX.

\bibliography{example10}
\bibliographystyle{example10}

\end{document}

produces the output shown below

Result

1
  • Looks like a promising one. Please give me a few days to test your solution. A little pressed right now.
    – Masroor
    Commented Oct 23, 2014 at 15:18
2

(This answer is actually an extension of this answer, which I already accepted. Still I am posting this with the hope that the extended version might be useful to somebody. This answer let you create a style file, picinbib.sty, with a few optional switches which may come to use.)


Solution Code

\documentclass{beamer}

\usepackage{filecontents}

\begin{filecontents}{\jobname.bib}
  @BOOK{Lamport199407, 
    title={LaTeX: A Document Preparation System},
    author={Leslie Lamport},
    publisher={Addison-Wesley Professional},
    year={1994},
    month=jul,
    edition={2nd}
  }
\end{filecontents}

\begin{filecontents}{picinbib.sty}
% Adapted from https://tex.stackexchange.com/a/207763/14103 
% Usage is \picinbib[L|R]{imagefile}{reference key}

\ProvidesPackage{picinbib}
\RequirePackage{graphicx}
\RequirePackage{biblatex}
\RequirePackage{xstring}
\newcommand{\picinbib}[3][L]{%
  \def\@side{L}%
  \IfEqCase{#1}{%
    {L}{\relax}%
    {R}{\def\@side{R}}%
  }[\PackageWarning{picinbib}{Undefined option: #1}]
  \csname picinbib@\@side\endcsname{#2}{#3}}


\def\@reference@content#1{%
  \begin{column}{0.80\textwidth}%
    \begin{itemize}%
    \item\fullcite{#1}%
      \end{itemize}%
    \end{column}%
  }
\def\@referene@picture#1{%
  \begin{column}{0.20\textwidth}%
    \begin{center}%
      \includegraphics[width=\textwidth]{#1}%
    \end{center}%
  \end{column}%
}

% Image at left
\def\picinbib@L#1#2{%
  \begin{columns}
    \@referene@picture{#1}
    \@reference@content{#2}
  \end{columns}
}

% Image at right
\def\picinbib@R#1#2{%
  \begin{columns}
    \@reference@content{#2}
    \@referene@picture{#1}
  \end{columns}
}

\endinput
\end{filecontents}

\usepackage{picinbib}

\addbibresource{\jobname.bib}


\begin{document}

\begin{frame}

  \picinbib{lamportcover}{Lamport199407}
  \picinbib[R]{lamportcover}{Lamport199407}
  \picinbib[L]{lamportcover}{Lamport199407}
  \picinbib[X]{lamportcover}{Lamport199407}

\end{frame}

\end{document}

Usage of the Above Code

  1. Save the complete code in a file, say, mybibpic.tex.
  2. Save this image file in the same directory with the name, lamportcover.png.

Now execute the following commands,

pdflatex mybibpic
biber mybibpic
pdflatex mybibpic
pdflatex mybibpic

The above generates the file picinbib.sty which can be used for other projects. (And definitely generates mybibpic.pdf which shows your result.)


Usage for Other Projects

Copy picinbib.sty (generated in the previous section) to some location where LaTeX can find it.

Command provided by the above style file is,

\picinbib[L|R]{imagefile}{bibliography reference key}

where L|R determines image location, left or right. Default is at left.

2
  • A definite improvement/extension!
    – jon
    Commented Nov 9, 2014 at 0:47
  • @jon I am glad that you like it.
    – Masroor
    Commented Nov 9, 2014 at 0:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .