我正在写一本小说,我想创建一个数据结构来保存人物属性并能够引用这些值。
我研究过创建自定义词汇表、bibtex 和数据工具结构,但找不到合适的方法。我更愿意不创建自定义命令,而是使用原生 latex 可用功能。
例子
character{emma,
title = {Emma},
dateofbirth = {1995-05-10},
eyecolor = {brown}
}
Emma her eye colour is \ref{emma:eyecolor}.
答案1
我同意其他人的观点,bibtex 数据库可能不是最好的方法。您可以探索的一种替代方法是将数据放入 R 数据框中,这样可以通过多种方式轻松与 LaTeX 文本集成。
这里的 MWE 仅显示了其中的一些方式:
(注意:如果您不知道什么是 R/knitr,请将文件保存为mwe.Rnw
以便用 RStudio 进行编译,或者将其保存为以便 mwe.Rtex
在 Overleaf 中在线进行编译。)
\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}