Using BibLaTeX for D&D

It is possible to do this with biblatex (people have done all sorts already: https://www.tug.org/TUGboat/tb35-3/tb111fischer.pdf), but this might not be the most comfortable way to deal with this. biblatex offers a lot of things you won't need and it might be complicated to redefine and opt out of certain things you don't want and get the things you'd like to have instead. In particular it could be painful to obtain a tabular stats block.

There are other tools that can read in data and display it according to your wishes. datatool comes to mind, but Lua (of LuaLaTeX fame) could also offer you some possibilities.

Have a look at How can I create entirely new data types with BibLaTeX/Biber? for the details of defining a new entry type and its driver.

\RequirePackage{filecontents}
\begin{filecontents*}{\jobname.bib}
@monster{gazebo,
  name      = {Gazebo},
  size      = {large},
  alignment = {lawful evil},
  ac        = {13},
  hp        = {13 (2d8+4)},
  speed     = {5ft},
}
\end{filecontents*}
\begin{filecontents}{dnd.dbx}
\DeclareDatamodelEntrytypes{monster}
\DeclareDatamodelFields[type=field,datatype=literal]{
  name,
  size,
  alignment,
  ac,
  hp,
  speed,
}
\DeclareDatamodelEntryfields[monster]{
  name,
  size,
  alignment,
  ac,
  hp,
  speed,
}
\end{filecontents}
\documentclass[english]{article}
\usepackage{babel}
\usepackage{csquotes}
\usepackage[datamodel=dnd,style=authoryear,backend=biber]{biblatex}
\usepackage{hyperref}
\addbibresource{\jobname.bib}

\DeclareFieldFormat{alignment}{\mkbibparens{#1}}

\DeclareFieldFormat{ac}{AC\space#1}
\DeclareFieldFormat{hp}{#1\addspace HP}
\DeclareFieldFormat{speed}{Speed\addcolon\space#1}

\DeclareBibliographyDriver{monster}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \printfield{name}%
  \setunit{\addspace}%
  \printfield{alignment}%
  \newunit\newblock
  \printfield{size}%
  \newunit\newblock
  \printfield{ac}%
  \newunit\newblock
  \printfield{hp}%
  \newunit\newblock
  \printfield{speed}%
  \newunit\newblock
  \usebibmacro{finentry}}

\renewbibmacro*{cite}{\printfield[bibhyperref]{name}}

\begin{document}
Then Eric was attacked by a \cite{gazebo}

\printbibliography[title=Monsters]
\end{document}

Then Eric was attacked by a Gazebo//(Heading)Monsters//Gazebo (lawful evil). large. AC 13. 13 (2d8+4) HP. Speed: 5ft.

Depending on how interactive you'd like your document to be maybe PDF is not the right medium and you want a more dynamic HTML page instead? Markdown might be a lighter alternative to LaTeX markup when you don't need most of LaTeX's advanced (especially mathematical and general typographic) features.


Rather than biblatex, perhaps you want the glossaries package.

\documentclass{article}

\usepackage{hyperref}
\usepackage[nonumberlist]{glossaries}

\newglossary*{monster}{Bestiary}
\newglossary*{npc}{Characters}


\makeglossaries

\newglossaryentry{monster:skeleton}{
    name = Skeleton,
    type=monster,
    description = {size: medium,\\
    alignment: lawful evil,
    ac: 13,
    hp: 13 (2d8+4),
    speed: 30ft}
}
\newglossaryentry{npc:king}{
    name = King Knuth,
    description = {Ruler of the realm},
    type = npc
}

\begin{document}

A \gls{monster:skeleton} attacks \gls{npc:king}

\printglossaries

\end{document}

enter image description here

Tags:

Biblatex