An error message such as
Argument of \@caption has an extra }
usually means that a command in the argument of \caption
needs protection. In this case the command is surely \MSE
. Thus
\caption{A caption \protect\MSE{img1(illusion)}{\BilineaireA}}
might solve the problem.
However, in this particular application \protect
is not sufficient. We need something that contains the value we need, so a different road can be taken. Define a similar \MSEset
macro, that takes also an optional argument (default value \MSEresult
:
\begin{filecontents*}{data.csv}
Images,Infos,Bayer,BilineaireA,BilineaireB,TeinteA,TeinteB,ContourA,ContourB,Forme
img1(illusion),Temps (en ms),0,4,5,7,6,6,7,442
img1(illusion),Erreur MSE,152.44,34.44,34.44,24.04,24.04,24.06,25.99,32.90
img1(illusion),Erreur DeltaE,17.70,4.92,4.92,4.58,4.58,4.39,4.30,5.24
img1(illusion),Erreur PSNR (en dB),26.30,32.76,32.76,34.32,34.32,34.32,33.98,32.96
\end{filecontents*}
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{csvsimple}
\newcommand{\MSE}[2]{%
\csvreader[ head to column names,%
before filter=\ifthenelse{ \equal{\Images}{#1} }{%
\ifthenelse{ \equal{\Infos}{Erreur MSE} }{\csvfilteraccept}{\csvfilterreject}%
}{\csvfilterreject}]%
{data.csv}{}{#2}%
}
\newcommand{\MSEset}[3][\MSEresult]{%
\csvreader[ head to column names,%
before filter=\ifthenelse{ \equal{\Images}{#2} }{%
\ifthenelse{ \equal{\Infos}{Erreur MSE} }{\csvfilteraccept}{\csvfilterreject}%
}{\csvfilterreject}]%
{data.csv}{}{\xdef#1{#3}}%
}
\newbox{\remibox}
\begin{document}
\listoffigures
\begin{figure}
\centering
My Image
\MSEset{img1(illusion)}{\BilineaireA}
\caption{A caption \MSEresult}
\end{figure}
\end{document}
You set the macro before typing the \caption
and use \result
to stand for the value. You can also say
\MSEset[\MSEresultA]{img1(illusion)}{\BilineaireA}
or any control sequence you want if you need more than one of these numbers. Take care of using control sequence names that are not used elsewhere (a common prefix such as MSE
should do).
This will print the correct value also in the List of Figures, should you need it.
I just ran into the same issue. (It's really annoying when trying to produce print-quality preprint versions of the paper.) Poking around in pnastwo.cls, I found the following fix:
Find the first line in pnastwo.cls which says
\ifx\@captype\xtable
Change this to
\ifx\@captype\table
Alternatively, if you don't want to touch the class file, you can
put the following into the preamble of your document:
% Fix wierd behavior which prevents table captions from appearing for
% tables in the body of the article
\makeatletter
\long\def\@makecaption#1#2{%
\ifx\@captype\table
\let\currtabcaption\relax
\gdef\currtabcaption{
\tabnumfont\relax #1. \tabtextfont\relax#2\par
\vskip\belowcaptionskip
}
\else
\vskip\abovecaptionskip
\sbox\@tempboxa{\fignumfont#1.\figtextfont\hskip.5em\relax #2}%
\ifdim \wd\@tempboxa >\hsize
\fignumfont\relax #1.\figtextfont\hskip.5em\relax#2\par
\else
\global \@minipagefalse
\hb@xt@\hsize{\hfil\box\@tempboxa\hfil}%
\fi
\fi
}
\makeatother
One additional comment: once this bug is fixed, you'll almost certainly run into another issue which you'd want fixed if you use the PNAS two-column class to produce production-quality output: Unless you define floats with the h "here" placement, it loses the labels, so all cross-referencing of figures and tables breaks. Here is the fix, for direct pasting into the document preamble. You can also patch up the macro \DonormalEndcol pnastwo.cls, it's the same mistake 6 times over...
% And another fix. PNAS class loses the label of floats unless they
% were defined with the [h] option (so not really floats at all). It
% all comes down to wrong scope in the following routine which pushes
% out the floats onto the page. This is the fixed version:
\makeatletter
\def\DonormalEndcol{%
%% top float ==>
\ifx\toporbotfloat\xtopfloat%
%% figure ==>
\ifcaptypefig%
\expandafter\gdef\csname topfloat\the\figandtabnumber\endcsname{%
\vbox{\vskip\PushOneColTopFig%
\unvbox\csname figandtabbox\the\loopnum\endcsname%
\vskip\abovefigcaptionskip%
\csname caption\the\loopnum\endcsname%
\csname letteredcaption\the\loopnum\endcsname%
\csname continuedcaption\the\loopnum\endcsname%
\csname letteredcontcaption\the\loopnum\endcsname
\ifredefining%
\csname label\the\loopnum\endcsname%
\expandafter\gdef\csname topfloat\the\loopnum\endcsname{}\fi}%
\vskip\intextfloatskip%%
\vskip-4pt %% probably an artifact of topskip??
}%
\else%
%% plate ==>
\ifcaptypeplate%
\expandafter\gdef\csname topfloat\the\figandtabnumber\endcsname{%
\vbox{\vskip\PushOneColTopFig%
\unvbox\csname figandtabbox\the\loopnum\endcsname
\vskip\abovefigcaptionskip
\csname caption\the\loopnum\endcsname
\csname letteredcaption\the\loopnum\endcsname
\csname continuedcaption\the\loopnum\endcsname
\csname letteredcontcaption\the\loopnum\endcsname
\ifredefining
\csname label\the\loopnum\endcsname
\expandafter\gdef\csname topfloat\the\loopnum\endcsname{}\fi}
\vskip\intextfloatskip %%
\vskip-4pt %% probably an artifact of topskip??
}%
\else% table ==>
\expandafter\gdef\csname topfloat\the\figandtabnumber\endcsname{%
\vbox{\vskip\PushOneColTopTab %%
\csname caption\the\loopnum\endcsname
\csname letteredcaption\the\loopnum\endcsname
\csname continuedcaption\the\loopnum\endcsname
\csname letteredcontcaption\the\loopnum\endcsname
\vskip\captionskip
\unvbox\csname figandtabbox\the\loopnum\endcsname
\ifredefining
\csname label\the\loopnum\endcsname
\expandafter\gdef\csname topfloat\the\loopnum\endcsname{}\fi
}\vskip\intextfloatskip %% why don't we need this?
\vskip-10pt}
\fi\fi%
%
\else% bottom float
%
\ifcaptypefig
\expandafter\gdef\csname botfloat\the\figandtabnumber\endcsname{%
\vskip\intextfloatskip
\vbox{\unvbox\csname figandtabbox\the\loopnum\endcsname
\vskip\abovefigcaptionskip
\csname caption\the\loopnum\endcsname
\csname letteredcaption\the\loopnum\endcsname%
\csname continuedcaption\the\loopnum\endcsname%
\csname letteredcontcaption\the\loopnum\endcsname%
\vskip\PushOneColBotFig%%
\ifredefining%
\csname label\the\loopnum\endcsname
\expandafter\gdef\csname botfloat\the\loopnum\endcsname{}\fi}}%
\else
\ifcaptypeplate
\expandafter\gdef\csname botfloat\the\figandtabnumber\endcsname{%
\vskip\intextfloatskip
\vbox{\unvbox\csname figandtabbox\the\loopnum\endcsname
\vskip\abovefigcaptionskip
\csname caption\the\loopnum\endcsname
\csname letteredcaption\the\loopnum\endcsname%
\csname continuedcaption\the\loopnum\endcsname%
\csname letteredcontcaption\the\loopnum\endcsname%
\vskip\PushOneColBotFig%%
\ifredefining%
\csname label\the\loopnum\endcsname
\expandafter\gdef\csname botfloat\the\loopnum\endcsname{}\fi}}%
\else% TABLE
\expandafter\gdef\csname botfloat\the\figandtabnumber\endcsname{%
\vskip\intextfloatskip
\vbox{\csname caption\the\loopnum\endcsname
\csname letteredcaption\the\loopnum\endcsname
\csname continuedcaption\the\loopnum\endcsname
\csname letteredcontcaption\the\loopnum\endcsname%
\vskip.5\intextfloatskip
\unvbox\csname figandtabbox\the\loopnum\endcsname%
\vskip\PushOneColBotTab
\ifredefining%
\csname label\the\loopnum\endcsname
\expandafter\gdef\csname botfloat\the\loopnum\endcsname{}\fi}}%
\fi\fi\fi}
\makeatother
Best Answer
This is a problem with fragile commands. See What is the difference between Fragile and Robust commands?
With e-tex compatible compiler you may use
\newrobustcmd
frometoolbox
:Without it you may use
\DeclareRobustCommand
the result is: