the following example compiles assumed that the caption command is
commented out. With the caption command I have to write
\newcommand*{\Subref[1]}{\@ifstar{\@Subrefstar}{\@Subrefnostar}}
Is this the right syntax? The "[1]" inside the curly bracket?
Alex
--
\documentclass{scrbook}
\usepackage{floatrow,caption,hyperref,subcaption}
\usepackage[demo]{graphicx}
\DeclareCaptionSubType[alph]{figure}
\captionsetup{labelfont=bf,textformat=period}
\captionsetup[subfigure]{textformat=simple}
% Subref command - set subcaptions in parentheses
\makeatletter
\newcommand*{\Subref}[1]{\@ifstar{\@Subrefstar}{\@Subrefnostar}}
\newcommand*{\@Subrefstar}[1]{(\subref*{#1})}
\newcommand*{\@Subrefnostar}[1]{\hyperref[{#1}]{(\subref*{#1})}}
\makeatother
\begin{document}
\begin{figure}
\ffigbox{%
\begin{subfloatrow}
\ffigbox{\caption{}\label{img:1}}%
{\includegraphics[width=0.4\textwidth]{my1test}}%
\ffigbox{\caption{}\label{img:2}}%
{\includegraphics[width=0.4\textwidth]{mytest2}}%
\end{subfloatrow}
}{%
%\caption{\Subref*{img:1} my first picture, b) my second picture}%
\label{img:allpictures}%
}
\end{figure}
\Subref*{img:1}.
\end{document}
--
//
// Dipl.-Inform. Alexander Zimmermann
// Department of Computer Science, Informatik 4
// RWTH Aachen University
// Ahornstr. 55, 52056 Aachen, Germany
// phone: (49-241) 80-21468, fax: (49-241) 80-22220
// email: zimme...@cs.rwth-aachen.de
// web: http://www.umic-mesh.net
//
> Hi all,
>
> the following example compiles assumed that the caption command is
> commented out. With the caption command I have to write
>
> \newcommand*{\Subref[1]}{\@ifstar{\@Subrefstar}{\@Subrefnostar}}
>
> Is this the right syntax? The "[1]" inside the curly bracket?
No, it isn't. In general, the "[1]" goes /outside/ the braces:
\newcommand{\foo}[1]{...something with #1...}
But in this particular case, you actually want to define
a command /without/ arguments. So
\newcommand{\Subref}{\@ifstar{\@Subrefstar}{\@Subrefnostar}}
It will be a job for one of the two commands to collect the
argument:
\makeatletter
\newcommand*{\Subref}{\@ifstar{\@Subrefstar}{\@Subrefnostar}}
\newcommand*{\@Subrefstar}[1]{(\subref*{#1})}
\newcommand*{\@Subrefnostar}[1]{\hyperref[{#1}]{(\subref*{#1})}}
\makeatother
Ciao
Enrico
This doesn't compile...
./floatrow.tex:37: Argument of \@caption has an extra }.
<inserted text>
\par
l.37 }
> This doesn't compile...
>
> ./floatrow.tex:37: Argument of \@caption has an extra }.
> <inserted text>
> \par
> l.37 }
I took you example file, did the suggested modification and it
compiles fine. Please provide an example.
Ciao
Enrico
\usepackage{floatrow,caption,hyperref,subcaption}
\usepackage[demo]{graphicx}
\DeclareCaptionSubType[alph]{figure}
\captionsetup{labelfont=bf,textformat=period}
\captionsetup[subfigure]{textformat=simple}
\makeatletter
\newcommand*{\Subref}{\@ifstar{\@Subrefstar}{\@Subrefnostar}}
\newcommand*{\@Subrefstar}[1]{(\subref*{#1})}
\newcommand*{\@Subrefnostar}[1]{\hyperref[{#1}]{(\subref*{#1})}}
\makeatother
\begin{document}
\begin{figure}
\ffigbox{%
\begin{subfloatrow}
\ffigbox{\caption{}\label{img:1}}%
{\includegraphics[width=0.4\textwidth]{my1test}}%
\ffigbox{\caption{}\label{img:2}}%
{\includegraphics[width=0.4\textwidth]{mytest2}}%
\end{subfloatrow}
}{%
\caption{\Subref*{img:1} my first picture, b) my second picture}%
\label{img:allpictures}%
}
\end{figure}
\Subref*{img:1}.
\end{document}
--
*File List*
scrbook.cls 2010/02/15 v3.05 KOMA-Script document class (book)
scrkbase.sty 2010/02/15 v3.05 KOMA-Script package
(KOMA-Script-dependent bas
ics and keyval usage)
scrbase.sty 2010/02/15 v3.05 KOMA-Script package
(KOMA-Script-independent b
asics and keyval usage)
keyval.sty 1999/03/16 v1.13 key=value parser (DPC)
scrlfile.sty 2009/03/25 v3.03 KOMA-Script package (loading files)
tocbasic.sty 2010/01/05 v3.04b KOMA-Script package (handling toc-files)
scrsize11pt.clo 2010/02/15 v3.05 KOMA-Script font size class option
(11pt)
typearea.sty 2010/02/15 v3.05 KOMA-Script package (type area)
floatrow.sty 2008/08/02 v0.3b floatrow: float package extension
caption3.sty 2010/01/14 v3.1m caption3 kernel (AR)
caption.sty 2010/01/09 v3.1m Customizing captions (AR)
hyperref.sty 2010/04/17 v6.80x Hypertext links for LaTeX
ltxcmds.sty 2010/04/16 v1.6 LaTeX kernel commands for general use (HO)
kvsetkeys.sty 2010/03/01 v1.9 Key value parser (HO)
infwarerr.sty 2010/04/08 v1.3 Providing info/warning/message (HO)
etexcmds.sty 2010/01/28 v1.3 Prefix for e-TeX command names (HO)
pdfescape.sty 2010/03/01 v1.9 Provides hex, PDF name and string
conversions
(HO)
pdftexcmds.sty 2010/04/01 v0.9 Utility functions of pdfTeX for LuaTeX
(HO)
ifluatex.sty 2010/03/01 v1.3 Provides the ifluatex switch (HO)
ifpdf.sty 2010/01/28 v2.1 Provides the ifpdf switch (HO)
ifvtex.sty 2010/03/01 v1.5 Switches for detecting VTeX and its
modes (HO)
ifxetex.sty 2009/01/23 v0.5 Provides ifxetex conditional
hycolor.sty 2009/12/12 v1.6 Color options of hyperref/bookmark (HO)
xcolor-patch.sty 2009/12/12 xcolor patch
letltxmacro.sty 2008/06/24 v1.3 Let assignment for LaTeX macros (HO)
pd1enc.def 2010/04/17 v6.80x Hyperref: PDFDocEncoding definition (HO)
intcalc.sty 2007/09/27 v1.1 Expandable integer calculations (HO)
hyperref.cfg 2002/06/06 v1.2 hyperref configuration of TeXLive
kvoptions.sty 2010/02/22 v3.7 Keyval support for LaTeX options (HO)
url.sty 2006/04/12 ver 3.3 Verb mode for urls, etc.
bitset.sty 2007/09/28 v1.0 Data type bit set (HO)
bigintcalc.sty 2007/11/11 v1.1 Expandable big integer calculations (HO)
atbegshi.sty 2010/03/25 v1.12 At begin shipout hook (HO)
hpdftex.def 2010/04/17 v6.80x Hyperref driver for pdfTeX
atveryend.sty 2010/03/24 v1.5 Hooks at very end of document (HO)
rerunfilecheck.sty 2010/03/16 v1.6 Rerun checks for auxiliary files (HO)
uniquecounter.sty 2009/12/18 v1.1 Provides unlimited unique counter (HO)
subcaption.sty 2008/08/31 v1.0b Adding subcaptions (AR)
graphicx.sty 1999/02/16 v1.0f Enhanced LaTeX Graphics (DPC,SPQR)
graphics.sty 2009/02/05 v1.0o Standard LaTeX Graphics (DPC,SPQR)
trig.sty 1999/03/16 v1.09 sin cos tan (DPC)
graphics.cfg 2009/08/28 v1.8 graphics configuration of TeX Live
pdftex.def 2010/02/14 v0.04n Graphics/color for pdfTeX
color.sty 2005/11/14 v1.0j Standard LaTeX Color (DPC)
color.cfg 2007/01/18 v1.5 color configuration of teTeX/TeXLive
nameref.sty 2010/04/17 v2.39 Cross-referencing by name of section
refcount.sty 2008/08/11 v3.1 Data extraction from references (HO)
gettitlestring.sty 2009/12/18 v1.3 Cleanup title references (HO)
floatrow.out
floatrow.out
supp-pdf.mkii
***********
> ...
> \caption{\Subref*{img:1} my first picture, b) my second picture}%
> \label{img:allpictures}%
> ...
Of course \Subref is fragile. Either define it with
\DeclareRobustCommand instead of \newcommand or use
\protect in front of it in moving arguments.
Ciao
Enrico
> \makeatletter
> \newcommand*{\Subref}{\@ifstar{\@Subrefstar}{\@Subrefnostar}}
> \newcommand*{\@Subrefstar}[1]{(\subref*{#1})}
> \newcommand*{\@Subrefnostar}[1]{\hyperref[{#1}]{(\subref*{#1})}}
> \makeatother
> \caption{\Subref*{img:1} my first picture, b) my second picture}%
\Subref is fragile and gets broken inside the moving argument
of \caption.
* Use \protect:
\caption{\protect\Subref*{img:1}}
* Or make \Subref robust:
\@ifdefinable{\Subref}{%
\DeclareRobustCommand*{\Subref}{%
\@ifstar\@Subrefstar\@Subrefnostar
}%
}
(\DeclareRobustCommand overwrites a previous \Subref
without warning or error, therefore it is wrapped in \@ifdefinable.)
--
Heiko Oberdiek
A radical alternative would be to use xparse:
\usepackage{xparse}
\DeclareDocumentCommand\Subref{sm}{%
% #1 is a flag for the presence of a star
% #2 is the mandatory argument
\IfBooleanTF#1
{\subref*{#2}}
{\hyperref[{#2}]{(\subref*{#2})}}%
}
This will make a naturally-robust \Subref macro.
--
Joseph Wright