\ProvidesPackage{dlfltxbmisc}[2008/01/01 v0.2 by Lars Madsen]

% This package 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 2003/12/01 or later.
%% 
%% This work has the LPPL maintenance status "maintained".
%% 
%% The Current Maintainer of this work is Lars Madsen (daleif@imf.au.dk).
%%



% if memoir is not loaded we will need the chngpage to get adjustwidth
\@ifclassloaded{memoir}{}{
  \RequirePackage{chngpage}
}

\RequirePackage{ragged2e}
\RequirePackage{url}
\RequirePackage{calc}

\@ifundefined{marg}{\newcommand\marg{}}{}
\@ifundefined{oarg}{\newcommand\oarg{}}{}
\@ifundefined{parg}{\newcommand\parg{}}{}


\newcommand*\Arg@s[1]{\textnormal{\texttt{#1}}}%
\newcommand*\Arg@n[1]{\textnormal{$\langle$\textit{#1}$\rangle$}}%
\newcommand*\Arg{\@ifstar{\Arg@s}{\Arg@n}}%

\newcommand*\marg@s[1]{\textnormal{\texttt{\{#1\}}}}
\newcommand*\marg@n[1]{%
  \textnormal{\texttt{\{}$\langle$\textit{#1}$\rangle$\texttt{\}}}%
}
\renewcommand*\marg{\@ifstar{\marg@s}{\marg@n}}

\newcommand*\oarg@s[1]{\textnormal{\texttt{[#1]}}}
\newcommand*\oarg@n[1]{%
  \textnormal{\texttt{[}$\langle$\textit{#1}$\rangle$\texttt{]}}%
}
\renewcommand*\oarg{\@ifstar{\oarg@s}{\oarg@n}}

\newcommand*\parg@s[1]{\textnormal{\texttt{(#1)}}}
\newcommand*\parg@n[1]{%
  \textnormal{\texttt{(}$\langle$\textit{#1}$\rangle$\texttt{)}}%
}
\renewcommand*\parg{\@ifstar{\parg@s}{\parg@n}}

\newcommand\malign[2][2pt]{%
  \makebox[0pt][l]{\kern#1\smash{\rule[-1.5mm-#2\baselineskip]{0.01pt}{5mm+#2\baselineskip}}}%
}


\newenvironment{syntax}{%
  \vskip.5\baselineskip\allowbreak%
  \begin{adjustwidth}{\parindent}{0pt}
    \parindent=0pt%
    \obeylines%
    \let\\=\relax%
  }{%
  \end{adjustwidth}%
  \vskip.5\baselineskip%
}
\newenvironment{syntax*}{%
  \vskip.5\baselineskip%
  \begin{adjustwidth}{\parindent}{0pt}
    \parindent=0pt%
  }{%
  \end{adjustwidth}%
  \vskip.5\baselineskip%
}

\let\syntaks=\syntax
\let\endsyntaks=\endsyntax

% macro used in several math examples to show the structure. It acts
% like some text but only displays a box.
\newcommand\@dbx[1]{{\fboxsep=0pt\fboxrule=0.4pt\,\fbox{\phantom{\rule[-0.6mm]{#1}{3mm}}}\,}}
\newcommand\dbx[1][5mm]{\ifmmode\mathord{\@dbx{#1}}\else\@dbx{#1}\fi}


% powerfull macro by Morten Høgholm, this enables you to measure the
% length of the previous paragraf.
\newdimen\lastlinedim
\def\getlastlinesize{%
   \begingroup\frozen@everydisplay{}%
        $$
        \abovedisplayskip=\z@skip \abovedisplayshortskip=\z@skip
        \belowdisplayskip=\z@skip \belowdisplayshortskip=\z@skip
        \global\lastlinedim=\dimexpr\predisplaysize-2em\relax
        \halign{##\cr}%
        $$
        \mbox{}%
        \endgroup%
}

% this is a very special little macro to be used in the 'note' field
% of bibtex entries. It eats up the added '.' and typesets the main
% argument (an URL) in a raggedright manner, wrapped up into the
% previous paragraph. It looks pretty cool.
\newcommand\addurl[3][\textsc{url}:]{%
  \getlastlinesize{}%
  \vskip-2\baselineskip%
  \begingroup%
  \def\UrlNoBreaks{\do\(\do\[\do\{\do\<\do\:\do\.}%\]
  \RaggedLeft%
  \fussy%
  \hbadness=10000% cheating
  \addtolength\lastlinedim{-\bibhang}%
  \fboxsep=0pt%
  \fboxrule=0pt%
  \fbox{\hbox to \lastlinedim{\hfill \footnotesize \strut   \hfill}}%
  \ifdim \lastlinedim > 0.6\linewidth\relax% we break
  \nopagebreak\vskip-3pt%
  \else%
  % special thanks to Dan Luecking for this, since my original
  % \hspace{\fill} failed miserably
  \hskip1em plus 5em minus .7em
  \fi%
  {\footnotesize #1~~{\url{#2}}} % 
  \par%
  \endgroup%
}


