%%
%% This is file `fixme.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% fixme.dtx  (with options: `header,fixme')
%% 


%% Copyright (C) 1998-2002, 2004-2007, 2009, 2013, 2017-2019 Didier Verna

%% This file is part of FiXme.

%% FiXme 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.

%% FiXme consists of the files listed in the file `README'.

%% \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         \~}

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{fixme}[2019/01/03 v4.5 Collaborative annotations for LaTeX2e]

\RequirePackage{ifthen}
\RequirePackage{verbatim}
\RequirePackage{xkeyval}[2006/11/18]

\newcommand\fixmelogo{\textsf{FiXme}}

\newcommand\@fxpkginfo{\PackageInfo{FiXme}}
\newcommand\@fxpkgwarning{\PackageWarning{FiXme}}
\newcommand\@fxpkgerror{\PackageError{FiXme}}

\newcommand*\@fxaddtolist[2]{%
  \expandafter\ifx\csname #1\endcsname\relax%
    \expandafter\def\csname #1\endcsname{#2}%
  \else%
    \expandafter\ifx\csname #1\endcsname\empty%
      \expandafter\g@addto@macro\csname #1\endcsname{#2}%
    \else%
      \expandafter\g@addto@macro\csname #1\endcsname{,#2}%
    \fi%
  \fi}

\newcommand\@fxkeyifundefined{\key@ifundefined[fx]}
\newcommand\@fxdefinekey{\define@key[fx]}
\newcommand\@fxdefinecmdkey{\define@cmdkey[fx]}
\newcommand\@fxdefinechoicekey{\define@choicekey[fx]}
\newcommand\@fxsetkeys{\setkeys[fx]}
%%      Note: currently unused
%%      \newcommand\@fxpresetkeys{\presetkeys[fx]}

\newcommand*\@fxvoidkeyerror[2]{%
  \@fxpkgerror{misuse of key '#1'}{%
    You have given the key '#1' the argument '#2' but it takes
    none.\MessageBreak
    Type X to quit, fix that key and re-run LaTeX.\MessageBreak}}
\newcommand*\@fxdefinevoidkey[3]{%
  \define@key[fx]{#1}{#2}[]{%
    \ifthenelse{\equal{##1}{}}{%
      #3}{%
      \@fxvoidkeyerror{#2}{##1}}}}

\newcommand*\@fxdefineboolkey[3][]{%
  \define@boolkey[fx]{#2}{#3}[true]{#1}
  \@fxdefinevoidkey{#2}{no#3}{\@nameuse{fx@#2@#3}{false}}}

\newcommand*\@fxdefineoptioninterface[2]{%
  \expandafter\newcommand\csname FXDefine#2Key\endcsname{%
    \@fxdefinekey{#1}}%
  \expandafter\newcommand\csname FXDefine#2CmdKey\endcsname{%
    \@fxdefinecmdkey{#1}}%
  \expandafter\newcommand\csname FXDefine#2ChoiceKey\endcsname{%
    \@fxdefinechoicekey{#1}}%
  \expandafter\newcommand\csname FXDefine#2VoidKey\endcsname{%
    \@fxdefinevoidkey{#1}}%
  \expandafter\newcommand\expandafter*\csname FXDefine#2BoolKey\endcsname[2][]{%
    \@fxdefineboolkey[##1]{#1}{##2}}}

\let\l@fixme\l@figure
\newcommand*\@fxdottedtocline[5]{%
  \ifnum #1>\c@tocdepth \else
    \vskip \z@ \@plus.2\p@
    {\leftskip #2\relax \rightskip \@tocrmarg \parfillskip -\rightskip
     \parindent #2\relax\@afterindenttrue
     \interlinepenalty\@M
     \leavevmode
     \@tempdima #3\relax
     \advance\leftskip \@tempdima \null\nobreak\hskip -\leftskip
     {#4}\nobreak
     \leaders\hbox{$\m@th
       \mkern \@dotsep mu\hbox{.}\mkern \@dotsep
       mu$}\hfill
     \nobreak
     #5\par}%
  \fi}
\newcommand*\fxcontentsline[2]{%
  \begingroup%
  \let\@dottedtocline\@fxdottedtocline%
  \l@fixme{#1}{#2}%
  \endgroup}

\newcommand*\fxaddcontentsline[1]{%
  \ifthenelse{\equal{\cmdfx@note@target}{thepage}}{%
    \addcontentsline{lox}{fixme}{#1}}{%
    \addtocontents{lox}{\protect\fxcontentsline{#1}{\cmdfx@note@target}}}}

\newcommand\@lox@prtc@article{%
  \section*{\@fxlistfixmename%
    \@mkboth{\MakeUppercase\@fxlistfixmename}{\MakeUppercase\@fxlistfixmename}}}
\let\@lox@psttc@article\relax

\newcommand\@lox@prtc@report{%
  \if@twocolumn
    \@restonecoltrue\onecolumn
  \else
    \@restonecolfalse
  \fi
  \chapter*{\@fxlistfixmename%
    \@mkboth{\MakeUppercase\@fxlistfixmename}{\MakeUppercase\@fxlistfixmename}}}
\newcommand\@lox@psttc@report{\if@restonecol\twocolumn\fi}

\newcommand\@lox@prtc@book{%
  \if@twocolumn
    \@restonecoltrue\onecolumn
  \else
    \@restonecolfalse
  \fi
  \chapter*{\@fxlistfixmename%
    \@mkboth{\MakeUppercase\@fxlistfixmename}{\MakeUppercase\@fxlistfixmename}}}
\newcommand\@lox@psttc@book{\if@restonecol\twocolumn\fi}

\let\lox@final\relax

\newread\lox@file
\newif\iflox@typeset
\def\lox@eol{\par}
\newcommand\lox@draft{%
  \lox@typesetfalse%
  \openin\lox@file\jobname.lox\relax
  \ifeof\lox@file\else
    \read\lox@file to \lox@maybeeol
    \ifeof\lox@file
      \ifx\lox@maybeeol\lox@eol\else\lox@typesettrue\fi
    \else
      \lox@typesettrue
    \fi
  \fi
  \closein\lox@file
  \iflox@typeset\@lox@prtc\@starttoc{lox}\@lox@psttc\else\@starttoc{lox}\fi}
\newcommand\lox@draft@ams{\@starttoc{lox}\@fxlistfixmename}

\newcommand*\fxsetface[2]{\@fxsetkeys{face}{#1face=#2}}
\newcommand*\@fxnewface[2][]{%
  \@fxdefinecmdkey{face}{#2face}{}%
  \fxsetface{#2}{#1}}
\newcommand*\@fxuseface[1]{\@nameuse{cmdfx@face@#1face}}

\@fxdefineboolkey[%
  \ifthenelse{\equal{#1}{true}}{%
    \fx@mode@singleuserfalse}{%
    \fx@mode@singleusertrue}]{%
    mode}{multiuser}
\@fxdefineboolkey[%
  \ifthenelse{\equal{#1}{true}}{%
    \fx@mode@multiuserfalse}{%
    \fx@mode@multiusertrue}]{%
    mode}{singleuser}
\@fxdefinechoicekey{mode}{mode}{multiuser,singleuser}{\@fxsetkeys{mode}{#1}}

\let\@fxearlylayouts\empty
\let\@fxlatelayouts\empty
\newcommand*\FXProvidesLayout[1]{\ProvidesPackage{fxlayout#1}}
\newcommand*\@fxrecordlayoutmutex[2]{%
  \edef\@fxlts{\zap@space#2 \@empty}%
  \def\@fxexpr{\@fxaddtolist{@fxlayout@#1@mutex}}%
  \expandafter\@fxexpr\expandafter{\@fxlts}%
  \@for\@fxlt:=\@fxlts\do{\@fxaddtolist{@fxlayout@\@fxlt @mutex}{#1}}}
\newcommand*\@fxhandlelayoutmutex[1]{%
  \ifthenelse{\boolean{fx@layout@#1}}{%
    \def\@fxexpr{\@for\@fxlt:=}%
    \expandafter\@fxexpr\csname @fxlayout@#1@mutex\endcsname\do{%
      \@ifundefined{iffx@layout@\@fxlt}{}{%
        \ifthenelse{\boolean{fx@layout@\@fxlt}}{%
          \@fxpkgwarning{%
            #1 layout requested;\MessageBreak
            turning \@fxlt\space layout off}%
          \@nameuse{fx@layout@\@fxlt}{false}}{}}}}{}}

\def\@FXRegisterLayout#1[#2]#3#4{%
  \@fxkeyifundefined{layout}{#3}{%
    \@fxrecordlayoutmutex{#3}{#2}%
    \@fxdefineboolkey[\@fxhandlelayoutmutex{#3}]{layout}{#3}%
    \expandafter\def\csname @fxlayout@#3\endcsname{#4}%
    \@fxaddtolist{@fx#1layouts}{#3}}{%
    \@fxpkgerror{layout '#3' already registered}{%
      You have called \string\FXRegisterLayout\space with a name already
      in use.\MessageBreak
      If you want to modify an existing layout, renew its
      command.\MessageBreak
      Otherwise, you must choose a different name.}}}
\newcommand\FXRegisterLayout{%
  \@ifstar{%
    \@ifnextchar[%]
    {\@FXRegisterLayout{early}}{\@FXRegisterLayout{early}[]}}{%
    \@ifnextchar[%]
    {\@FXRegisterLayout{late}}{\@FXRegisterLayout{late}[]}}}

\@fxdefineoptioninterface{layout}{Layout}

\newcommand*\@fxtextstd[3]{\ignorespaces#3 \fxnotename{#1}: #2}
\DeclareRobustCommand*\@fxsignature[1]{%
  \ifthenelse{\equal{#1}{}}{}{ -- {\@fxuseface{signature}#1}}}
\newcommand*\@fxsigstd[3]{\fxnotename{#1}: #2\@fxsignature{#3}}
\@fxnewface{margin}
\newcommand*\FXLayoutMargin[3]{%
  \marginpar[\raggedleft\@fxuseface{margin}\@fxtextstd{#1}{#2}{#3}]{%
    \raggedright\@fxuseface{margin}\@fxtextstd{#1}{#2}{#3}}}
\FXRegisterLayout*{margin}{\FXLayoutMargin}
\newcommand*\FXLayoutMarginClue[3]{%
  \marginpar[%
  {\raggedleft\@fxuseface{margin}\ignorespaces#3 \fxnotename{#1}!}]{%
    \raggedright\@fxuseface{margin}\ignorespaces#3 \fxnotename{#1}!}}
\FXRegisterLayout*[margin]{marginclue}{\FXLayoutMarginClue}
\newcommand*\FXLayoutFootnote[3]{\footnote{\@fxtextstd{#1}{#2}{#3}}}
\FXRegisterLayout{footnote}{\FXLayoutFootnote}
\@fxnewface{inline}
\newcommand*\FXLayoutInline[3]{ \@fxuseface{inline}\@fxtextstd{#1}{#2}{#3}}
\FXRegisterLayout{inline}{\FXLayoutInline}
\newcommand\fixmeindexname{\fixmelogo}
\def\@wrindex#1{%
  \ifthenelse{\equal{\cmdfx@note@target}{thepage}}{%
    \protected@write\@indexfile{}{\string\indexentry{#1}{\thepage}}}{%
    \protected@write\@indexfile{}{\string\indexentry{#1}{\cmdfx@note@target}}}%
  \endgroup
  \@esphack}
\newcommand\@fxnotekey{***a}
\newcommand\@fxwarningkey{***b}
\newcommand\@fxerrorkey{***c}
\newcommand\@fxfatalkey{***d}
\newcommand*\FXLayoutIndex[3]{%
  \iffx@mode@multiuser%
    \index{***@\fixmeindexname:%
      !\@nameuse{@fx#1key}@\fxnotesname{#1}:%
      !\@nameuse{thefx#1count}: #3: #2}%
    \index{***#3@\fixmeindexname{} (#3):%
      !\@nameuse{@fx#1key}@\fxnotesname{#1}:%
      !\@nameuse{thefx#1count}: #2}%
  \else%
    \index{***@\fixmeindexname:%
      !\@nameuse{@fx#1key}@\fxnotesname{#1}:%
      !\@nameuse{thefx#1count}: #2}%
  \fi}
\FXRegisterLayout{index}{\FXLayoutIndex}
\newcommand*\FXLayoutContentsLine[3]{%
  \iffx@mode@multiuser%
    \fxaddcontentsline{\@fxtextstd{#1}{#2}{#3}}%
  \else%
    \fxaddcontentsline{\fxnotename{#1}: #2}%
  \fi}

\newcommand*\fxloadlayouts[1]{%
  \edef\@fxlts{\zap@space#1 \@empty}%
  \@for\@fxlt:=\@fxlts\do{\usepackage{fxlayout#1}}}

\newcommand\@fxsetlayoutkeys{\@fxsetkeys{layout}}
\def\@fxparselayout#1#2#3\relax{\def\@fxltprefix{#1#2}\def\@fxltrest{#3}}
\newcommand*\fxuselayouts[1]{%
  \edef\@fxlts{\zap@space#1 \@empty}%
  \@for\@fxlt:=\@fxlts\do{%
    \expandafter\@fxparselayout\@fxlt\relax%
    \ifthenelse{\equal{\@fxltprefix}{no}}{%
      \let\@fxltname\@fxltrest}{%
      \let\@fxltname\@fxlt}%
    \@fxkeyifundefined{layout}{\@fxltname}{\fxloadlayouts{\@fxltname}}{}}%
  \@fxsetkeys{layout}{#1}}
\let\FXRequireLayouts\fxuselayouts

\@fxdefinecmdkey{layout}{innerlayout}{}
\@fxdefinekey{layout}{morelayout}{\fxuselayouts{#1}}
\@fxdefinekey{layout}{layout}{%
  \edef\@fxlayouts{\@fxearlylayouts,\@fxlatelayouts}%
  \@for\@fxlt:=\@fxlayouts\do{%
    \@nameuse{fx@layout@\@fxlt}{false}}%
  \fxuselayouts{#1}}

\newcommand*\FXProvidesEnvLayout[1]{\ProvidesPackage{fxenvlayout#1}}
\newcommand*\FXRegisterEnvLayout[3]{%
  \@ifundefined{@fxenvlayout@#1@begin}{%
    \expandafter\def\csname @fxenvlayout@#1@begin\endcsname{#2}%
    \expandafter\def\csname @fxenvlayout@#1@end\endcsname{#3}}{%
    \@fxpkgerror{environment layout '#2' already registered}{%
      You have called \string\FXRegisterEnvLayout\space with a name already in
      use.\MessageBreak
      If you want to modify an existing environment layout, renew its
      commands.\MessageBreak
      Otherwise, you must choose a different name.}}}

\@fxdefineoptioninterface{envlayout}{EnvLayout}

\@fxnewface{env}
\newcommand*\FXEnvLayoutPlainBegin[2]{%
  \@fxuseface{env}\ignorespaces#2 \fxnotename{#1}: \ignorespaces}
\newcommand*\FXEnvLayoutPlainEnd[2]{}
\FXRegisterEnvLayout{plain}{\FXEnvLayoutPlainBegin}{\FXEnvLayoutPlainEnd}

\@fxnewface[\itshape]{signature}
\newcommand*\FXEnvLayoutSignatureBegin[2]{%
  \@fxuseface{env}\fxnotename{#1}: \ignorespaces}
\newcommand*\FXEnvLayoutSignatureEnd[2]{\@fxsignature{#2}}
\FXRegisterEnvLayout{signature}{%
  \FXEnvLayoutSignatureBegin}{\FXEnvLayoutSignatureEnd}

\newcommand*\@fxselectenvlayout[1]{%
  \expandafter\let\expandafter\@fxenvlayout@begin%
    \csname @fxenvlayout@#1@begin\endcsname%
  \expandafter\let\expandafter\@fxenvlayout@end%
    \csname @fxenvlayout@#1@end\endcsname}

\newcommand*\fxloadenvlayouts[1]{%
  \edef\@fxlts{\zap@space#1 \@empty}%
  \@for\@fxlt:=\@fxlts\do{\usepackage{fxenvlayout#1}}}

\newcommand*\fxuseenvlayout[1]{%
  \@ifundefined{@fxenvlayout@#1@begin}{\fxloadenvlayouts{#1}}{}%
  \@fxselectenvlayout{#1}}
\let\FXRequireEnvLayout\fxuseenvlayout
\@fxdefinekey{envlayout}{envlayout}{\fxuseenvlayout{#1}}

\newcommand*\FXProvidesTargetLayout[1]{\ProvidesPackage{fxtargetlayout#1}}
\newcommand*\FXRegisterTargetLayout[2]{%
  \@ifundefined{@fxtargetlayout@#1}{%
    \expandafter\def\csname @fxtargetlayout@#1\endcsname{#2}}{%
    \@fxpkgerror{target layout '#1' already registered}{%
      You have called \string\FXRegisterTargetLayout\space with a name
      already in use.\MessageBreak
      If you want to modify an existing target layout, renew its
      command.\MessageBreak
      Otherwise, you must choose another name.}}}

\@fxdefineoptioninterface{targetlayout}{TargetLayout}

\@fxnewface{target}
\newcommand\FXTargetLayoutPlain[2]{\@fxuseface{target}#2}
\FXRegisterTargetLayout{plain}{\FXTargetLayoutPlain}

\newcommand*\@fxselecttargetlayout[1]{%
  \expandafter\let\expandafter\@@fxtargetlayout%
    \csname @fxtargetlayout@#1\endcsname}

\newcommand*\fxloadtargetlayouts[1]{%
  \edef\@fxlts{\zap@space#1 \@empty}%
  \@for\@fxlt:=\@fxlts\do{\usepackage{fxtargetlayout#1}}}

\newcommand*\fxusetargetlayout[1]{%
  \@ifundefined{@fxtargetlayout@#1}{\fxloadtargetlayouts{#1}}{}%
  \@fxselecttargetlayout{#1}}
\let\FXRequireTargetLayout\fxusetargetlayout
\@fxdefinekey{targetlayout}{targetlayout}{\fxusetargetlayout{#1}}

\newcommand\@fxtargetlayout@final[2]{#2}
\newcommand\@fxtargetlayout@draft[2]{%
  \begingroup\@@fxtargetlayout{#1}{#2}\endgroup}

\newcommand*\FXLogNote[1]{%
  \GenericInfo{%
    (FiXme)\@spaces\@spaces\@spaces\@spaces}{%
    FiXme Note: '#1'}}
\newcommand*\FXLogWarning[1]{%
  \GenericWarning{%
    (FiXme)\@spaces\@spaces\@spaces\@spaces}{%
    FiXme Warning: '#1'}}
\newcommand*\FXLogError[1]{%
  \GenericWarning{%
    (FiXme)\@spaces\@spaces\@spaces\@spaces}{%
    FiXme Error: '#1'}}
\newcommand*\FXLogFatal[1]{%
  \GenericWarning{%
    (FiXme)\@spaces\@spaces\@spaces\@spaces}{%
    FiXme Fatal Error: '#1'}}

\def\@fxlog@note{\FXLogNote}
\def\@fxlog@warning{\FXLogWarning}
\def\@fxlog@error{\FXLogError}
\def\@fxlog@fatal{\FXLogFatal}

\@fxdefineboolkey{log}{silent}

\newcounter{fixmecount}
\newcounter{fxnotecount}
\newcounter{fxwarningcount}
\newcounter{fxerrorcount}
\newcounter{fxfatalcount}

\@fxdefinecmdkey{note}{author}{}
\@fxdefinecmdkey{note}{target}{}
\newcommand\@fxhandleinnermode{%
  \ifinner%
    \ifthenelse{\boolean{fx@layout@margin}}{%
      \@fxpkginfo{%
        inner mode detected;\MessageBreak
        turning margin layout form off}}{%
      \ifthenelse{\boolean{fx@layout@marginclue}}{%
        \@fxpkginfo{%
          inner mode detected;\MessageBreak
          turning marginclue layout form off}}{}}%
    \expandafter\@fxsetlayoutkeys\expandafter{%
      \cmdfx@layout@innerlayout,nomargin,nomarginclue}%
  \fi}
\newcommand*\@fxissueearlydraftlayouts[2]{%
  \@fxhandleinnermode%
  \@for\@fxlt:=\@fxearlylayouts\do{%
    \@nameuse{iffx@layout@\@fxlt}%
      \@nameuse{@fxlayout@\@fxlt}{#1}{#2}{\cmdfx@note@author}%
    \fi}}
\newcommand*\@fxissuelatedraftlayouts[2]{%
  \@for\@fxlt:=\@fxlatelayouts\do{%
    \@nameuse{iffx@layout@\@fxlt}%
      \@nameuse{@fxlayout@\@fxlt}{#1}{#2}{\cmdfx@note@author}%
    \fi}}
\newcommand*\@fxissuecommonlayouts[2]{%
  \iffx@log@silent\else\@nameuse{@fxlog@#1}{#2}\fi}

\newcommand*\@@@fxnote@early@final[2]{%
  \ifthenelse{\equal{#1}{fatal}}{%
    \@fxpkgerror{'#2' fatal error left in final version}{%
      You are currently processing in final mode,\MessageBreak
      but you still have some FiXme fatal errors left behind.\MessageBreak
      Type X to quit, fix your document (or switch back to draft
      mode),\MessageBreak
      and rerun LaTeX.}}{}}
\newcommand*\@@@fxnote@late@final[2]{\@fxissuecommonlayouts{#1}{#2}}
\newcommand*\@@@fxnote@early@draft[2]{%
  \@fxissueearlydraftlayouts{#1}{#2}}
\newcommand*\@@@fxnote@late@draft[2]{%
  \@fxissuelatedraftlayouts{#1}{#2}%
  \FXLayoutContentsLine{#1}{#2}{\cmdfx@note@author}%
  \@fxissuecommonlayouts{#1}{#2}}

\newcommand*\@fxpostconfigure{%
  \ifthenelse{\equal{\cmdfx@note@author}{fixme}}{%
    \@fxsetkeys{note}{author=\fixmelogo}}{}%
  \iffx@lang@langtrack%
    \@fxkeyifundefined{lang}{\languagename}{%
      \@fxpkgwarning{unknown language '\languagename';\MessageBreak
        falling back to \@fxdefaultlang}%
      \@fxsetkeys{lang}{\@fxdefaultlang}}{%
      \@fxsetkeys{lang}{\languagename}}
  \fi}

\let\@fxendgroup\endgroup
\def\@@fxnote@early#1#2{%
    \@fxpostconfigure%
    \stepcounter{fixmecount}%
    \stepcounter{fx#1count}%
    \@@@fxnote@early{#1}{#2}}
\def\@@fxnote@late#1#2{%
    \@@@fxnote@late{#1}{#2}%
  \@fxendgroup}
\def\@@fxnote#1#2{%
  \@@fxnote@early{#1}{#2}%
  \@@fxnote@late{#1}{#2}}
\def\@fxnote#1[#2]#3{%
  \@fxsetkeys{mode,status,lang,log,note,face,layout}{#2}%
  \@@fxnote{#1}{#3}}

\long\def\@@fxsnote#1#2#3{%
  \@fxpostconfigure\let\@fxpostconfigure\relax%
  \@@fxnote@early{#1}{#2}\@fxtargetlayout{#1}{#3}\@@fxnote@late{#1}{#2}}
\long\def\@fxsnote#1[#2]#3#4{%
  \@fxsetkeys{mode,status,lang,log,note,face,layout,targetlayout}{#2}%
  \@@fxsnote{#1}{#3}{#4}}

\newcommand*\@fxpreconfigure[1]{%
  \ifthenelse{\equal{#1}{fixme}}{}{\@fxsetkeys{note}{author=#1}}}
\newcommand*\@fxnewnotemacro[3]{%
  \expandafter\DeclareRobustCommand\csname #1#2\endcsname{%
    \begingroup%
      \@fxpreconfigure{#3}%
      \@ifstar{%
        \@ifnextchar[%]
        {\@fxsnote{#2}}{\@@fxsnote{#2}}}{%
        \@ifnextchar[%]
        {\@fxnote{#2}}{\@@fxnote{#2}}}}}
\def\@@@@fxbeginenv@final#1{\comment}
\def\@@@@fxbeginenv@draft#1{\@fxenvlayout@begin{#1}{\cmdfx@note@author}}
\def\@fxendenv@final#1{\endcomment}
\def\@fxendenv@draft#1{\unskip\@fxenvlayout@end{#1}{\cmdfx@note@author}}

\def\@@@fxbeginenv#1#2{%
  \@fxpostconfigure\let\@fxpostconfigure\relax%
  \@@fxnote{#1}{#2}%
  \@@@@fxbeginenv{#1}}
\def\@@fxbeginenv#1#2{%
  \@fxsetkeys{layout}{noinline}%
  \@@@fxbeginenv{#1}{#2}}
\def\@fxbeginenv#1[#2]#3{%
  \@fxsetkeys{mode,status,lang,log,note,face,layout,envlayout}{#2,noinline}%
  \@@@fxbeginenv{#1}{#3}}

\long\def\@@@fxbeginsenv#1#2#3{%
  \@fxpostconfigure\let\@fxpostconfigure\relax%
  \@@fxsnote{#1}{#2}{#3}%
  \@@@@fxbeginenv{#1}}
\long\def\@@fxbeginsenv#1#2#3{%
  \@fxsetkeys{layout}{noinline}%
  \@@@fxbeginsenv{#1}{#2}{#3}}
\long\def\@fxbeginsenv#1[#2]#3#4{%
  \@fxsetkeys{mode,status,lang,log,note,face,layout,envlayout,targetlayout}{%
    #2,noinline}%
  \@@@fxbeginsenv{#1}{#3}{#4}}

\newcommand*\@fxnewnoteenvs[3]{%
  \expandafter\def\csname #1#2\endcsname{%
    \begingroup%
      \let\@fxendgroup\relax%
      \@fxpreconfigure{#3}%
      \@ifnextchar[%]
        {\@fxbeginenv{#2}}{\@@fxbeginenv{#2}}}
  \expandafter\def\csname end#1#2\endcsname{%
      \@fxendenv{#2}%
    \endgroup}%
  \expandafter\long\expandafter\def\csname #1#2*\endcsname{%
    \begingroup%
      \let\@fxendgroup\relax%
      \@fxpreconfigure{#3}%
      \@ifnextchar[%]
        {\@fxbeginsenv{#2}}{\@@fxbeginsenv{#2}}}
  \expandafter\def\csname end#1#2*\endcsname{%
      \@fxendenv{#2}%
    \endgroup}}

\newcommand*\FXRegisterAuthor[3]{%
  \@ifundefined{#1note}{}{%
    \@fxpkgerror{command prefix '#1' already in use}{%
      You have called \string\FXRegisterAuthor\space with a command prefix
      already in use.\MessageBreak
      Please choose another one.}}%
  \@ifundefined{#2note}{}{%
    \@fxpkgerror{environment prefix '#2' already in use}{%
      You have called \string\FXRegisterAuthor\space with an environment
      prefix already in use.\MessageBreak
      Please choose another one.}}%
  \@fxnewnotemacro{#1}{note}{#3}%
  \@fxnewnotemacro{#1}{warning}{#3}%
  \@fxnewnotemacro{#1}{error}{#3}%
  \@fxnewnotemacro{#1}{fatal}{#3}%
  \@fxnewnoteenvs{#2}{note}{#3}%
  \@fxnewnoteenvs{#2}{warning}{#3}%
  \@fxnewnoteenvs{#2}{error}{#3}%
  \@fxnewnoteenvs{#2}{fatal}{#3}}

\FXRegisterAuthor{fx}{anfx}{fixme}
\DeclareRobustCommand\fixme{%
  \@fxpkgwarning{\string\fixme\space is deprecated;\MessageBreak
    please use \string\fxfatal\space instead}%
  \fxfatal}
\def\afixme{%
  \@fxpkgwarning{The 'afixme' environment is deprecated;\MessageBreak
    please use 'anfxfatal' instead}%
  \anfxfatal}
\let\endafixme\endanfxfatal
\newcommand*\@fxlanguages{%
  english,french,francais,spanish,italian,german,ngerman,danish,croatian}

\newcommand\fxenglishnotename{Note}
\newcommand\fxenglishnotesname{Notes}
\newcommand\fxenglishwarningname{Warning}
\newcommand\fxenglishwarningsname{Warnings}
\newcommand\fxenglisherrorname{Error}
\newcommand\fxenglisherrorsname{Errors}
\newcommand\fxenglishfatalname{Fatal}
\newcommand\fxenglishfatalsname{Fatal errors}
\newcommand\englishlistfixmename{List of Corrections}

\newcommand\fxfrenchnotename{Note}
\newcommand\fxfrenchnotesname{Notes}
\newcommand\fxfrenchwarningname{Attention}
\newcommand\fxfrenchwarningsname{Avertissements}
\newcommand\fxfrencherrorname{Erreur}
\newcommand\fxfrencherrorsname{Erreurs}
\newcommand\fxfrenchfatalname{Fatal}
\newcommand\fxfrenchfatalsname{Erreurs fatales}
\newcommand\frenchlistfixmename{Liste des Corrections}

\newcommand\fxspanishnotename{Nota}
\newcommand\fxspanishnotesname{Notas}
\newcommand\fxspanishwarningname{Aviso}
\newcommand\fxspanishwarningsname{Avisos}
\newcommand\fxspanisherrorname{Error}
\newcommand\fxspanisherrorsname{Errores}
\newcommand\fxspanishfatalname{Fatal}
\newcommand\fxspanishfatalsname{Errores fatales}
\newcommand\spanishlistfixmename{Lista de Correcciones}

\newcommand\fxitaliannotename{Nota}
\newcommand\fxitaliannotesname{Note}
\newcommand\fxitalianwarningname{Avviso}
\newcommand\fxitalianwarningsname{Avvisi}
\newcommand\fxitalianerrorname{Errore}
\newcommand\fxitalianerrorsname{Errori}
\newcommand\fxitalianfatalname{Fatale}
\newcommand\fxitalianfatalsname{Errori fatali}
\newcommand\italianlistfixmename{Corrigenda}

\newcommand\fxgermannotename{Anm}
\newcommand\fxgermannotesname{Anmerkungen}
\newcommand\fxgermanwarningname{Warnung}
\newcommand\fxgermanwarningsname{Warnungen}
\newcommand\fxgermanerrorname{Fehler}
\newcommand\fxgermanerrorsname{Fehler}
\newcommand\fxgermanfatalname{Verh\"angnisvoll}
\newcommand\fxgermanfatalsname{Verh\"angnisvolle fehler}
\newcommand\germanlistfixmename{Verzeichnis der Korrekturen}

\newcommand\fxdanishnotename{Note}
\newcommand\fxdanishnotesname{Noter}
\newcommand\fxdanishwarningname{Advarsel}
\newcommand\fxdanishwarningsname{Advarsler}
\newcommand\fxdanisherrorname{Fejl}
\newcommand\fxdanisherrorsname{Fejl}
\newcommand\fxdanishfatalname{Fatal}
\newcommand\fxdanishfatalsname{Fatale fejl}
\newcommand\danishlistfixmename{Rettelser}

\newcommand\fxcroatiannotename{Poruka}
\newcommand\fxcroatiannotesname{Poruke}
\newcommand\fxcroatianwarningname{Upozorenja}
\newcommand\fxcroatianwarningsname{Upozorenje}
\newcommand\fxcroatianerrorname{Gre\v ska}
\newcommand\fxcroatianerrorsname{Greske}
\newcommand\fxcroatianfatalname{Fatalan}
\newcommand\fxcroatianfatalsname{Kobne gre\v ske}
\newcommand\croatianlistfixmename{Popis korekcija}

\@fxdefineboolkey{lang}{langtrack}
\def\@fxexpr{\@fxdefinechoicekey{lang}{defaultlang}[\@fxdefaultlang]}
\expandafter\@fxexpr\expandafter{\@fxlanguages}{}

\def\@fxexpr{\@fxdefinechoicekey{lang}{lang}[\@fxlang]}
\expandafter\@fxexpr\expandafter{\@fxlanguages}{%
  \ifthenelse{\equal{#1}{francais}}{\def\@fxlang{french}}{%
    \ifthenelse{\equal{#1}{ngerman}}{\def\@fxlang{german}}{}}%
  \@fxsetkeys{lang}{langtrack=false}}

\@for\@fxlg:=\@fxlanguages\do{
  \def\@fxexprone{\@fxdefinevoidkey{lang}}
  \edef\@fxexprtwo{{\@fxlg}{\noexpand\@fxsetkeys{lang}{lang=\@fxlg}}}
  \expandafter\@fxexprone\@fxexprtwo}

\newcommand*\@fxlistfixmename{\@nameuse{\@fxlang listfixmename}}
\newcommand*\fxnotename[1]{\@nameuse{fx\@fxlang#1name}}
\newcommand*\fxnotesname[1]{\@nameuse{fx\@fxlang#1sname}}

\@fxdefinevoidkey{status}{final}{%
  \let\@@@fxnote@early\@@@fxnote@early@final%
  \let\@@@fxnote@late\@@@fxnote@late@final%
  \let\@@@@fxbeginenv\@@@@fxbeginenv@final
  \let\@fxendenv\@fxendenv@final%
  \let\@fxtargetlayout\@fxtargetlayout@final%
  \let\listoffixmes\lox@final}
\@fxdefinevoidkey{status}{draft}{%
  \let\@@@fxnote@early\@@@fxnote@early@draft%
  \let\@@@fxnote@late\@@@fxnote@late@draft%
  \let\@@@@fxbeginenv\@@@@fxbeginenv@draft
  \let\@fxendenv\@fxendenv@draft%
  \let\@fxtargetlayout\@fxtargetlayout@draft%
  \let\listoffixmes\lox@draft}
\@fxdefinechoicekey{status}{status}{final,draft}{\@fxsetkeys{status}{#1}}

\newcommand*\FXProvidesTheme[1]{\ProvidesPackage{fxtheme#1}}
\newcommand*\fxusetheme[1]{\usepackage{fxtheme#1}}
\@fxdefinekey{theme}{theme}{\fxusetheme{#1}}
\@ifclassloaded{article}{%
  \let\@lox@prtc\@lox@prtc@article%
  \let\@lox@psttc\@lox@psttc@article}{%
  \@ifclassloaded{report}{%
    \let\@lox@prtc\@lox@prtc@report%
    \let\@lox@psttc\@lox@psttc@report}{%
    \@ifclassloaded{book}{%
      \let\@lox@prtc\@lox@prtc@book%
      \let\@lox@psttc\@lox@psttc@book}{%
      \@ifclassloaded{amsbook}{%
        \let\lox@draft\lox@draft@ams}{%
        \@ifclassloaded{amsart}{%
          \let\lox@draft\lox@draft@ams}{%
          %% Use the article layout by default.
          \let\@lox@prtc\@lox@prtc@article%
          \let\@lox@psttc\@lox@psttc@article}}}}}

\@ifpackageloaded{tocbasic}{%
  \addtotoclist[fixme]{lox}%
  \renewcommand\lox@draft{\listoftoc[\@fxlistfixmename]{lox}}}{}
\ExecuteOptionsX[fx]<%
  mode,status,lang,log,note,face,layout,envlayout,targetlayout>{%
  mode=singleuser,%
  status=final,%
  lang=english,%
  langtrack=false,%
  defaultlang=english,%
  nosilent,%
  author=fixme,%
  target=thepage,%
  layout=margin,%
  innerlayout={layout=inline},%
  envlayout=plain,%
  targetlayout=plain,%
  inlineface=\bfseries,%
  marginface=\footnotesize,%
  envface=\bfseries,%
  targetface=\itshape}
\ProcessOptionsX*[fx]<%
  mode,status,lang,log,note,face,layout,envlayout,targetlayout>

\newcommand*\fxsetup[1]{%
  \@fxsetkeys{%
    mode,status,lang,log,note,face,layout,envlayout,targetlayout,theme}{%
    #1}}

\AtEndDocument{%
  \iffx@log@silent\else
    \GenericWarning{%
      (FiXme)\@spaces\@spaces}{%
      FiXme Summary: Number of notes: \thefxnotecount,\MessageBreak%
      Number of warnings: \thefxwarningcount,\MessageBreak%
      Number of errors: \thefxerrorcount,\MessageBreak%
      Number of fatal errors: \thefxfatalcount,\MessageBreak%
      Total: \thefixmecount\@gobble}%
  \fi}
\endinput
%%
%% End of file `fixme.sty'.
