I'm back and I found a partial solution to my problem.
Please keep in mind that I am almost a complete beginner so I'm experimenting. ^^'
(I'm using Overleaf to write my code because I tried on RStudio but the datatool package was apparently not available for R version 3.5.1)
So to simplify, this is the pattern I used:
% Load CSV database (here database.csv)
% and give it a label (here DB)
\DTLloaddb{DB}{database.csv}
%%%%%%%%%%%%%%%%
% Iteration
% Here in the D column I can have d1, d2, etc.
% but I only want to display the result for the rows with d1:
\DTLforeach*[\DTLiseq{\D}{d1}] % Condition
{DB} % Database label
{\A=A,\B=B,\C=C,\D=D,\E=E} % Assignment
{% Stuff to do at each iteration:
\item[]
\textbf{\A}
\textbf{ \B}
\textit{ \C}
(\E)
}
%%%%%%%%%%%%%%%%
In my particular situation, I am doing a wine list/menu (Carte des Vins) and eventually I want to:
1) sort them by wine (Bordeaux / Burgundy / Port / Rest of the World)
For now I'm using a csv file with only the Bordeaux wines (bordeaux.csv) but ultimately I would like to use a file with all the wines on it (wine.csv)
2) sort them by type (Red / White / Sweet white)
As you will see below, I managed to do that, but maybe there is a better way to do the same thing.
3) format the text as follows:
Vintage Name, Classification (Origin)
ex: 2009 Château Grand Village, Bordeaux Supérieur (Bordeaux)
The only thing that I have trouble with is the comma, because when the Classification column is empty I don't want to get "Vintage Name," with a useless comma... So for now I left the text without a comma.
So this is my whole code:
\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
% Pour modifer les marges
\usepackage{geometry}
% Marges du document
\geometry{hmargin=2.5cm,vmargin=1.5cm}
% To remove the heading of the table of contents ("Contents")
\makeatletter
\renewcommand\tableofcontents{%
\@starttoc{toc}%
}
\makeatother
% To make itemized lists
% This package provides user control over the layout of the three basic list
% environments: enumerate, itemize and description. It supersedes both enumerate
% and mdwlist (providing well-structured replacements for all their funtionality),
% and in addition provides functions to compute the layout of labels, and to
% ‘clone’ the standard environments, to create new environments with counters of
% their own.
\usepackage{enumitem}
% Datatool package to load external files (cdv)
\usepackage{datatool}
\Huge\title{Carte des Vins}
\author{Buck's}
\date{September 2018}
\begin{document}
\maketitle
\tableofcontents
%--------------------------%
\newpage
\section{Bordeaux}
% Load CSV database and give it a name
\DTLloaddb{BOR}{bordeaux.csv}
\subsection{Red}
%%%%%%%%%%%%%%%%
% Iteration
\DTLforeach*[\DTLiseq{\Type}{Red}] % Condition
{BOR} % Database label
{\Vintage=Vintage,\Name=Name,\Classification=Classification,\Type=Type,\Origin=Origin} % Assignment
{% Stuff to do at each iteration:
\item[]
\textbf{\Vintage}
\textbf{ \Name}
\textit{ \Classification}
(\Origin)
}
%%%%%%%%%%%%%%%%
\subsection{White}
%%%%%%%%%%%%%%%%
% Iteration
\DTLforeach*[\DTLiseq{\Type}{White}] % Condition
{BOR} % Database label
{\Vintage=Vintage,\Name=Name,\Classification=Classification,\Type=Type,\Origin=Origin} % Assignment
{% Stuff to do at each iteration:
\item[]
\textbf{\Vintage}
\textbf{ \Name}
\textit{ \Classification}
(\Origin)
}
%%%%%%%%%%%%%%%%
\subsection{Sweet White}
%%%%%%%%%%%%%%%%
% Iteration
\DTLforeach*[\DTLiseq{\Type}{Sweet white}] % Condition
{BOR} % Database label
{\Vintage=Vintage,\Name=Name,\Classification=Classification,\Type=Type,\Origin=Origin} % Assignment
{% Stuff to do at each iteration:
\item[]
\textbf{\Vintage}
\textbf{ \Name}
\textit{ \Classification}
(\Origin)
}
%%%%%%%%%%%%%%%%
%--------------------------%
\newpage
\section{Burgundy}
\subsection{Red}
\subsection{White}
%--------------------------%
\newpage
\section{Rest of the World}
%--------------------------%
\newpage
\section{Port}
%--------------------------------
\end{document}
And this is what I managed to get so far (this is the beginning of my section "Bordeaux" and of my subsection "Red"):
datatool
package has the most flexibility, and might be most appropriate; other tools likecsvsimple
andpgfplotstable
have more limited functionality and may or may not serve your needs. There are plenty of related questions on the site about these packages. If you're importing the data as a one-time thing, thenexcel2latex
might be appropriate.xtable
.datatooltk
as in this example.