%% The LaTeX package genealogytree - version 2.00 (2020/06/19)
%% genealogytree.sty: genealogy trees (graphs)
%%
%% -------------------------------------------------------------------------------------------
%% Copyright (c) 2013-2020 by Prof. Dr. Dr. Thomas F. Sturm <thomas dot sturm at unibw dot de>
%% -------------------------------------------------------------------------------------------
%%
%% 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 `author-maintained'.
%%
%% This work consists of all files listed in README
%%
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{genealogytree}[2020/06/19 version 2.00 genealogy trees]
\def\gtr@version{2.00}

\RequirePackage{expl3}[2020/02/25]
\RequirePackage{xparse}
\RequirePackage{tcolorbox}[2020/04/28]

\tcbuselibrary{skins,fitting,external}
\usetikzlibrary{arrows.meta}
\usetikzlibrary{fit}

\def\gtr@warning#1{\PackageWarning{genealogytree}{#1}}
\def\gtr@error#1#2{\PackageError{genealogytree}{#1}{#2}}

\pgfkeys{/handlers/.gstore in/.code=\pgfkeysalso{\pgfkeyscurrentpath/.code=\gdef#1{##1}}}
\pgfkeys{/handlers/.xstore in/.code=\pgfkeysalso{\pgfkeyscurrentpath/.code=\xdef#1{##1}}}
\pgfkeys{/gtr/.is family}
\def\gtrset{\pgfqkeys{/gtr}}

\def\gtr@load@language@nil#1-#2\@nil{\gtruselibrary{lang.#1}}
\def\gtr@load@language#1{\gtr@load@language@nil#1-\@nil}%
\def\gtrloadlanguage#1{\forcsvlist{\gtr@load@language}{#1}}

\gtrset{
  code/.code={#1},
  keysfrom/.code={\pgfkeysalsofrom{#1}},
  language/.code={%
    \edef\gtrlanguagename{#1}%
    \gtr@load@language{#1}%
    \gtrset{language@=#1}%
  },
  language@/.is choice,
  language@/.unknown/.code={%
    \gtr@error{The language '\pgfkeyscurrentname' is unknown or not loaded}{%
      Set this language in the preamble or use '\string\gtrloadlanguage{\pgfkeyscurrentname}' in the preamble.}%
  },
}

\AtBeginDocument{%
  \gtrset{language/.code={%
      \edef\gtrlanguagename{#1}%
      \gtrset{language@=#1}%
  }}%
  \ifdefined\gtrlanguagename\else\gtrset{language=english}\fi}

\def\gtr@optionlist{}

\def\gtr@set@library@version#1{%
  \def\gtr@library@version{#1}%
  \typeout{Library (genealogytree): '\@currname' version '\gtr@library@version'}
  \gtr@check@library@version%
}

\def\gtr@check@library@version{%
  \ifx\gtr@library@version\gtr@version\else%
  \PackageError{genealogytree}{genealogytree version '\gtr@version' loads library '\@currname' with version '\gtr@library@version'}
  \fi%
}

\def\gtruselibrary#1{\gtrset{library/.cd,#1}}
\@onlypreamble\gtruselibrary

\providecommand{\gtrpkgprefix}{}

\def\gtr@load@library@#1#2#3{%
  \pgfkeysifdefined{/gtr/libload/#2}{}{%
    \pgfkeyssetvalue{/gtr/libload/#2}{}%
    \@pushfilename%
    \xdef\@currname{#3}%
    \makeatletter%
    #1%
    \@popfilename%
  }%
}

\def\gtr@load@library{\gtr@load@library@{%
  \def\gtr@library@version{-}%
  \input\gtrpkgprefix\@currname\relax%
  \gtr@check@library@version%
}}

\def\gtr@load@external@library{\gtr@load@library@{%
  \typeout{External library (genealogytree): '\@currname'}
  \input\@currname\relax%
}}

\gtrset{library/.unknown/.code={%
  \IfFileExists{gtrlib.\pgfkeyscurrentname.code.tex}%
    {\begingroup\edef\x{\endgroup\noexpand\gtr@load@external@library%
      {\pgfkeyscurrentname}{gtrlib.\pgfkeyscurrentname.code.tex}}\x}%
    {\gtr@error{The library '\pgfkeyscurrentname' is unknown}{Perhaps you misspelled it.}}%
}}

\def\gtr@add@library#1#2{%
  \gtrset{library/#1/.code={\gtr@load@library{#1}{#2}}}%
  \DeclareOption{#1}{\appto\gtr@optionlist{,#1}}%
}
\def\gtr@add@library@style#1#2{%
  \gtrset{library/#1/.style={#2}}%
  \DeclareOption{#1}{\appto\gtr@optionlist{,#1}}%
}

\gtr@add@library{core.parser}{gtrcore.parser.code.tex}
\gtr@add@library{core.processing}{gtrcore.processing.code.tex}
\gtr@add@library{core.contour}{gtrcore.contour.code.tex}
\gtr@add@library{core.node}{gtrcore.node.code.tex}
\gtr@add@library{core.drawing}{gtrcore.drawing.code.tex}
\gtr@add@library{core.options}{gtrcore.options.code.tex}
\gtr@add@library{core.symbols}{gtrcore.symbols.code.tex}

\gtr@add@library{lang.danish}{gtrlang.danish.code.tex}
\gtr@add@library{lang.dutch}{gtrlang.dutch.code.tex}
\gtr@add@library{lang.english}{gtrlang.english.code.tex}
\gtr@add@library{lang.french}{gtrlang.french.code.tex}
\gtr@add@library{lang.german}{gtrlang.german.code.tex}
\gtr@add@library{lang.italian}{gtrlang.italian.code.tex}
\gtr@add@library{lang.spanish}{gtrlang.spanish.code.tex}
\gtr@add@library{lang.swedish}{gtrlang.swedish.code.tex}

\gtr@add@library{debug}{gtrlib.debug.code.tex}
\gtr@add@library{templates}{gtrlib.templates.code.tex}
\gtr@add@library{fanchart}{gtrlib.fanchart.code.tex}

\gtr@add@library@style{all}{debug,templates,fanchart}

\ProcessOptions*

\gtruselibrary{
  core.parser,
  core.processing,
  core.contour,
  core.node,
  core.drawing,
  core.options,
  core.symbols,
  lang.english,
}

\begingroup\edef\x{\endgroup\noexpand\gtruselibrary{\gtr@optionlist}}\x
