JET
**What I trying to get**
I am willing to centralize information for my chapters in an xls (csv).
![image.png](/image?hash=5ccad04c72fa515fd84a1822aa1393451f36bb6c109781fc9ea6ce5bb9ed1ac5)
**What is my pb ?**
Probably a problem of expansion when I try to include a graphic based on the address stored in my csv.
**Context**
For each chapter (55 of them), I have for instance a mindmap and the final rendering looks like
![image.png](/image?hash=3cbd22f485ff7bc5b7424e5031a6203dbe54d804fe40340d24facf8d8346abc3)
The chapter long title, short title, the address of the mindmap are stored in the csv.
The Orientation Colorbox will be populated by the csv fields
```
\documentclass[landscape]{book}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{geometry}
\geometry{
a4paper,
%total={170mm,257mm},
left=5mm,
right=5mm,
top=5mm,
bottom=5mm,
}
\begin{filecontents*}[overwrite]{ChapInfo.csv}
Index,Chap,short,long,image,objectif
1,01,Enjeux en finance de marché ,Enjeux,F:/NewOrga/TikZ/Mindmap/TikZOut/MMFinancialMarkets0.pdf,"\'Etayer les problématiques fréquemment rencontrées sur les marchés financiers. En comprendre les instruments et leurs relations"
2,02,Buy side ,BuySide,F:/NewOrga/TikZ/Mindmap/TikZOut/MMOrgaClients0.pdf,Problématiques des clients
3,03,Sell Side ,SellSide,F:/NewOrga/_chap/chap60/TikZ/TikZOut/BusinessOrgaSdm1.pdf,Problématiques des fournisseurs
\end{filecontents*}
\usepackage{datatool}
\DTLsetseparator{,}
\DTLloadrawdb{mysource}{ChapInfo.csv}
\newcommand{\myfld}[2][]{\DTLfetch{mysource}{Index}{#2}{#1}}
\begin{document}
\DTLdisplaydb{mysource}
I get to retrieve each field where index = 1
Chap : \myfld[Chap]{1}
short : \myfld[short]{1}
long : \myfld[long]{1}
objectif : \myfld[objectif]{1}
image : \myfld[image]{1}
But when I try :
\includegraphics[width=\textwidth]{\myfld[image]{1}}
it feels like the image address is not understood as such...
\end{document}
```
Top Answer
Skillmon
You're right, you can't access the database expandably because neither your definition of `\myfld` nor `\DTLfetch` are expandable.
Instead you can use a two step approach, first getting the value inside a macro which you can then use to include your image:
```
\documentclass[landscape]{book}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{geometry}
\geometry{
a4paper,
%total={170mm,257mm},
left=5mm,
right=5mm,
top=5mm,
bottom=5mm,
}
\begin{filecontents*}[overwrite]{ChapInfo.csv}
Index,Chap,short,long,image,objectif
1,01,Enjeux en finance de marché ,Enjeux,example-image-a,"\'Etayer les problématiques fréquemment rencontrées sur les marchés financiers. En comprendre les instruments et leurs relations"
2,02,Buy side ,BuySide,example-image-b,Problématiques des clients
3,03,Sell Side ,SellSide,example-image-c,Problématiques des fournisseurs
\end{filecontents*}
\usepackage{datatool}
\DTLsetseparator{,}
\DTLloadrawdb{mysource}{ChapInfo.csv}
\newcommand{\myfld}[2][]{\DTLfetch{mysource}{Index}{#2}{#1}}
\newcommand\myimg[2][]
{%
\DTLgetvalueforkey\myimgTMP{image}{mysource}{Index}{#2}%
\includegraphics[{#1}]{\myimgTMP}%
}
\begin{document}
\noindent
\DTLdisplaydb{mysource}
I get to retrieve each field where index = 1
Chap : \myfld[Chap]{1}
short : \myfld[short]{1}
long : \myfld[long]{1}
objectif : \myfld[objectif]{1}
image : \myfld[image]{1}
But when I try :
\noindent
\myimg[width=\textwidth]{1}
it feels like the image address is not understood as such...
\end{document}
```