\ProvidesPackage{customenv}

\usepackage{xargs}

% Three versions of centeredfigure environment are defined below. 
% Make it sure that only one of them is activated.

%\newenvironment{centeredfigure}	
%	{
%		\begin{figure}
%		 \centering
%	}
%	{	
%		\end{figure}
%	}

%\newenvironment{centeredfigure}[1]	
%	{
%		\begin{figure}[#1]
%		\centering
%	}
%	{
%		\end{figure}
%	}

\newenvironmentx{centeredfigure}[1][1=]	
	{
		 %
		 \ifx #1\empty 
		 % without an optional argument
		 \begin{figure}	 
		 %
		 \else 
		 % with an optional argument
		 \begin{figure}[#1]
		 %
		 \fi
		 %
		 \centering
	}
	{
		\end{figure}
	}

\newsavebox{\subfigurebox}
\newenvironmentx{framedsubfigure}[2][1=]
	{
		 \begin{lrbox}{\subfigurebox}
			 %
			 \ifx #1\empty 
			 % without an optional argument
			 \begin{subfigure}{#2}
			 %
			 \else 
			 % with an optional argument
			 \begin{subfigure}[#1]{#2}
			 \fi
			 %
			 \centering
	}
	{ 
			 \end{subfigure}
		 \end{lrbox}	 
		 %
		 \fbox{
		 	\usebox{\subfigurebox}
		}
	}
