Idraluna Archives

LaTeX for RPGs: Monster Macros from a CSV

Step 1: Download or make a csv file with monster stats.

I'm using columns A-P of the free and open-source Basic Fantasy RPG monsters from the sheet here. Similar spreadsheets exist for most popular systems. Whatever you use, Make sure the file doesn't include any commas in the cells (use find-replace in excel or google sheets to delete them or replace with semicolons)

Step 2: Add \usepackage[l3]{csvsimple} to your document preamble. Documentation.

Step 3: Design a macro.

Here's a simple example that prints some commonly-used stats inline with a block of text. This one would work well if you need to insert monster stats into a room description or something:

% Macro for simple inline monster stats:
\newcommand{\monsterinl}[1]{  % define a new macro called \monsterinl with one input
\csvreader[
filter strcmp={\Name}{#1}  % filter the csv file such that the \Name column (defined below) equals the command input.
]{Basic-Fantasy-Creature-List.csv}  % specify the csv file
{3=\Name,7=\HD, 5=\AC, 9=\atk, 10=\dmg, 11=\mv, 13=\sv, 6=\spec}{  % specify macros for each column. In this case, column 3 has the name info, etc.
{\large\bfseries \Name } \textemdash \  % Print the monster name in large, bold type
HD: \HD, AC: \AC, \atk \ (\dmg), Move \mv, Save as \sv.  % List the minimum viable stats.
\textit{\spec}  % Display special powers in italics, if any
}
}

Invoking it by adding \monsterinl{Fire Giant} somewhere in the document produces:

Here's a fancier stat block that creates a tabular output with optional space for an image:

% Macro for a more detailed stat block:

\usepackage{booktabs}  % for nice horizontal lines
\usepackage{tabularray}  % for making nicer tables
\UseTblrLibrary{booktabs}

\newcommand{\monsterblock}[2]{
\csvreader[
filter strcmp={\Name}{#1}
]{Basic-Fantasy-Creature-List.csv}  % specify the csv file
{3=\Name,7=\HD, 5=\AC, 9=\atk, 10=\dmg, 11=\mv, 13=\sv,
    6=\spec, 14=\morale, 16=\xp, 17=\tr, 12=\napp}{

\begin{minipage}{0.7\textwidth}  % put the statblock in a minipage next to an illustration
  {\large\bfseries \Name } \\
  \begin{tblr}{colspec={X[1,l]X[1,l]X[1.75,l]}}\midrule
    AC: \AC & HD: \HD & \# Attacks: \atk \\
    Move: \mv & Morale: \morale  & Damage: \dmg  \\
    Save as: \sv & \# Appearing: \napp  & \SetCell[r=2,c=1]{l} \textit{\spec} \\
    XP: \xp & Treasure: \tr & \\ \midrule
  \end{tblr}
\end{minipage}\hspace{0.04\textwidth}\begin{minipage}{0.25\textwidth}
  \includegraphics[width=\textwidth]{#2}
\end{minipage}
}
}

Using this, \monsterblock{Mastodon}{Mastodon.jpg} produces:

The empty space at the bottom-right is reserved for special abilities - for example, \monsterblock{Ochre Jelly*} produces:

These are just rough proofs-of-concept - with a little extra work one could generate even nicer-looking output or detailed simulacra of one's preferred system. The beauty of typesetting in LaTeX is that if you change systems or decide you want to format the stat blocks differently, you just need to alter the csv and/or macro definition accordingly, and everything else in your document will update.

Additional Ideas

#DIY #LaTeX