0

I would like to create a custom BibTeX(like) entry, say @businesscard with a name a phone number and an age. I imagine it looks something like this

@buisinesscard{Mister_Boss_Sir,
name = {Boss Sir},
phonenumber = {1234567890},
age = {61}}

@buisinesscard{Mrs_Boss_lady,
name = {Boss Lady},
phonenumber = {0987654321},
age = {35}}

And then when I cite the business card (or refer to it in some way) I would like a businesscard to show in the document

so the following code

\begin{document}
first text
\cite(Mr_Boss_Sir)

second text
\end{document}

Would yield the following result:

enter image description here

Is there any way to do this? It doesn't have to involve bibtex or cite really, just anyway to make bundles of information and format the information in a bundle would be great!

1

This can be done with biblatex, but it requires some machinery.

Ulrike Fischer wrote a TUGBoat article about using biblatex for 'non-standard' applications, where she does something similar. In Using BibLaTeX for D&D I show an example of using biblatex for character data in D&D. From there it is only a small step to a business card.

The details of creating a new entry type and using it are explained in How can I create entirely new data types with BibLaTeX/Biber?. With the help of that answer it should be possible to understand what happens in the following code.

Roughly speaking, you need to define a new entry type with new fields and make them known to Biber via the datamodel (.dbx) file.

Then it is only a matter of printing the available data in a nice format. Specifically we define a new citation command that prints a tcolorbox with the business card details.

\begin{filecontents}{businesscard.dbx}
\DeclareDatamodelEntrytypes{businesscard}
\DeclareDatamodelFields[type=field,datatype=literal]{
  phonenumber,
}
\DeclareDatamodelFields[type=list, datatype=name]{
  name,
}
\DeclareDatamodelFields[type=field, datatype=integer]{
  age,
}
\DeclareDatamodelEntryfields[businesscard]{
  name,
  phonenumber,
  age,
}
\end{filecontents}
\documentclass[english]{article}
\usepackage{babel}
\usepackage{csquotes}
\usepackage[datamodel=businesscard, backend=biber]{biblatex}
\usepackage{tcolorbox}

\usepackage{hyperref}

\NewBibliographyString{name,phonenumber,age}
\DefineBibliographyStrings{english}{
  name        = {name},
  phonenumber = {phonenumber},
  age         = {age},
}

\DeclareCiteCommand{\businesscite}
  {}
  {\usebibmacro{businesscite}}
  {}
  {}

\DeclareFieldFormat{businesscard}{%
  \begin{tcolorbox}
  #1
  \end{tcolorbox}} 

\DeclareNameWrapperFormat{name}{\bibstring{name}\addcolon\space#1}
\DeclareFieldFormat{age}{\bibstring{age}\addcolon\space#1}
\DeclareFieldFormat{phonenumber}{\bibstring{phonenumber}\addcolon\space#1}

\newbibmacro{businesscite}{%
  \printtext[businesscard]{%
    \printnames{name}%
    \setunit{\par}%
    \printfield{phonenumber}%
    \setunit{\par}%
    \printfield{age}%
  }%
}

\begin{filecontents*}{\jobname.bib}
@businesscard{Mister_Boss_Sir,
  name        = {Boss Sir},
  phonenumber = {1234567890},
  age         = {61},
}
@businesscard{Mrs_Boss_lady,
  name        = {Boss Lady},
  phonenumber = {0987654321},
  age         = {35},
}
\end{filecontents*}
\addbibresource{\jobname.bib}

\begin{document}
\businesscite{Mister_Boss_Sir}

\businesscite{Mrs_Boss_lady}
\end{document}

Two business cards.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.