# Trouble including graphics from csv file into Pgftable, commands are dissapearing (local maybe?)

I've been trying to add eps graphics with the filename in a csv file. Take a look at the CSV to get an idea of what I mean: https://docs.google.com/spreadsheet/ccc?key=0Ao9if7HTdeaPdGowdXJXbURJQWVmVTdDUVRaYTdldXc#gid=0

So far, I've managed to get LaTeX to spit out this much:

I'm trying to place figures (with compound eps and name) for each compound in the Reagent column. So far I've created a new column in Pgfplotstable and I'm trying to include values from the name and structure column of my csv file.

I'm pretty confused at this point, so I started trying to create a new command for every image which I would later call in the figure (\cmpi->compound 1 name, \structurei->compound 1 structure, \cmpii->compound 2 name, \structureii->compound 2 structure). I can't get that set up because the commands are lost after another call to defineCompound. There is probably a better way to create the in-table figures, but I am lost at this point.

The first \typeout{TESTING: \cmpi, \structurei} works and prints TESTING: (R)-(-)carvone, ../chemicals/(r)-(-)-carvone.eps, but the second fails due to "Undefined control sequence"

Any help at this point would be appreciated. I've just started using LaTeX and it's been a pretty rough journey so far.

I'm hoping to finally be able to have all of my compounds in one csv file and just be able to select which ones I would like based on which experiment I'm performing.

My LaTeX is:

\documentclass[pdftex,12pt,a4paper]{article}
\usepackage{enumitem}
\usepackage[left=.75in,right=.75in,top=.75in,bottom=1in]{geometry}
\usepackage{textcomp}
\usepackage{pgfplotstable}
\usepackage{graphicx}
\usepackage{siunitx}
\usepackage{tabularx}
\usepackage{epstopdf}
\usepackage{longtable}
\usepackage{booktabs}
\usepackage{colortbl}
\usepackage{fp}
\usepackage[runs=2]{auto-pst-pdf}
\usepackage[journal=rsc]{chemstyle}

\newlist{steps}{enumerate}{1}
\setlist[steps,1]{
label={Step~\arabic*},
leftmargin=*,
align=left,
labelsep=10mm,
}

\setcounter{secnumdepth}{0}

\newcommand\defineCompound[3]{%
\typeout{#1}
\typeout{#2}
\typeout{#3}
\global\expandafter\newcommand\csname cmp#1\endcsname{#2}
\global\expandafter\newcommand\csname structure#1\endcsname{#3}
\typeout{TESTING: \cmpi, \structurei}
}

\begin{document}
\makeatletter
\section{Introduction}
\newcommand{\expnum}{14}
\newcommand{\exptitle}{Conversion of Carvone to Carvacrol: Multiweek Experiment Part 1}
\input{../common/intro.tex}

\begin{figure}[h!]
\caption{Conversion of (R)-(-)Carvone to Carvacrol by Sulfuric Acid and Heat.}
\centering
\includegraphics[width=\textwidth]{../reactions/(r)-(-)-carvone-to-carvacrol.eps}
\end{figure}
\begin{figure}[h!]
\caption{Balanced Equation.}
\centering
\includegraphics[width=\textwidth]{../reactions/2.eps}
\end{figure}
\newpage
\section{Table of Reagents}
\begin{center}
\pgfplotstablecreatecol[
create col/assign/.code={%
\getthisrow{name}\name
\getthisrow{structure}\structure
\FPeval{\result}{clip(\pgfplotstablerow + 1)}
\edef\entry{\romannumeral\result}
\defineCompound{\entry}{\name}{\structure}
\pgfkeyslet{/pgfplots/table/create col/next content}\entry
\pgfplotstabletypeset[
string type,
begin table=\begin{tabularx}{\textwidth},
end table=\end{tabularx},
columns={reagent,mw,bp,mp,density},
%columns/name/.style={column name=Name, column type={|c}},
columns/reagent/.style={
column name=Reagent,
column type={l},
postproc cell content/.code={
\message{\pgfkeysvalueof{/pgfplots/table/@cell content}}
\message{\cmpi}
%\pgfkeyssetvalue{/pgfplots/table/@cell content}{}%
},
},
columns/mw/.style={column name={Molecular Weight (\si[per-mode=symbol]{\gram\per\mol})}, column type={X}},
columns/bp/.style={column name=Boiling Point (\si{\celsius}), column type={l}},
columns/mp/.style={column name=Melting Point (\si{\celsius}), column type={l}},
columns/density/.style={column name=Density (g/mol), column type={X}},
every nth row={1}{before row=\midrule},
every last row/.style={after row=\bottomrule},
\end{center}

\end{document}

• Welcome at tex.sx. If you are doing first steps with LaTeX -- are you sure that this is good first use-case? It sounds to be highly advanced to me... – Christian Feuersänger Feb 12 '14 at 21:29
• I'm pretty sure I've blown up a simple use to a really complex one. I'm going to try to simplify the problem so I can attack it a little easier. – James Kraus Feb 13 '14 at 22:16

I hope that I am answering the right question here... from what I understand you have a column of sorts "filename" and instead of just typesetting the file name, you want to include the associated graphics file by means of \includegraphics, right? If this assumption is wrong, I'd ask you to clean up your example and rephrase the question accordingly.

If my understanding is correct, then the following might prove helpful:

\documentclass{standalone}
\usepackage{pgfplotstable}
\usepackage{graphicx}

\begin{document}
filename X
PP-figure0.pdf 1
PP-figure1.pdf 2
PP-figure2.pdf 3

\pgfplotstabletypeset[
columns/filename/.style={
column name=Reagent,
column type={l},
assign cell content/.code={%
\pgfkeyssetvalue{/pgfplots/table/@cell content}{\includegraphics{##1}}%
},
},

\end{document}


I have generated a small minimal example on my own. It uses assign cell content since this step is not a preprocessing step; it is the step as such.

It might benefit from some vertical alignment, but before I (or someone else) jumps onto it, you should clarify if this is what you wanted.

For the records: I generated the graphics files using pdflatex -shell-escape PP on the following file

\documentclass[a4paper]{article}

\usepackage{tikz}
\usetikzlibrary{external}
\tikzexternalize

\begin{document}

\tikz \draw[left color=red, right color=white] (0,0) circle (10pt);
\tikz \draw[left color=blue, right color=white] (0,0) circle (10pt);
\tikz \draw[left color=black, right color=white] (0,0) circle (10pt);
\end{document}

• Thanks for the reply! Include graphics works right up until I need to add the name of the compound below the graphic in the table. I can't figure out how to access the name of the compound and include the graphics in the same cell, which is why my example is getting overly complex. – James Kraus Feb 13 '14 at 22:08
• Ah, I see. Could you modify your example such that it compiles out-of-the box (in particular, includes the table + its column names) with as few dependencies as possible? – Christian Feuersänger Feb 14 '14 at 9:36