% LaTeX package for private notes (by Paul Taylor)

\newif\if@attns\@attnsfalse

\def\private@bra{[\![}\def\private@ket{]\!]}

%\def\text@private#1{\leavevmode$[\![${#1}$]\!]$}%
%\def\math@private#1{\;{[\![\hbox{#1}]\!]}\;}%

\def\text@private#1{\leavevmode$\private@bra${\aftergroup\end@text@private#1}}%
\def\end@text@private{$\private@ket$}%

\def\math@private#1{\;\bgroup
   \private@bra\hbox\bgroup\aftergroup\end@text@private#1\egroup}%
\def\end@math@private{\private@ket\egroup\;}%

%\def\do@private#1{\relax\ifmmode\math@private{#1}\else\text@private{#1}\fi}

\def\do@private{\relax
   \ifmmode\expandafter
       \math@private
   \else\expandafter
       \text@private
   \fi}

\def\ig@private#1{\relax\ifhmode\unskip\fi}%

\def\ATTENTION{%
  \relax
  \typeout{****************** ATTENTION: on line \the\inputlineno}%
  \ifmmode
      \@warning{attention ignored within maths}%
  \else
      \if@attns\@attn[\strut@rule{1pt}]\fi
  \fi
}

\def\strut@rule#1{\vrule height\ht\strutbox depth\dp\strutbox width #1\relax}

\def\@attn[#1]{%
     \setbox2=\rlap{\kern\hsize\kern 5pt{#1}\hss}\ht2\z@
     \ifhmode
        \ifinner
           \@warning{attention ignored in inner horizontal mode}%
        \else
           % this was based on TeXbook p316
           % depth \strutbox because of descenders in the text
           \dp2\dp\strutbox
           \@bsphack
           \strut@rule\z@
           \vadjust{\kern-\dp\strutbox\box2}%
           \@esphack
        \fi
     \else
        % in vertical mode: attach to following line
        % saving \prevdepth
        \dimen@\prevdepth
        \nointerlineskip
        \dp2\z@
        \kern\baselineskip\nobreak
        \box2\nobreak
        \prevdepth\dimen@
        \kern-\baselineskip
     \fi
}

\let\private\do@private\let\enddoc\relax
\DeclareOption{show}{\let\private\do@private\let\enddoc\relax}%
\DeclareOption{hide}{\let\private\ig@private\def\enddoc{\end{document}}}%
\DeclareOption{attn}{\@attnstrue}%
\ProcessOptions

\endinput

% The following was used in my book

\newenvironment{annotation}%
   {\@bsphack\insert\note@box\bgroup
      \textwidth 80mm
      \hsize\textwidth \linewidth\textwidth
      \hfuzz 60mm
      \small
      \NumberResultsfalse\let\c@Result\count@
      \reset@font
      \let\footnote\relax
      \let\cite\relax
      \diagramstyle{silent}%
      \MakeIndexfalse
      \reportchangefalse
      \let\ref\noref
      \noindent\textbf{[\@currentlabel]}%
   }%
   {\vskip 10pt plus 10pt minus 6pt \penalty-4000 \@ignoretrue\egroup
     \global\setbox\note@box\vbox{}%  DISABLE ALL ANNOTATIONS
     \@esphack}

\let\annotate\annotation\let\endannotate\endannotation
