%% Copyright (C) 2018 The University of Sheffield
%%               2018 The University of Paris-Sud
%%
%% License:
%%   This program can be redistributed and/or modified under the terms
%%   of the LaTeX Project Public License Distributed from CTAN
%%   archives in directory macros/latex/base/lppl.txt; either
%%   version 1 of the License, or any later version.
%%   OR
%%   The 2-clause BSD-style license.
%%  
%%   SPDX-License-Identifier: LPPL-1.0+ OR BSD-2-Clause

\NeedsTeXFormat{LaTeX2e}\relax
\ProvidesPackage{DOF-core}
  [0000/00/00 Unreleased v0.0.0+%
  Document-Type Support Framework for Isabelle.]

\RequirePackage{keycommand}
\RequirePackage{environ}
\RequirePackage{graphicx}
\RequirePackage{fp}

% Generic dispatcher
\newkeycommand+[\|]\isaDof[label=,type=,args={}][1]{%
\csname isaDof\commandkey{type}\endcsname[label=\commandkey{label},\commandkey{args}]{#1}%
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% begin: figure*
\NewEnviron{isamarkupfigure*}[1][]{\isaDof[#1]{\BODY}}
\expandafter\newkeycommand\csname isaDofIsa_DOF.figure\endcsname%
[label=,type=%
,Isa_DOF.figure.relative_width=%
,Isa_DOF.figure.placement=%
,Isa_DOF.figure.src=%
,Isa_DOF.figure.spawn_columns=enum False True%
][1]{%
  \gdef\DOF@src{\commandkey{Isa_DOF.figure.src}}%
  \begin{figure}[]
    \centering
    \ifcommandkey{Isa_DOF.figure.relative_width}
    {%
      \FPdiv\scale{\commandkey{Isa_DOF.figure.relative_width}}{100}
      \includegraphics[width=\scale\textwidth]{\DOF@src} 
    }{%
      \includegraphics[]{\DOF@src}
    } 
    \caption{#1}\label{\commandkey{label}}%
  \end{figure}
}
% end: figure*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% begin: side_by_side_figure*
\NewEnviron{isamarkupside_by_side_figure*}[1][]{\isaDof[#1]{\BODY}}
\expandafter\newkeycommand\csname isaDofIsa_DOF.side_by_side_figure\endcsname%
[label=,type=%
,Isa_DOF.figure.relative_width=%
,Isa_DOF.figure.src=%
,Isa_DOF.side_by_side_figure.anchor=%
,Isa_DOF.side_by_side_figure.caption=%
,Isa_DOF.side_by_side_figure.relative_width2=%
,Isa_DOF.side_by_side_figure.src2=%
,Isa_DOF.side_by_side_figure.anchor2=%
,Isa_DOF.side_by_side_figure.caption2=%
,Isa_DOF.side_by_side_figure.placement=%
,Isa_DOF.side_by_side_figure.spawn_columns=enum False True%
][1]{%
  \begin{figure}[]
  \gdef\DOF@src{\commandkey{Isa_DOF.figure.src}}%
  \gdef\DOF@srctwo{\commandkey{Isa_DOF.side_by_side_figure.src2}}%
  \subfloat[\label{\commandkey{Isa_DOF.side_by_side_figure.anchor}}\commandkey{Isa_DOF.side_by_side_figure.caption}]%
    {\ifcommandkey{Isa_DOF.figure.relative_width}%
      {%
        \FPdiv\scale{\commandkey{Isa_DOF.figure.relative_width}}{100}%
        \includegraphics[width=\scale\textwidth]{\DOF@src}% 
      }{%
        \includegraphics[]{\DOF@src}%
      }% 
    }%
    \hfill%
    \subfloat[\label{\commandkey{Isa_DOF.side_by_side_figure.anchor2}}\commandkey{Isa_DOF.side_by_side_figure.caption2}]%
    {\ifcommandkey{Isa_DOF.side_by_side_figure.relative_width2}%
      {%
        \FPdiv\scale{\commandkey{Isa_DOF.side_by_side_figure.relative_width2}}{100}%
        \includegraphics[width=\scale\textwidth]{\DOF@srctwo}% 
      }{%
        \includegraphics[]{\DOF@srctwo}%
      }% 
    }%
  \caption{#1}\label{\commandkey{label}}%
  \end{figure}
}
% end: side_by_side_figure*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% begin: Text*
\NewEnviron{isamarkupText*}[1][]{\isaDof[#1]{\BODY}}
\newkeycommand\isaDofText[label=,type=][1]{%
  \begin{isamarkuptext}%
      #1
  \end{isamarkuptext}%
}
% end: Text*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% begin: text*
\NewEnviron{isamarkuptext*}[1][]{\isaDof[#1]{\BODY}}
\newkeycommand\isaDoftext[label=,type=][1]{%
  \begin{isamarkuptext}%
      #1
  \end{isamarkuptext}%
}
% end: text*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newkeycommand\isaDofOpenMonitor[label=,type=]{}
\newkeycommand\isaDofCloseMonitor[label=,type=]{}

\newkeycommand\isaDofDeclareReferenceTextSection[label=,type=]{}
\newkeycommand\isaDofDeclareReferenceFigure[label=,type=]{}

\NewEnviron{isamarkupsection*}[1][]{\isaDof[#1]{\BODY}}
\NewEnviron{isamarkupsubsection*}[1][]{\isaDof[#1]{\BODY}}
