@B3ret:
You can try the following code. I have thoroughly tested the key definition part, but not the figure inclusion portion of the code. That is left to the user.
\documentclass{article}
\usepackage{graphicx}
\usepackage{lipsum}
\usepackage[strict]{changepage}
\usepackage{xkeyval}
% Note: \setkeys from 'xkeyval' strips up to 3 levels of outer braces.
\makeatletter
\newcommand*\ifcmdempty[1]{%
\@nameuse{@\expandafter\ifx\expandafter\\\@gobble#1.\\%
second\else first\fi oftwo}%
{\@nameuse{@\ifx#1\@empty first\else second\fi oftwo}}%
\@secondoftwo
}
\newcommand\@expandarg[2]{%
\begingroup
\protected@edef\reserved@a{\endgroup\unexpanded{#1}{#2}}\reserved@a
}
\newcommand\@expandargnobrace[2]{%
\begingroup
\protected@edef\reserved@a{\endgroup\unexpanded{#1}#2}\reserved@a
}
\newcommand*\ifpdfstrcmp[2]{%
\@nameuse{@\ifnum\pdfstrcmp{\detokenize{#1}}{\detokenize{#2}}=\z@
first\else second\fi oftwo}%
}
\newcommand*\makecs[1]{\@expandonce{\csname#1\endcsname}}
\newcommand*\putsubfloat[6]{%
\begingroup
\protected@edef\reserved@a{\endgroup
\ifnum#1=\z@\else\noexpand\subfloat[\makecs{mfbdf@#2}][\makecs{mfbdf@#3}]{\fi
\noexpand\includegraphics[width=\makecs{mfbdf@#4}\textwidth]{\unexpanded{#5}}%
\noexpand\label{\makecs{mfbdf@#6}}%
\ifnum#1=\z@\else}\fi
}%
\reserved@a
}
\edef\fullwidth{\the\dimexpr\textwidth+\marginparwidth+\marginparsep}
% \Define@Keys is adapted from the development version of keyreader package.
% The new facilities of keyreader package are more extensive
% than seen here:
\newcommand*\define@keysloop[1]{\@define@keysloop#1,\defkey@nil,}
\def\@define@keysloop#1,{%
\begingroup\edef\reserved@a{\unexpanded{#1}}%
\expandafter\endgroup\ifx\reserved@a\defkey@nnil\else
\define@keysdo{#1}\relax
\expandafter\@define@keysloop
\fi
}
\def\defkey@nnil{\defkey@nil}
\newcommand*\@expandonce[1]{\unexpanded\expandafter{#1}}
\newcommand*\Define@Keys{\@testopt\@define@keys{KV}}
\def\@define@keys[#1]#2{\@testopt{\@@define@keys{#1}{#2}}{mp@}}
\def\@@define@keys#1#2[#3]#4{%
\KV@@sp@def\keyprefix{#1}%
\KV@@sp@def\keyfamily{#2}%
\KV@@sp@def\macroprefix{#3}%
\def\key@vals{}%
\def\define@keys@do##1=##2=##3\defkey@nil{%
\expandafter\ifx\expandafter\\\@gobble##1.\\%
\@latex@error{Empty key name}\@ehc
\fi
\define@keys@@do##1/##2//\defkey@nil
}%
\def\define@keys@@do##1/##2/##3/##4\defkey@nil{%
\KV@@sp@def\keyname{##1}%
\KV@@sp@def\keydefault{##2}%
\edef\key@vals{%
\ifcmdempty\key@vals{}{\@expandonce\key@vals,}%
\@expandonce\keyname=\@expandonce\keydefault
}%
\edef\reserved@a{%
[\keyprefix]{\keyfamily}[\macroprefix]{\keyname}%
[\@expandonce\keydefault]{\unexpanded{##3}}%
}%
\expandafter\ifpdfstrcmp\expandafter{\keydefault}{true}{%
\expandafter\define@boolkey
}{%
\expandafter\ifpdfstrcmp\expandafter{\keydefault}{false}{%
\expandafter\define@boolkey
}{%
\expandafter\define@cmdkey
}%
}%
\reserved@a
}%
\long\def\define@keysdo##1{\define@keys@do##1==\defkey@nil}%
\define@keysloop{#4}%
\edef\reserved@a{%
\noexpand\setkeys[\keyprefix]{\keyfamily}{\@expandonce\key@vals}%
}%
\reserved@a
}
\Define@Keys[KV]{bigfig}[mfbf@]{pos=!htp,label,shortcaption,relsize=0.95,
testbool=true/\ifmfbf@testbool\def\testfunc##1{xx##1xx}\fi}
% Parameters: [key-val pairs]{file}{caption}
\newcommand{\bigfigure}[3][]{%
% Default values:
\setkeys[KV]{bigfig}{pos=!htp,label=fig:#2,
shortcaption={{{#3}}},relsize=0.95}%
% User-provided values:
\ifx\\#1\\\else\setkeys[KV]{bigfig}{#1}\fi
\@expandargnobrace{\begin{figure}}{[\mfbf@pos]}%
\checkoddpage
\@expandargnobrace{\makebox[\textwidth]}{[\ifoddpage l\else r\fi]}{%
\begin{minipage}[t]{\fullwidth}%
\centering
\includegraphics[width=\mfbf@relsize\textwidth]{#2}%
\caption[\mfbf@shortcaption]{#3}%
\label{\mfbf@label}%
\end{minipage}%
}%
\end{figure}%
}
\Define@Keys[KV]{bigdblfig}[mfbdf@]{pos=!htp,mainrelsize=0.95,
mainlabel=fig:mainlabel,maincaption,mainshortcaption,
leftrelsize=0.45,leftlabel=fig:leftlabel,leftcaption,
leftshortcaption,rightrelsize=0.45,rightlabel=fig:rightlabel,
rightcaption,rightshortcaption
}
% [key-value pairs]{file-left}{file-right}
\newcommand{\bigdoublefigure}[3][]{%
% The keyreader package avoids this type of repetition:
\setkeys[KV]{bigdblfig}{pos=!htp,mainrelsize=0.95,
mainlabel={fig:#2-#3},maincaption=,mainshortcaption=,
leftrelsize=0.45,leftlabel={fig:#2-left},leftcaption=,
leftshortcaption=,rightrelsize=0.45,rightlabel={fig:#2-right},
rightcaption=,rightshortcaption=
}%
\ifx\\#1\\\else\setkeys[KV]{bigdblfig}{#1}\fi
\@expandargnobrace{\begin{figure}}{[\mfbdf@pos]}%
\checkoddpage
\@expandargnobrace{\makebox[\textwidth]}{[\ifoddpage l\else r\fi]}{%
\begin{minipage}{\mfbdf@mainrelsize\fullwidth}%
\centering
\ifcmdempty\mfbdf@leftcaption{%
\putsubfloat\z@{}{}{leftrelsize}{#2}{leftlabel}%
}{%
\ifcmdempty\mfbdf@leftshortcaption{%
\putsubfloat\@ne{leftcaption}{leftcaption}{leftrelsize}{#2}{leftlabel}%
}{%
\putsubfloat\@ne{leftshortcaption}{leftcaption}{leftrelsize}{#2}{leftlabel}%
}%
}%
\hfill
\ifcmdempty\mfbdf@rightcaption{%
\putsubfloat\z@{}{}{rightrelsize}{#3}{rightlabel}%
}{%
\ifcmdempty\mfbdf@rightshortcaption{%
\putsubfloat\@ne{rightcaption}{rightcaption}{rightrelsize}{#3}{rightlabel}%
}{%
\putsubfloat\@ne{rightshortcaption}{rightcaption}{rightrelsize}{#3}{rightlabel}%
}%
}%
\ifcmdempty\mfbdf@maincaption{}{%
\ifcmdempty\mfbdf@mainshortcaption{%
\caption[\mfbdf@maincaption]{\mfbdf@maincaption}%
}{%
\caption[\mfbdf@mainshortcaption]{\mfbdf@maincaption}%
}%
}%
\label{\mfbdf@mainlabel}%
\end{minipage}
}%
\end{figure}
}
\makeatother
\begin{document}
\lipsum[1-2]
\end{document}
\ifodd\c@pagebefore, which is wrong at the beginning of a page. I knew the trick to make a cross-reference for every\if, but I didn't implement it yet. Now I needn't do it myself. – Leo Liu Feb 07 '11 at 20:11strictto the package or put\strictpagecheckbefore the\checkoddpage. – Konrad Rudolph Feb 07 '11 at 20:39ifoddpageis always strict and will work after the two usual compiler runs. In the first run the "current" page number is used instead which can be off. I agree that thechangepageshould be loaded withstrict, and my example reflects this (see the commented-out line). However, at the time of Konrads comment the answer didn't included neitherifoddpagenor thestrictoption. – Martin Scharrer Jan 07 '13 at 16:03ifoddpageis great, but it does not work when figure is on the top of the page. It seems thatifoddpagedoes not correctly conclude the side of the book. Any ideas how to solve that? – Pygmalion Oct 19 '13 at 17:44ifoddpage, but requires at least two compiler runs, sometimes more in bigger documents. If you then still have a problem please try to create a minimal working document for this behaviour and send it to me. My email address is stated in theifoddpagemanual (I'm the author). – Martin Scharrer Oct 20 '13 at 17:40\ifthispageodd, and it works perfectly. Thank you for your concern. – Pygmalion Oct 20 '13 at 18:18\ifthispageodddoes not work properly. I am sending you MWE. Thanks. – Pygmalion Oct 26 '13 at 10:04