0

Suppose you want to maintain a set of objects in a central place and render them differently (``views'') at various places in your LaTeX document, similar to glossaries but more generic.

For example, consider you want to setup a small "database" of employees with their first names, last names, identifier, date of birth etc. Then you want to create a list of employees in the introduction section of the document, where only the first names are printed, separated by comma. In the appendix, however, you want to print a table that shows all properties (as columns) and all employees (as rows).

Also, you want to be able to ``pick'' single entries from this database in different formats, similar to \Glspl{employee1}, \gls{employee1}, ...

Of course, one method could be to use e.g. a combination of scripting and sqlite to generate latex code as a preprocessing step.

However, what would be the most straightforward LaTeXish way to do this? Are there any packages that could help here?

Mischa
  • 101
  • 2
    Too abstract. I think the answer would be "learn some TeX programming then the solution would essentially be straightforward", but not much more can be said. – user202729 Jan 03 '23 at 09:26
  • (but TeX is a terrible programming language so easier option includes using e.g. PythonTeX, LuaTeX,PerlTeX etc.) – user202729 Jan 03 '23 at 09:26
  • Have a look at biber - it can do more than just bibliographies. – samcarter_is_at_topanswers.xyz Jan 03 '23 at 09:27
  • 1
    ... or the datatool package – samcarter_is_at_topanswers.xyz Jan 03 '23 at 09:27
  • I agree, this sounds more or less like object-oriented programming, so why not simply use Lua which supports this out of the box? – Gaussler Jan 03 '23 at 09:27
  • 1
    it depends a bit on the numbers. A small set can be done with expl3 properties or datatool (both load all data in memory). With biblatex you can store more entries in an external bib-file. – Ulrike Fischer Jan 03 '23 at 09:32
  • As an example of the datatool approach see https://tex.stackexchange.com/questions/137504/generating-lists-and-tables-of-items-from-commands-in-the-document/137598 which shows most of the features you are asking about I think. – Marijn Jan 03 '23 at 13:58

1 Answers1

0

As said on the comments, to manipulate big amounts of data, there are better programming languages that can be used together with LaTeX. One of this alternatives is knitr (an R package) that allow mix R and LaTeX code.

To test the example below, you should save it with the .Rnw extension and you can compile it with Rstudio,or see How to build Knitr document from the command line. If you have not R in your computer, also in Overleaf you probably test this file, but using the extension.Rtex.

The MWE:


mwe


\documentclass{article}
% preample only to beautify the result, nothing is essential 
\usepackage{parskip}
\usepackage{booktabs}
\usepackage[colorlinks]{hyperref}
\renewcommand\belowcaptionskip{1ex}

\begin{document}

\section*{The raw data for this example}

<<employees,echo=FALSE>>=

construct a data frame (you can also import it csv, excel, csv, ...)

df <- data.frame( Name = c("Bob", "Sam", "Jim"), Surname = c("Wood","Smith","Carter"), Rate = c(94, 4, 3), # Field experience (%) date = as.Date(c('1990-10-02','1981-3-24','1987-6-14')), Position= c("director","subdirector","secretary"))

Nicknames as ID

rownames(df) <- c("nba", "spy", "tv")

today <- as.Date(Sys.Date())

Show raw data

df

@

\section*{About our fake employees}

The team will be our employees \Sexpr{combine_words(paste(df$Name,df$Surname))}.

Although the mean rate experience of the team is only \Sexpr{round(mean(df$Rate),1)};%, but the \Sexpr{df[1,5]} of the project will be \Sexpr{df[1,1]}. Mr. \Sexpr{df["nba",2]} is highly cualified for this specific work (\Sexpr{df["nba","Rate"]};%). He was born in \Sexpr{format(df["nba","date"], format = "%Y")}, so roughly he has now \Sexpr{format(difftime(today, df["nba","date"], unit="days"), big.mark = '\\;')} days of living experience.

\section*{Full team data (to show)}

See in table \ref{Team}:

<<team table,echo=F, results="asis">>= library(xtable)

df$date <- as.character(df$date)
print(xtable(df[,c(1,2,5,4,3)], caption="Full team", label="Team", align="llllcr", digits=0), booktabs=T, include.rownames=F, caption.placement="top" )

@

\end{document}

Fran
  • 80,769