0

I am writing a novel and I would like to create a data structure to hold character attributes and be able to reference the values.

I looked into creating custom glossaries, bibtex and datatool structure but I wasn't able to find a suitable method. I would much prefer not creating custom commands and using native latex available functionality.

Example

character{emma,
    title = {Emma},
    dateofbirth = {1995-05-10},
    eyecolor = {brown}
}

Emma her eye colour is \ref{emma:eyecolor}.

Rien
  • 195
  • 1
    "Standard LaTeX" does not have a function to do that out of the box. You will have to resort to packages. I'm not sure if biblatex is your best bet here, but since you tagged your question biblatex, let me say that you can define new data types as described in https://tex.stackexchange.com/q/175776/35864 and that you can extract specific data from entries as shown in https://tex.stackexchange.com/q/207591/35864. – moewe Jul 02 '23 at 15:37
  • This could be a solution, I tried it but cant get the MWE working. All I see is [se:l3help] on the page, not its contents. – Rien Jul 02 '23 at 15:51
  • 1
    Do you really need to use external tools to manage this? It's easy to set up a data structure like your example using expl3 property lists. Also it's not too difficult to parse JSON input in LuaTeX. See Ways to parse JSON in LaTeX?. – Alan Munn Jul 02 '23 at 16:12
  • I have not used expl3 before and not sure how it works, I dont want to make it too complicated, not for myself but also others – Rien Jul 02 '23 at 16:16
  • 1
    If you want to use the biblatex solution you need to compile your document with Biber. See https://tex.stackexchange.com/q/63852/35864 for background and https://tex.stackexchange.com/q/154751/35864 for help on getting your editor to run Biber for you. I don't necessarily think biblatex is the best approach here. You don't need all features of bibliographies and citations and the overhead is probably not worth it here. – moewe Jul 02 '23 at 19:08
  • I'm not clear what you're asking for. You don't want custom commands and you want only native LaTeX functionality, but you've rejected the suggestion to use the most suitable native LaTeX functionality. What would an acceptable answer look like, given that \ref{} doesn't do what you'd like it to? – cfr Jul 03 '23 at 00:06
  • This question has been closed (which I don't agree with) but here is an expl3 example of what I had in mind in my previous comment. I don't think biblatex is the right tool for what you want to do. Programming with LaTeX -- Add names and characteristics – Alan Munn Jul 03 '23 at 21:42

1 Answers1

0

I agree with others that a bibtex database probably is not the best way. One alternative that you may explore is put the data in a R data frame, that can be easily integrated with LaTeX text in several ways.

Here a MWE showing only some of these ways:

(note: if you do not have idea of what is R/knitr, save the file as mwe.Rnw to compile it with RStudio, or alternatively save it as mwe.Rtex to compile it on line in Overleaf.)

MWE

\documentclass{article}
\usepackage{booktabs}
\begin{document}

<<data,echo=FALSE,results="asis">>= df <- data.frame( name=c("Negan","Rick Grimes","Maggie Greene"), date = c("1995-05-10","1995-05-13","2005-05-13"), eyecolor = c("brown","blue","green"), rol = c("evil","hero","survivor"), zombies=c(502,834,254) )

row.names(df) <- c("negan","rick","maggie") # nick names

library(xtable) library(knitr) print(xtable(df, caption="Example characters to start walking, but alive."), booktabs=TRUE)

df$date <- as.Date(df$date)

@

I am \Sexpr{df["negan","name"]}. Main characters are \Sexpr{combine_words(df$name)}. \Sexpr{df$name[1]} have
\Sexpr{df$eyecolor[1]} eyes and born in \Sexpr{format(df$date[1], format="%Y")} and he is the \Sexpr{df["negan","rol"]}, whereas \Sexpr{df["rick","name"]} is the
\Sexpr{df["rick","rol"]} of
\Sexpr{df["rick","eyecolor"]} eyes and born only \Sexpr{df$date[2]-df$date[1]} days later. \Sexpr{df["maggie","name"]} was roughly \Sexpr{round((df$date[3]-df$date[2])/365.25,0)} years younger and have
\Sexpr{df[3,3]} eyes. She is a \Sexpr{df["maggie","rol"]} survivor of the zombie apocalypse. Each character kill an average of \Sexpr{round(mean(df$zombies),0)} zombies. \end{document}

Fran
  • 80,769