% \iffalse meta-comment
%
% Copyright (C) 2014 by Jos�� Romildo Malaquias <malaquias@gmail.com>
% ---------------------------------------------------------------------------
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
% of this license or (at your option) any later version.
% The latest version of this license is in
%   http://www.latex-project.org/lppl.txt
% and version 1.3 or later is part of all distributions of LaTeX
% version 2005/12/01 or later.
%
% This work has the LPPL maintenance status `maintained'.
%
% The Current Maintainer of this work is Jos�� Romildo Malaquias.
%
% This work consists of the files efbox.dtx and efbox.ins
% and the derived filebase efbox.sty.
%
% \fi
%
% \iffalse
%<*driver>
\ProvidesFile{efbox.dtx}
%</driver>
%<package>\NeedsTeXFormat{LaTeX2e}[1999/12/01]
%<package>\ProvidesPackage{efbox}
%<*package>
    [2014/03/19 1.0 An enhanced fbox command.]
%</package>
%
%<*driver>
\documentclass{ltxdoc}
\usepackage{efbox}[2014/03/19]
\usepackage[utf8]{inputenc}
\usepackage{xcolor}
\usepackage[final]{showexpl}
\EnableCrossrefs
\CodelineIndex
\RecordChanges
\lstset{%
  language=[LaTeX]TeX,
  basicstyle=\ttfamily\small,
  breaklines=true,
  backgroundcolor=\color{lightgray},
  breakautoindent=true,
}
\begin{document}
  \DocInput{efbox.dtx}
  \PrintChanges
  % \PrintIndex
\end{document}
%</driver>
% \fi
%
% \CheckSum{0}
%
% \CharacterTable
%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%   Digits        \0\1\2\3\4\5\6\7\8\9
%   Exclamation   \!     Double quote  \"     Hash (number) \#
%   Dollar        \$     Percent       \%     Ampersand     \&
%   Acute accent  \'     Left paren    \(     Right paren   \)
%   Asterisk      \*     Plus          \+     Comma         \,
%   Minus         \-     Point         \.     Solidus       \/
%   Colon         \:     Semicolon     \;     Less than     \<
%   Equals        \=     Greater than  \>     Question mark \?
%   Commercial at \@     Left bracket  \[     Backslash     \\
%   Right bracket \]     Circumflex    \^     Underscore    \_
%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%   Right brace   \}     Tilde         \~}
%
%
% \changes{v0.1}{2011/12/22}{Converted to DTX file.}
%
% \changes{v1.0}{2014/03/28}{Many changes in preparation for release.}
% 
% \DoNotIndex{\newcommand,\newenvironment}
% \DoNotIndex{\def,\ifpdf,\begin}
% \DoNotIndex{\DeclareOption,\ExecuteOptions,\RequirePackage}
% \DoNotIndex{\renewcommand,\else,\fi,\relax,\@bsphack,\@esphack}
% \DoNotIndex{\active,\AtEndOfPackage,\catcode,\centering}
% \DoNotIndex{\closeout,\comment,\do,\dospecials,\end,\endcomment}
% \DoNotIndex{\fbox,\gdef,\immediate,\includegraphics,\let}
% \DoNotIndex{\linewidth,\message,\newif,\newwrite,\openout}
% \DoNotIndex{\PackageWarning,\space,\the,\verbatim@line}
% \DoNotIndex{\verbatim@processline,\verbatim@start,\write}
% \DoNotIndex{\@makeother,\IfFileExists,\ProcessOptions}
% \DoNotIndex{\@ifnextchar,\define@key,\MessageBreak,\setkeys}
% \DoNotIndex{\stepcounter,\newcounter,\trivlist,\AtEndDocument}
% \DoNotIndex{\@empty,\edef,\csname,\endcsname,\edef,\begingroup}
% \DoNotIndex{\endgroup,\endtrivlist,\global,\if,\ifx,\item}
% \DoNotIndex{\PackageWarningNoLine,\PassOptionsToPackage}
% \DoNotIndex{\ProvidesPackage,\@arabic}
% 
% \providecommand*{\url}{\texttt}
% \GetFileInfo{efbox.dtx}
% \title{The \textsf{efbox} package}
% \author{Jos�� Romildo Malaquias \\ \url{malaquias@gmail.com}}
% \date{\fileversion~from \filedate}
%
% \maketitle
%
% \section{Introduction}
%
% The \texttt{efbox} package defines the command \texttt{efbox}, which
% is an enhanced version of the \texttt{fbox} command. It creates a box
% just wide enough to hold the text created by its argument, allowing to
% draw a frame around the outside of the box at the chosen borders, and
% to set a background color for the box.
%
% \section{Usage}
%
% In order to use the package, just load it in the preamble of your
% document:
% \begin{verbatim}
% \usepackage{efbox}
% \end{verbatim}
%
% \DescribeMacro{\efbox}
% 
% The macro \verb|efbox| can be used to create a horizontal box just
% wide enough to hold the text created by its argument (like the
% \verb|makebox| macro). Additionaly a frame can be drawn around the
% outside of the box (like the \verb|fbox| macro) at the chosen
% borders. Also it can set a background color for the box.
% \begin{quote}
% \verb|\efbox[|\meta{keyword}$=$\meta{value}\verb|...]{|\meta{text}\verb|}|
% \end{quote}
% 
% The available keywords are:
% \begin{description}
%   \item[\normalfont\texttt{leftline}:] This is a boolean, either true
%   or false; the default is true. If true, a line is drawn in the left
%   border of the box.
% 
%   \item[\normalfont\texttt{rightline}:] This is a boolean, either true
%   or false; the default is true. If true, a line is drawn in the right
%   border of the box.
% 
%   \item[\normalfont\texttt{topline}:] This is a boolean, either true
%   or false; the default is true. If true, a line is drawn in the top
%   border of the box.
% 
%   \item[\normalfont\texttt{bottomline}:] This is a boolean, either
%   true or false; the default is true. If true, a line is drawn in the
%   bottom border of the box.
% 
%   \item[\normalfont\texttt{hidealllines}:] This is a boolean, either
%   true or false; the default is false. If true, no line is drawn in
%   the borders of the box.
% 
%   \item[\normalfont\texttt{backgroundcolor=}\meta{backgroundcolor}:]
%   \meta{backgroundcolor} is the color used as the background for the
%   box. The default is the current background color.
% 
%   \item[\normalfont\texttt{linecolor=}\meta{linecolor}:]
%   \meta{linecolor} is the color used for the border lines. The default
%   is black.
%
%   \item[\normalfont\texttt{linewidth=}\meta{linewidth}:]
%   \meta{linewidth} is the width of the lines drawn at the borders of
%   the box. The default is \verb|\fboxrule|.
%
%   \item[\normalfont\texttt{margin=}\meta{margin}:] \meta{margin} is
%   the distance between the border lines and the box text. The default
%   is \verb|\fboxsep|.
% 
%   \item[\normalfont\texttt{font=}\meta{font}:] \meta{font} is the font
%   used to typeset the text in the box. The default is the current
%   font.
% 
%   \item[\normalfont\texttt{baselinestretch=}\meta{baselinestretch}:]
%   \meta{baselinestretch} is the base line stretch. There is no
%   default.
% \end{description}
%
% \DescribeMacro{\efboxsetup}
% 
% The macro \verb|efboxsetup| can be used to set options used by
% \verb|\efbox|.
% \begin{quote}
% \verb|\efboxsetup{|\meta{keyword}$=$\meta{value}\verb|...]|
% \end{quote}
% The available keyworkds are the same from the \verb|\efbox| macro.
%
% \StopEventually{}
%
% \section{Examples}
% 
% This is a demonstration of the \texttt{efbox} macro.
% 
% \iffalse
%<*example>
% \fi
% \begin{LTXexample}[pos=b,numbers=none]
\efbox{Foo}
\efbox[rightline=false,topline=false]{Foo}
\efbox[topline,backgroundcolor=red]{Foo}
\efbox[linewidth=2pt,font=\Large]{Large Foo}
\efbox[rightline=false,topline=false,linecolor=blue,linewidth=2pt]{Foo}
\efbox[margin=10pt,backgroundcolor=yellow,font=\ttfamily\itshape]{Italic Typewriter Foo}

\efbox[linewidth=3pt,margin=5pt,backgroundcolor=red]{Foo}
\efbox[hidealllines,backgroundcolor=red]{Foo}
\efbox{Foo}
\efbox[hidealllines,backgroundcolor=red,margin=15pt]{Foo}
\efbox[margin=15pt,linewidth=5pt]{Foo}
\efbox[bottomline=false,rightline=false,linewidth=2pt,margin=1pt,backgroundcolor=yellow]{Foo}

\efbox{Foo}
% \end{LTXexample}
% \iffalse
%</example>
% \fi
%
% \section{Implementation}
%
% \iffalse
%<*package>
% \fi
%
%    \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{efbox}[2014/03/19 v1.0 An enhanced fbox command]
\RequirePackage{color}
\RequirePackage{pgfkeys}
\newif\if@efbox@leftline
\newif\if@efbox@rightline
\newif\if@efbox@topline
\newif\if@efbox@bottomline
\pgfkeys{
  /efbox/.cd,
  leftline/.is if           = @efbox@leftline,
  rightline/.is if          = @efbox@rightline,
  topline/.is if            = @efbox@topline,
  bottomline/.is if         = @efbox@bottomline,
  hidealllines/.style       = {leftline=false,rightline=false,topline=false,bottomline=false},
  backgroundcolor/.store in = \efbox@backgroundcolor,
  linecolor/.store in       = \efbox@linecolor,
  linewidth/.store in       = \efbox@linewidth,
  margin/.store in          = \efbox@margin,
  font/.store in            = \efbox@font,
  baselinestretch/.store in = \efbox@baselinestretch,
}
\pgfqkeys{/efbox}{
  leftline   = true,
  rightline  = true,
  topline    = true,
  bottomline = true,
  linecolor  = black,
  linewidth  = \fboxrule,
  margin     = \fboxsep,
}
\newif\if@efbox@hasframe
%    \end{macrocode}
%
% \begin{macro}{\efboxsetup}
%    \begin{macrocode}
\def\efbox@global@options{}
\newcommand\efboxsetup[1]{%
  \def\efbox@global@options{#1}%
}%
\newcommand*\mypgfqkeys@with@saved@options[3]{%
  % #1 => path
  % #2 => macro holding saved options
  % #3 => keys
  \def\@pgfqkeys@##1{\pgfqkeys{#1}{##1}}%
  \expandafter\@pgfqkeys@\expandafter{#2,#3}%
}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\efbox}
%    \begin{macrocode}
\newcommand\efbox[2][]{%
  \begingroup%
    \mypgfqkeys@with@saved@options{/efbox}{\efbox@global@options}{#1}%
    %\expandafter\pgfqkeys\expandafter{/efbox}\expandafter{\efbox@global@options,#1}%
%    \end{macrocode}
%
%    \begin{macrocode}
    \ifdefined\efbox@font\efbox@font\fi
%    \end{macrocode}
%
%    \begin{macrocode}
    \ifdefined\efbox@baselinestretch
      \def\baselinestretch{\efbox@baselinestretch}%
    \fi
%    \end{macrocode}
%
%    \begin{macrocode}
    \@efbox@hasframefalse
    \if@efbox@topline\@efbox@hasframetrue\else\fi
    \if@efbox@bottomline\@efbox@hasframetrue\else\fi
    \if@efbox@leftline\@efbox@hasframetrue\else\fi
    \if@efbox@rightline\@efbox@hasframetrue\else\fi
    \ifdefined\efbox@backgroundcolor\@efbox@hasframetrue\else\fi
    \if@efbox@hasframe
      \ifdefined\efbox@backgroundcolor\else\def\efbox@backgroundcolor{white}\fi
      \fboxsep=\efbox@margin
      \fboxrule=\efbox@linewidth
      \let\@frameb@x\@my@frameb@x
      \fboxsep=\efbox@margin
      \def\efbox@body{\fcolorbox{\efbox@linecolor}{\efbox@backgroundcolor}{#2}}%
    \else
      \def\efbox@body{#2}%
    \fi
    \ifdefined\efbox@title
      \ifx\@empty\efbox@title
        \noindent\efbox@body
      \else
        \vbox{%
          \nobreak\vskip\fboxsep
          \rlap{\frametitle{\efbox@title}}%
          \nobreak\nointerlineskip
          \vskip-\baselineskip
          \vskip \fboxsep
          \noindent\efbox@body
        }%
      \fi
    \else
      \efbox@body
    \fi
  \endgroup
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\@my@frameb@x}
%    \begin{macrocode}
\def\@my@frameb@x#1{%
   \@tempdima\fboxrule
   \advance\@tempdima\fboxsep
   \advance\@tempdima\dp\@tempboxa
   \hbox{%
     \lower\@tempdima\hbox{%
       \vbox{%
	\if@efbox@topline\hrule\@height\fboxrule\fi
	\hbox{%
	  \if@efbox@leftline\vrule\@width\fboxrule\fi
           #1%
           \vbox{%
             \vskip\fboxsep
             \box\@tempboxa
             \vskip\fboxsep}%
           #1%
           \if@efbox@rightline\vrule\@width\fboxrule\fi
	}%
         \if@efbox@bottomline\hrule\@height\fboxrule\fi
       }%
     }%
   }%
}%
\endinput
%    \end{macrocode}
% \end{macro}
%
%
% \iffalse
%</package>
% \fi
%
% \Finale
\endinput