% \iffalse meta-comment
%
% Copyright (C) 2021 by Jinwen XU 
% -------------------------------
% 
% This file may be distributed and/or modified under the conditions of the LaTeX
% Project Public License, either version 1.3c 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
%
% \fi
%
%<*driver>
\ProvidesFile{ProjLib.dtx}
%</driver>
\NeedsTeXFormat{LaTeX2e}[2020-10-01]
%
%<*ProjLib>
\ProvidesPackage{ProjLib}
    [2021/06/17 The collective interface of ProjLib toolkit]
%</ProjLib>
%
%<*PJLamssim>
\ProvidesPackage{PJLamssim}
    [2021/06/17 Simulate some features of amsart]
%</PJLamssim>
%
%<*PJLauthor>
\ProvidesPackage{PJLauthor}
    [2021/06/17 Enhanced author information block]
%</PJLauthor>
%
%<*PJLdate>
\ProvidesPackage{PJLdate}
    [2021/06/17 Convert yyyy-mm-dd to normal datetime format]
%</PJLdate>
%
%<*PJLdraft>
\ProvidesPackage{PJLdraft}
    [2021/06/17 Some useful macros for the draft stage]
%</PJLdraft>
%
%<*PJLlang>
\ProvidesPackage{PJLlang}
    [2021/06/17 Multi-language configuration]
%</PJLlang>
%
%<*PJLlogo>
\ProvidesPackage{PJLlogo}
    [2021/06/17 The ProjLib logo]
%</PJLlogo>
%
%<*PJLpaper>
\ProvidesPackage{PJLpaper}
    [2021/06/17 Paper style configuration]
%</PJLpaper>
%
%<*PJLthm>
\ProvidesPackage{PJLthm}
    [2021/06/17 Theorem setup and configuration]
%</PJLthm>
%
%<*PJLtoolkit>
\ProvidesPackage{PJLtoolkit}
    [2021/06/17 Collective interface of ProjLib Toolkit]
%</PJLtoolkit>
%
\RequirePackage{kvoptions}
\RequirePackage{etoolbox}
%
%<*PJLamssim>
\ifdefined\subjclass\endinput\fi

\RequirePackage{PJLauthor}
\RequirePackage{calc}

\providecommand{\conditionalbfseries}{\bfseries}

% keywords
\def\keywordsnameEN{\textsc{Key words and phrases}}
\def\keywordsnameFR{\textsc{Mots et phrases clés}}
\def\keywordsnameDE{\textsc{Schlüsselwörter und Phrasen}}
\def\keywordsnameIT{\textsc{Parole e frasi chiave}}
\def\keywordsnamePT{\textsc{Palavras e frases chave}}
\def\keywordsnameBR{\textsc{Palavras e frases chave}}
\def\keywordsnameES{\textsc{Palabras y frases clave}}
\def\keywordsnameCN{关键词}
\def\keywordsnameTC{關鍵詞}
\def\keywordsnameJP{キーワード}
\def\keywordsnameRU{Ключевые слова и фразы}

\ifdefined\keywords\else
    \def\PJL@keywords{}
    \newcommand*{\keywords}[1]{\def\PJL@keywords{#1}}
\fi

% dedicatory
\ifdefined\dedicatory\else
    \def\PJL@dedicatory{}
    \newcommand*{\dedicatory}[1]{\def\PJL@dedicatory{#1}}
\fi

% \thanks: behave like article-style when in \author, and ams-style (no marker) when outside
\AtEndPreamble{
% In case that \@author changes again
\let\footnotemark@PJLoriginal\footnotemark%
\let\footnotemark\relax%
\let\thanks@PJLoriginal\thanks%
\newlength\PJL@starlength
\setlength{\PJL@starlength}{\widthof{*}}
\newcommand*{\PJL@prethanks}[1]{\thanks@PJLoriginal{\hspace*{-\PJL@starlength}#1}}
% \renewcommand*{\thanks}[1]{%
%     \ifx#1\@empty\else%
%         \thanks@PJLoriginal{\hspace*{-\PJL@starlength}#1}%
%     \fi}
\renewcommand*{\thanks}[1]{%
    \ifx#1\@empty\else%
        \apptocmd{\@title}{%
            \thanks@PJLoriginal{\hspace*{-\PJL@starlength}#1}%
        }{}{\FAIL}%
    \fi}
\let\author@PJLoriginal\author
\renewcommand{\author}[1]{%
    \author@PJLoriginal{%
        \let\footnotemark\footnotemark@PJLoriginal%
        \let\thanks\thanks@PJLoriginal%
        #1%
        \let\footnotemark\relax%
    }%
}
% \pretocmd{\@author}{\let\footnotemark\footnotemark@PJLoriginal\let\thanks\thanks@PJLoriginal}{}{\FAIL}
% \apptocmd{\@author}{\let\footnotemark\relax}{}{\FAIL}
}

%% Modify abstract to allow it before maketitle
\let\abstract@PJLoriginal\abstract%
\let\endabstract@PJLoriginal\endabstract%
\newif\if@PJLamssim@maketitle\@PJLamssim@maketitlefalse
\newif\if@PJLamssim@absbefore\@PJLamssim@absbeforefalse
\RequirePackage{fancyvrb}
% Taken from https://tex.stackexchange.com/a/596328
% define the same as \protected@write, but with \immediate
\providecommand*\protected@iwrite[3]{%
  \begingroup
  \let\thepage\relax
  #2%
  \let\protect\@unexpandable@protect
  \edef\reserved@a{\immediate\write#1{#3}}\reserved@a
  \endgroup
  \if@nobreak\ifvmode\nobreak\fi\fi
}
\patchcmd{\FVB@VerbatimOut}
  {\immediate\write\FV@OutFile}
  {\protected@iwrite\FV@OutFile{}}
  {}{}
%
\renewenvironment{abstract}{%
    \VerbatimOut{\jobname.pjlabs}%
}{
    \endVerbatimOut%
    \if@PJLamssim@maketitle%
        \begin{abstract@PJLoriginal}%
            \input{\jobname.pjlabs}%
        \end{abstract@PJLoriginal}%
        % \ifx\PJL@keywords\@empty\else%
        %     \par\smallskip\noindent{\conditionalbfseries\csname keywordsname\csname\languagename ABBR\endcsname\endcsname.}~\PJL@keywords%
        % \fi%
    \else%
        \global\@PJLamssim@absbeforetrue%
    \fi%
}

%% Modify maketitle
\AtEndPreamble{%
% Add dedicatory to @maketitle
\patchcmd{\@maketitle}{\@date}{%
    \ifx\@date\@empty\vspace{-2\baselineskip}%
    \else\@date\fi%
    \ifx\PJL@dedicatory\@empty\else%
        \ifx\@date\@empty\vspace{2\baselineskip}\fi%
        \par\vspace{-\parskip}\bigskip%
        {\itshape\PJL@dedicatory}%
        \ifx\@date\@empty%
            \vspace{-1.7\baselineskip}%
            \vspace{-\parskip}%
        \fi%
    \fi%
}{}{\FAIL}
% Add keywords to maketitle
\pretocmd{\maketitle}{%
    \ifx\PJL@keywords\@empty\else%
    \PJL@prethanks{{\protect\conditionalbfseries%
    \csname keywordsname\csname\languagename ABBR\endcsname\endcsname.}%
    ~\PJL@keywords}%
    \fi}{}{\FAIL}
% Add abstract to maketitle
\apptocmd{\maketitle}{%
    \if@PJLamssim@absbefore%
        \begin{abstract@PJLoriginal}%
            \input{\jobname.pjlabs}%
            % \ifx\PJL@keywords\@empty\else%
            %     \par\smallskip\noindent{\conditionalbfseries\csname keywordsname\csname\languagename ABBR\endcsname\endcsname.}~\PJL@keywords%
            % \fi%
        \end{abstract@PJLoriginal}%
    \fi%
    \global\let\address\relax
    \global\let\curraddr\relax
    \global\let\email\relax
    \global\let\dedicatory\relax
    \global\let\keywords\relax
    \global\@PJLamssim@maketitletrue
}{}{\FAIL}
% Disbale the \newpage in maketitle
% \let\maketitle@PJLoriginal=\maketitle
% \renewcommand*{\maketitle}{{\let\newpage\relax\maketitle@PJLoriginal}}
}

\newcommand*\subjclass[2][2020]{%
    \def\@subjclass{#2}%
    \@ifundefined{subjclassname@#1}{%
        \ClassWarning{\@currname}{Unknown edition (#1) of Mathematics
        Subject Classification; using '2020'}%
        \expandafter\let\expandafter\subjclassname\csname subjclassname@2020\endcsname
    }{%
        \expandafter\let\expandafter\subjclassname\csname subjclassname@#1\endcsname
    }%
    \PJL@prethanks{{\itshape\subjclassname.}\enspace\@subjclass{}.}
}
\@namedef{subjclassname@1991}{%
  \textup{1991} Mathematics Subject Classification}
\@namedef{subjclassname@2000}{%
  \textup{2000} Mathematics Subject Classification}
\@namedef{subjclassname@2010}{%
  \textup{2010} Mathematics Subject Classification}
\@namedef{subjclassname@2020}{%
  \textup{2020} Mathematics Subject Classification}
%</PJLamssim>
%
%<*PJLauthor>
\ifdefined\subjclass\endinput\fi

\RequirePackage{PJLlang}

%%================================
%% Font and style
%%================================
\def\PJLauthor@font@author{\normalsize\normalfont\scshape}
\def\PJLauthor@font@address{\small\normalfont\itshape}
\def\PJLauthor@font@curraddr{\small\normalfont\itshape}
\def\PJLauthor@font@email{\small\normalfont\ttfamily}

%%================================
%% Lengths
%%================================
% Space between author and address
\newlength{\PJLauthor@length@innersep}
\setlength{\PJLauthor@length@innersep}{.3\baselineskip}

% Space between different author blocks
\newlength{\PJLauthor@length@sep}
\setlength{\PJLauthor@length@sep}{.5\baselineskip}

% Space between affiliation and date
\newlength{\PJLauthor@length@aftersep}
\setlength{\PJLauthor@length@aftersep}{.3\baselineskip}

%%================================
%% The macros
%%================================
\newif\if@PJLauthor@affilon
\renewcommand*{\author}[1]{%
    \gappto\@author{\phantom{A}\\[-\baselineskip]%
    \vspace{\PJLauthor@length@sep}%
    \PJLauthor@font@author{#1}\\\phantom{}
    \@PJLauthor@affilonfalse}}
\providecommand*{\address}[1]{%
    \gappto\@author{\phantom{A}\\[-\baselineskip]%
        \if@PJLauthor@affilon\else%
            \vspace{\PJLauthor@length@innersep}%
        \fi%
        \@PJLauthor@affilontrue%
        \PJLauthor@font@address{#1}\\\phantom{}}%
}
\providecommand*{\curraddr}[1]{%
    \gappto\@author{\phantom{A}\\[-\baselineskip]%
        \if@PJLauthor@affilon\else%
            \vspace{\PJLauthor@length@innersep}%
        \fi%
        \@PJLauthor@affilontrue%
        \PJLauthor@font@curraddr{#1}\\\phantom{}}%
}
\providecommand*{\email}[1]{%
    \gappto\@author{\phantom{A}\\[-\baselineskip]%
        \if@PJLauthor@affilon\else%
            \vspace{\PJLauthor@length@innersep}%
        \fi%
        \@PJLauthor@affilontrue%
        \PJLauthor@font@email{#1}\\\phantom{}}%
}

%%================================
%% Adjustment
%%================================
\patchcmd{\@maketitle}{\begin{tabular}[t]{c}}{}{}{}
\patchcmd{\@maketitle}{\end{tabular}}{}{}{}
\def\@author{} % Remove "No \author given."
\pretocmd{\@maketitle}{%
    \pretocmd{\@author}{\vspace{-\PJLauthor@length@sep}}{}{\FAIL}%
    \apptocmd{\@author}{%
% Fix the space caused by `\\\phantom{}`
        \vspace{-\baselineskip}%
        \if@PJLauthor@affilon%
            \vspace{\PJLauthor@length@aftersep}%
        \fi%
    }{}{\FAIL}%
}{}{\FAIL}
%</PJLauthor>
%
%<*PJLdate>
\SetupKeyvalOptions{
    family = @PJLdate,
    prefix = @PJLdate@,
}
\DeclareBoolOption[false]{draft}
\DeclareBoolOption[false]{fast}
\ProcessKeyvalOptions*\relax
\if@PJLdate@draft
    \@PJLdate@fasttrue
\fi
\DeclareDocumentCommand{\PLdate}{}{\PJLdate}
\if@PJLdate@fast\let\PJLdate\relax\endinput\fi

\RequirePackage{PJLlang}

% The following line is for "authblk"
\robustify\@latex@warning@no@line
\RequirePackage{silence}
\WarningFilter*{datetime2}{Date-Time Language Module}
\PassOptionsToPackage{fr-FR,en-US}{datetime2}
\RequirePackage{datetime2}
\RequirePackage{zhnumber}

\let\@DTMdate@PJLoriginal\@DTMdate
\gappto{\PJLlang@langconfig@common}{%
    \let\@DTMdate\@DTMdate@PJLoriginal%
}
\gappto{\PJLlang@langconfig@chinese}{%
    \renewcommand*{\@DTMdate}[1]{%
    \expandafter\@dtm@parsedate#1\@dtm@endparsedate%
    \zhdate{\@dtm@year/\@dtm@month/\@dtm@day}%
    }%
}
\gappto{\PJLlang@langconfig@tchinese}{%
    \renewcommand*{\@DTMdate}[1]{%
    \expandafter\@dtm@parsedate#1\@dtm@endparsedate%
    \zhdate{\@dtm@year/\@dtm@month/\@dtm@day}%
    }%
}
\gappto{\PJLlang@langconfig@japanese}{%
    \renewcommand*{\@DTMdate}[1]{%
    \expandafter\@dtm@parsedate#1\@dtm@endparsedate%
    \zhdate{\@dtm@year/\@dtm@month/\@dtm@day}%
    }%
}
\providecommand*{\PJLdate}[1]{\DTMdate{#1}}
%</PJLdate>
%
%<*PJLdraft>
\SetupKeyvalOptions{
    family = @PJLdraft,
    prefix = @PJLdraft@,
}
\DeclareBoolOption[false]{draft}
\DeclareBoolOption[false]{fast}
\ProcessKeyvalOptions*\relax
\if@PJLdraft@draft
    \@PJLdraft@fasttrue
\fi

\RequirePackage{PJLlang}
\RequirePackage{xcolor}

\def\dnfFont{\ttfamily}
\def\needgraphFont{\ttfamily}

\def\dnfTextEN{To be finished}
\def\needgraphTextEN{A graph is needed here}
\def\dnfTextFR{Pas encore fini}
\def\needgraphTextFR{Il manque une image ici}
\def\dnfTextDE{Nicht beendet}
\def\needgraphTextDE{Benötigen Sie ein Bild}
\def\dnfTextIT{Per essere finito}
\def\needgraphTextIT{Manca un'immagine qui}
\def\dnfTextPT{Não terminou}
\def\needgraphTextPT{Precisa de uma foto aqui}
\def\dnfTextBR{Não terminou}
\def\needgraphTextBR{Precisa de uma foto aqui}
\def\dnfTextES{Estar terminado}
\def\needgraphTextES{Falta una imagen aquí}
\def\dnfTextCN{这里尚未完成}
\def\needgraphTextCN{这里需要一张图片}
\def\dnfTextTC{這裡尚未完成}
\def\needgraphTextTC{這裡需要一張圖片}
\def\dnfTextJP{終わってない}
\def\needgraphTextJP{まだ画像が必要です}
\def\dnfTextRU{Не закончен}
\def\needgraphTextRU{Еще нужна картинка}

\definecolor{dnfColor}{RGB}{21,122,20}
\definecolor{needgraphColor}{RGB}{70,130,180}

\if@PJLdraft@fast
    \newcommand{\plainBox}[2][-paper]{\textcolor{#1}{%
    \setlength{\fboxsep}{1.5pt}%
    \setlength{\fboxrule}{1.2pt}%
    \fbox{#2}}}
\else
    \PassOptionsToPackage{many}{tcolorbox}
    \RequirePackage{tcolorbox}
    \newtcbox{\plainBox}[1][-paper]{enhanced jigsaw,%
        on line, arc = 1.2pt, outer arc = 1pt,breakable,%
        colframe = #1,colupper=#1,opacityback=0,%
        boxsep = 1pt,boxrule = 1.2pt,%
        left = 1pt, right = 1pt, top = 0pt, bottom = 0pt,%
    }
\fi

\newcounter{dnfcnt}
\newcounter{needgraphcnt}

\NewDocumentCommand{\dnf}{d<>}{%
    \noindent\plainBox[dnfColor]%
    {\normalfont\dnfFont\bfseries\small%
    \csname dnfText\csname\languagename ABBR\endcsname\endcsname%
    \stepcounter{dnfcnt}~\#\thednfcnt%
    \IfNoValueF{#1}{\,: #1}}%
}
\NewDocumentCommand{\needgraph}{d<>}{%
    \begin{center}%
        \plainBox[needgraphColor]%
        {\normalfont\needgraphFont\bfseries\small%
        \csname needgraphText\csname\languagename ABBR\endcsname\endcsname%
        \stepcounter{needgraphcnt}~\#\theneedgraphcnt%
        \IfNoValueF{#1}{\,: #1}}%
    \end{center}%
}
%</PJLdraft>
%
%<*PJLlang>
\SetupKeyvalOptions{%
    family = @PJLlang,
    prefix = @PJLlang@
}
\DeclareBoolOption[false]{polyglossia}
\ProcessKeyvalOptions*\relax

\newcommand\englishABBR{EN}
\newcommand\frenchABBR{FR}
\newcommand\ngermanABBR{DE}
\newcommand\italianABBR{IT}
\newcommand\portugueseABBR{PT}
\newcommand\brazilianABBR{BR}
\newcommand\spanishABBR{ES}
\newcommand\chineseABBR{CN}
\newcommand\tchineseABBR{TC}
\newcommand\japaneseABBR{JP}
\newcommand\russianABBR{RU}

\RequirePackage{iftex}
\ifPDFTeX
\RequirePackage[T1]{fontenc}
\RequirePackage{inputenc}
\fi

\if@PJLlang@polyglossia
    \RequirePackage{polyglossia}
    \setdefaultlanguage{english}
    \setotherlanguage[frenchpart=false]{french}
    \setotherlanguage{ngerman}
    \setotherlanguage{spanish}
    \setotherlanguage{portuguese}
    \setotherlanguage[variant=brazilian]{portuguese}
    \setotherlanguage{italian}
    \ifPDFTeX\else
        \setotherlanguage{russian}
        \setotherlanguage{japanese}
        \RequirePackage{silence}
        \WarningFilter{polyglossia}{Asking to add empty feature to latin font(Script="CJK" to scripttag "")}
    \fi
\else
    \ifPDFTeX\else
        \PassOptionsToPackage{japanese,russian}{babel}
    \fi
    \PassOptionsToPackage{italian,portuguese,brazilian,spanish,es-notilde,es-noquoting,ngerman,french,english,shorthands=off}{babel}
    \PassOptionsToPackage{italian,brazilian,spanish,ngerman,french,english}{cleveref}
    \RequirePackage{babel}
    \frenchsetup{PartNameFull=false}
\fi
%
\let\today@PJLoriginal\today
\newcommand{\PJLlang@langconfig@common}{%
    \ifdefined\DTMtoday%
        \let\today\DTMtoday%
    \else%
        \let\today\today@PJLoriginal%
    \fi%
}
\newcommand{\PJLlang@langconfig@chinese}{%
    \def\abstractname{摘要}%
    \def\proofname{证明}%
    \def\contentsname{目录}%
    \def\listfigurename{插图}%
    \def\listtablename{表格}%
    \def\figurename{图}%
    \def\tablename{表}%
    \def\indexname{索引}%
    \def\appendixname{附录}%
    \def\refname{参考文献}%
    \def\bibname{参考文献}%
    \let\today\zhtoday%
    \renewcommand{\languagename}{chinese}%
}
\newcommand{\PJLlang@langconfig@tchinese}{%
    \def\abstractname{摘要}%
    \def\proofname{證明}%
    \def\contentsname{目錄}%
    \def\listfigurename{插圖}%
    \def\listtablename{表格}%
    \def\figurename{圖}%
    \def\tablename{表}%
    \def\indexname{索引}%
    \def\appendixname{附錄}%
    \def\refname{參考文獻}%
    \def\bibname{參考文獻}%
    \let\today\zhtoday%
    \renewcommand{\languagename}{tchinese}%
}
\newcommand{\PJLlang@langconfig@japanese}{%
    \selectlanguage{japanese}%
}
\newcommand{\PJLlang@langconfig@english}{%
    \selectlanguage{english}%
}
\newcommand{\PJLlang@langconfig@french}{%
    \selectlanguage{french}%
% The line below is currently only needed for 'babel', but also works with 'polyglossia'
    \def\frenchpartname{Partie}%
}
\newcommand{\PJLlang@langconfig@german}{%
    \selectlanguage{ngerman}%
}
\newcommand{\PJLlang@langconfig@italian}{%
    \selectlanguage{italian}%
}
\newcommand{\PJLlang@langconfig@portuguese}{%
    \selectlanguage{portuguese}%
}
\newcommand{\PJLlang@langconfig@brazilian}{%
    \selectlanguage{brazilian}%
}
\newcommand{\PJLlang@langconfig@spanish}{%
    \selectlanguage{spanish}%
}
\newcommand{\PJLlang@langconfig@russian}{%
    \selectlanguage{russian}%
}

\RequirePackage{xstring}
\NewDocumentCommand\AddLanguageSetting{d()m}{%
\IfNoValueTF{#1}%
    {\gappto{\PJLlang@langconfig@common}{#2}}%
    {%
        \lowercase{\IfStrEqCase{#1}}{%
            {cn}{\gappto{\PJLlang@langconfig@chinese}{#2}}%
            {chinese}{\gappto{\PJLlang@langconfig@chinese}{#2}}%
            {schinese}{\gappto{\PJLlang@langconfig@chinese}{#2}}%
            {simplifiedchinese}{\gappto{\PJLlang@langconfig@chinese}{#2}}%
            {tc}{\gappto{\PJLlang@langconfig@tchinese}{#2}}%
            {tchinese}{\gappto{\PJLlang@langconfig@tchinese}{#2}}%
            {traditionalchinese}{\gappto{\PJLlang@langconfig@tchinese}{#2}}%
            {jp}{\gappto{\PJLlang@langconfig@japanese}{#2}}%
            {japanese}{\gappto{\PJLlang@langconfig@japanese}{#2}}%
            {en}{\gappto{\PJLlang@langconfig@english}{#2}}%
            {english}{\gappto{\PJLlang@langconfig@english}{#2}}%
            {fr}{\gappto{\PJLlang@langconfig@french}{#2}}%
            {french}{\gappto{\PJLlang@langconfig@french}{#2}}%
            {de}{\gappto{\PJLlang@langconfig@german}{#2}}%
            {ngerman}{\gappto{\PJLlang@langconfig@german}{#2}}%
            {it}{\gappto{\PJLlang@langconfig@italian}{#2}}%
            {italian}{\gappto{\PJLlang@langconfig@italian}{#2}}%
            {pt}{\gappto{\PJLlang@langconfig@portuguese}{#2}}%
            {portuguese}{\gappto{\PJLlang@langconfig@portuguese}{#2}}%
            {br}{\gappto{\PJLlang@langconfig@brazilian}{#2}}%
            {brazilian}{\gappto{\PJLlang@langconfig@brazilian}{#2}}%
            {es}{\gappto{\PJLlang@langconfig@spanish}{#2}}%
            {spanish}{\gappto{\PJLlang@langconfig@spanish}{#2}}%
            {german}{\gappto{\PJLlang@langconfig@german}{#2}}%
            {ru}{\gappto{\PJLlang@langconfig@russian}{#2}}%
            {russian}{\gappto{\PJLlang@langconfig@russian}{#2}}%
        }%
    }%
}

\RequirePackage{setspace}
% Line spacing configuration
\def\PJL@config@linespacing{\setstretch{1.00}}
\def\PJL@config@CJKlinespacing{\onehalfspacing}
\newcommand{\PJLsetlinespacing}[1]{\renewcommand{\PJL@config@linespacing}{#1}}
\newcommand{\PJLsetCJKlinespacing}[1]{\renewcommand{\PJL@config@CJKlinespacing}{#1}}
% Parindent configuration
\def\PJL@config@parindent{\ltx@ifpackageloaded{parskip}{}{\setlength{\parindent}{1.5em}}}
\def\PJL@config@CJKparindent{\ltx@ifpackageloaded{parskip}{}{\setlength{\parindent}{2em}}}
\newcommand{\PJLsetparindent}[1]{\renewcommand{\PJL@config@parindent}{\ltx@ifpackageloaded{parskip}{}{\setlength{\parindent}{#1}}}}
\newcommand{\PJLsetCJKparindent}[1]{\renewcommand{\PJL@config@CJKparindent}{\ltx@ifpackageloaded{parskip}{}{\setlength{\parindent}{#1}}}}
% All-in-all configuration
\def\PJL@config@CJK{\PJL@config@CJKlinespacing\PJL@config@CJKparindent}
\def\PJL@config@Latin{\PJL@config@linespacing\PJL@config@parindent}
%
\newcommand{\UseLanguageCORE}[1]{%
    \PJLlang@langconfig@common%
    \lowercase{\IfStrEqCase{#1}}{%
        {cn}{\PJL@config@CJK\PJLlang@langconfig@chinese}%
        {chinese}{\PJL@config@CJK\PJLlang@langconfig@chinese}%
        {schinese}{\PJL@config@CJK\PJLlang@langconfig@chinese}%
        {simplifiedchinese}{\PJL@config@CJK\PJLlang@langconfig@chinese}%
        {tc}{\PJL@config@CJK\PJLlang@langconfig@tchinese}%
        {tchinese}{\PJL@config@CJK\PJLlang@langconfig@tchinese}%
        {traditionalchinese}{\PJL@config@CJK\PJLlang@langconfig@tchinese}%
        {jp}{\PJL@config@CJK\PJLlang@langconfig@japanese}%
        {japanese}{\PJL@config@CJK\PJLlang@langconfig@japanese}%
        {en}{\PJL@config@Latin\PJLlang@langconfig@english}%
        {english}{\PJL@config@Latin\PJLlang@langconfig@english}%
        {fr}{\PJL@config@Latin\PJLlang@langconfig@french}%
        {french}{\PJL@config@Latin\PJLlang@langconfig@french}%
        {de}{\PJL@config@Latin\PJLlang@langconfig@german}%
        {ngerman}{\PJL@config@Latin\PJLlang@langconfig@german}%
        {german}{\PJL@config@Latin\PJLlang@langconfig@german}%
        {it}{\PJL@config@Latin\PJLlang@langconfig@italian}%
        {italian}{\PJL@config@Latin\PJLlang@langconfig@italian}%
        {pt}{\PJL@config@Latin\PJLlang@langconfig@portuguese}%
        {portuguese}{\PJL@config@Latin\PJLlang@langconfig@portuguese}%
        {br}{\PJL@config@Latin\PJLlang@langconfig@brazilian}%
        {brazilian}{\PJL@config@Latin\PJLlang@langconfig@brazilian}%
        {es}{\PJL@config@Latin\PJLlang@langconfig@spanish}%
        {spanish}{\PJL@config@Latin\PJLlang@langconfig@spanish}%
        {ru}{\PJL@config@Latin\PJLlang@langconfig@russian}%
        {russian}{\PJL@config@Latin\PJLlang@langconfig@russian}%
    }%
}
\newcommand{\UseLanguage}[1]{%
    \ifx\@onlypreamble\@notprerr%
        \UseLanguageCORE{#1}%
    \else%
        \AfterEndPreamble{\UseLanguageCORE{#1}}%
    \fi%
}
\newcommand{\UseOtherLanguage}[2]{%
\begingroup%
    \PJLlang@langconfig@common%
    \lowercase{\IfStrEqCase{#1}}{%
        {cn}{\PJLlang@langconfig@chinese}%
        {chinese}{\PJLlang@langconfig@chinese}%
        {schinese}{\PJLlang@langconfig@chinese}%
        {simplifiedchinese}{\PJLlang@langconfig@chinese}%
        {tc}{\PJLlang@langconfig@tchinese}%
        {tchinese}{\PJLlang@langconfig@tchinese}%
        {traditionalchinese}{\PJLlang@langconfig@tchinese}%
        {jp}{\PJLlang@langconfig@japanese}%
        {japanese}{\PJLlang@langconfig@japanese}%
        {en}{\PJLlang@langconfig@english}%
        {english}{\PJLlang@langconfig@english}%
        {fr}{\PJLlang@langconfig@french}%
        {french}{\PJLlang@langconfig@french}%
        {de}{\PJLlang@langconfig@german}%
        {ngerman}{\PJLlang@langconfig@german}%
        {german}{\PJLlang@langconfig@german}%
        {it}{\PJLlang@langconfig@italian}%
        {italian}{\PJLlang@langconfig@italian}%
        {pt}{\PJLlang@langconfig@portuguese}%
        {portuguese}{\PJLlang@langconfig@portuguese}%
        {br}{\PJLlang@langconfig@brazilian}%
        {brazilian}{\PJLlang@langconfig@brazilian}%
        {es}{\PJLlang@langconfig@spanish}%
        {spanish}{\PJLlang@langconfig@spanish}%
        {ru}{\PJLlang@langconfig@russian}%
        {russian}{\PJLlang@langconfig@russian}%
    }%
    #2%
\endgroup%
}

\UseLanguage{English}
%</PJLlang>
%
%<*PJLlogo>
\SetupKeyvalOptions{
    family = @PJLlogo,
    prefix = @PJLlogo@,
}
\DeclareBoolOption[false]{draft}
\DeclareBoolOption[false]{fast}
\ProcessKeyvalOptions*\relax
\if@PJLlogo@draft
    \@PJLlogo@fasttrue
\fi
\if@PJLlogo@fast\def\ProjLib{{\normalfont ProjLib}}\endinput\fi

\RequirePackage{xcolor}
\RequirePackage{graphicx}
\ifdefined\fontspec
  \newfontface{\PJLlogo@font}{LinBiolinum_R.otf}
\else
  \RequirePackage[T1]{fontenc}
  \newcommand{\PJLlogo@font}{\fontfamily{LinuxBiolinumT-TLF}\selectfont}
\fi

\newcommand{\PJLSigmaJ}{%
  \vbox{\offinterlineskip
    \ialign{%
      \hfil##\hfil\cr
      \hidewidth\hskip0.15ex\scalebox{0.4}{\rotatebox{-10}{\usefont{U}{zeur}{b}{n}\symbol{"06}}}\hidewidth\cr
      \noalign{\kern0.15ex}
      \j\cr
    }%
  }%
}

\newcommand{\ProjLib@generic}[1]{%
  \begingroup
  \normalfont\PJLlogo@font
  \textcolor{blue!60!cyan}{P}%
  \textcolor{blue!45!cyan}{r}%
  \textcolor{blue!30!cyan}{o}%
  \textcolor{green!70!black}{#1}%
  \textcolor{red!20!yellow}{L}%
  \textcolor{red!40!yellow}{i}%
  \textcolor{red!60!yellow}{b}%
  \endgroup
}
\DeclareRobustCommand*{\ProjLib}{\ProjLib@generic{\PJLSigmaJ}}
\DeclareRobustCommand*{\ProjLibText}{\ProjLib@generic{j}}
%</PJLlogo>
%
%<*PJLpaper>
\RequirePackage{ifthen}

\SetupKeyvalOptions{%
    family = @PJLpaper,
    prefix = @PJLpaper@,
    setkeys=\kvsetkeys
}

\DeclareStringOption[normal]{paperstyle}
\DeclareVoidOption{yellowpaper}{\kvsetkeys{@PJLpaper}{paperstyle=yellow}}
\DeclareVoidOption{darkpaper}{\kvsetkeys{@PJLpaper}{paperstyle=dark}}
\DeclareVoidOption{nordpaper}{\kvsetkeys{@PJLpaper}{paperstyle=nord}}
\DeclareBoolOption[false]{preview}

\ProcessKeyvalOptions*\relax

%%================================
%% Preview mode
%%================================
\ifdefined\PJLnoPreview\else%
    \if@PJLpaper@preview%
        \RequirePackage{calc}
        \AtEndPreamble{%
        \setlength{\paperwidth}{\textwidth*\real{1.05}}%
        \setlength{\paperheight}{%
        (\textheight+\headheight+\headsep+\footskip)*\real{1.05}}%
        \setlength{\oddsidemargin}{(\paperwidth-\textwidth)/2-1in}%
        \setlength{\evensidemargin}{(\paperwidth-\textwidth)/2-1in}%
        \setlength{\topmargin}{(\paperheight-\textheight-\headheight-\headsep-\footskip)/2- 1in}%
        }
    \fi
\fi

%%================================
%% Paper color
%%================================
\RequirePackage{xcolor}
\definecolor{paper}{RGB}{255,255,255}
\definecolor{maintext}{RGB}{0,0,0}

\ifthenelse{\equal{\@PJLpaper@paperstyle}{yellow}}
{
    \definecolor{paper}{RGB}{247,246,233}
}
{\relax}

\ifthenelse{\equal{\@PJLpaper@paperstyle}{dark}}
{
    \definecolor{paper}{RGB}{30,30,30}
    \definecolor{maintext}{RGB}{207,207,207}
}
{\relax}

\ifthenelse{\equal{\@PJLpaper@paperstyle}{nord}}
{
    \definecolor{paper}{RGB}{46,52,64}
    \definecolor{maintext}{RGB}{214,220,230}
}
{\relax}

\newcommand{\PJLglobalcolor}[1]{%
    \color{#1}\global\let\default@color\current@color
}

\pagecolor{paper}
\PJLglobalcolor{maintext}
\AtEndPreamble{
\ifdefined\tcbset%
    \tcbset{colupper=maintext,collower=maintext}
\fi
}
%</PJLpaper>
%
%<*PJLthm>
\SetupKeyvalOptions{%
    family = @PJLthm,
    prefix = @PJLthm@
}
\DeclareBoolOption[false]{nothms}
\DeclareBoolOption[false]{draft}
\DeclareBoolOption[false]{fast}
\DeclareBoolOption[false]{regionalref}
\ProcessKeyvalOptions*\relax
\if@PJLthm@draft
    \@PJLthm@fasttrue
\fi
\if@PJLthm@fast
    \@PJLthm@regionalreftrue
\fi

\RequirePackage{PJLlang}
\RequirePackage{amsmath,amsthm}
\RequirePackage{aliascnt}
\PassOptionsToPackage{nameinlink}{cleveref}
\RequirePackage{cleveref}

% Macro for naming theorems
\NewDocumentCommand{\NameTheorem}{omm}{%
    \protected@edef\PJLthm@temp{#2}%
    \expandafter\IfEndWith\expandafter{\PJLthm@temp}{*}{%
        \expandafter\StrGobbleRight\expandafter{\PJLthm@temp}{1}[\PJLthm@temp]%
    }{}%
    \IfValueTF{#1}{%
        \lowercase{\IfStrEqCase{#1}}{%
            {cn}{\def\PJL@temp@abbr{CN}}%
            {chinese}{\def\PJL@temp@abbr{CN}}%
            {schinese}{\def\PJL@temp@abbr{CN}}%
            {simplifiedchinese}{\def\PJL@temp@abbr{CN}}%
            {tc}{\def\PJL@temp@abbr{TC}}%
            {tchinese}{\def\PJL@temp@abbr{TC}}%
            {traditionalchinese}{\def\PJL@temp@abbr{TC}}%
            {jp}{\def\PJL@temp@abbr{JP}}%
            {japanese}{\def\PJL@temp@abbr{JP}}%
            {en}{\def\PJL@temp@abbr{EN}}%
            {english}{\def\PJL@temp@abbr{EN}}%
            {fr}{\def\PJL@temp@abbr{FR}}%
            {french}{\def\PJL@temp@abbr{FR}}%
            {de}{\def\PJL@temp@abbr{DE}}%
            {ngerman}{\def\PJL@temp@abbr{DE}}%
            {german}{\def\PJL@temp@abbr{DE}}%
            {it}{\def\PJL@temp@abbr{IT}}%
            {italian}{\def\PJL@temp@abbr{IT}}%
            {pt}{\def\PJL@temp@abbr{PT}}%
            {portuguese}{\def\PJL@temp@abbr{PT}}%
            {br}{\def\PJL@temp@abbr{BR}}%
            {brazilian}{\def\PJL@temp@abbr{BR}}%
            {es}{\def\PJL@temp@abbr{ES}}%
            {spanish}{\def\PJL@temp@abbr{ES}}%
            {ru}{\def\PJL@temp@abbr{RU}}%
            {russian}{\def\PJL@temp@abbr{RU}}%
        }%
        \expandafter\def\csname\PJLthm@temp name\PJL@temp@abbr\endcsname{#3}%
    }{%
        \expandafter\def\csname\PJLthm@temp nameEN\endcsname{#3}%
        \expandafter\def\csname\PJLthm@temp nameFR\endcsname{#3}%
        \expandafter\def\csname\PJLthm@temp nameDE\endcsname{#3}%
        \expandafter\def\csname\PJLthm@temp nameIT\endcsname{#3}%
        \expandafter\def\csname\PJLthm@temp namePT\endcsname{#3}%
        \expandafter\def\csname\PJLthm@temp nameBR\endcsname{#3}%
        \expandafter\def\csname\PJLthm@temp nameES\endcsname{#3}%
        \expandafter\def\csname\PJLthm@temp nameCN\endcsname{#3}%
        \expandafter\def\csname\PJLthm@temp nameTC\endcsname{#3}%
        \expandafter\def\csname\PJLthm@temp nameJP\endcsname{#3}%
        \expandafter\def\csname\PJLthm@temp nameRU\endcsname{#3}%
    }%
}

% Macro for creating theorems
\RequirePackage{xstring}
\newcommand\PassFirstToSecond[2]{#2{#1}}%
\NewDocumentCommand{\CreateTheorem}{sm}{%
    \begingroup
    \protected@edef\PJLthm@temp{#2}%
    \expandafter\IfEndWith\expandafter{\PJLthm@temp}{*}{%
        \expandafter\StrGobbleRight\expandafter{\PJLthm@temp}{1}[\PJLthm@temp]%
        \PassFirstToSecond{*}%
    }{%
        \PassFirstToSecond{}%
    }%
    {\expandafter\PassFirstToSecond%
        \expandafter{\PJLthm@temp}{\endgroup\InnerCreateTheorem{#1}}}%
}%
\if@PJLthm@regionalref
\NewDocumentCommand{\InnerCreateTheorem}{mmmod<>d()}{%
% #1 = star or no star
% #2 = name of environment
% #3 = emptiness or star to append to name of environment
% #4 = numbered like
% #5 = numbered within
% #6 = existed environment
    \IfBooleanTF{#1}{%
        \IfValueTF{#4}
            {\@firstoftwo}
            {\IfValueTF{#5}{\@firstoftwo}{\@secondoftwo}}%
    }{%
        \IfValueTF{#4}
            {\IfValueTF{#5}{\@firstoftwo}{\@secondoftwo}}{
            \@secondoftwo}
    }%
    {%
        \GenericError{}%
        {\string\CreateTheorem\space syntax error\on@line}{%
        You cannot call the starred variant with optional argument,\MessageBreak
        nor call the unstarred variant with several optional arguments.}%
        {}%
    }{%
        \IfValueTF{#6}{%
            \IfBooleanTF{#1}{%
                \ifcsmacro{#2#3}%
                {\renewenvironment{#2#3}{\begin{#6*}}{\end{#6*}}}%
                {\newenvironment{#2#3}{\begin{#6*}}{\end{#6*}}}%
            }{%
                \ifcsmacro{#2#3}%
                {\renewenvironment{#2#3}{\begin{#6}}{\end{#6}}}%
                {\newenvironment{#2#3}{\begin{#6}}{\end{#6}}}%
            }
        }{%
            \IfBooleanTF{#1}{%
                \newtheorem*{#2#3}{\csname#2name\csname\languagename ABBR\endcsname\endcsname}
            }{%
                \IfValueTF{#5}{%
                    \newtheorem{PJL#2#3}{\csname#2name\csname\languagename ABBR\endcsname\endcsname}[#5]%
                    \newaliascnt{#2#3}{PJL#2#3}%
                }{%
                    \IfValueTF{#4}{%
                            \newtheorem{PJL#2#3}[#4]{\csname#2name\csname\languagename ABBR\endcsname\endcsname}
                        }{%
                            \newtheorem{PJL#2#3}{\csname#2name\csname\languagename ABBR\endcsname\endcsname}  
                            \newaliascnt{#2#3}{PJL#2#3}%
                        }%
                }%
                \crefname{PJL#2#3}%
                    {\csname#2name\csname\languagename ABBR\endcsname\endcsname}%
                    {\csname#2name\csname\languagename ABBR\endcsname\endcsname}%
                \Crefname{PJL#2#3}%
                    {\csname#2name\csname\languagename ABBR\endcsname\endcsname}%
                    {\csname#2name\csname\languagename ABBR\endcsname\endcsname}%
                \NewDocumentEnvironment{#2#3}{}
                    {\begin{PJL#2#3}}
                    {\end{PJL#2#3}}
            }%
        }%
    }%
}%
\else
\NewDocumentCommand{\InnerCreateTheorem}{mmmod<>d()}{%
% #1 = Tokens denoting an xparse-boolean value;
%      value "true" -> the call was \CreateTheorem*{...}...
%      value "false" -> the call was \CreateTheorem{...}...
%      This indicates whether the "starred" variant or the
%      "unstarred" variant of \CreateTheorem was called.
% #2 = Name of environment to define. One trailing
%      star is removed from the environment-name provided 
%      to \CreateTheorem if that environment-name has
%      trailing stars.
% #3 = If the environment-name provided to \CreateTheorem has
%      trailing stars: A star (*).
%      If the environment-name provided to \CreateTheorem has
%      no trailing stars: Empty/no tokens at all.
% #4 = numbered like=name of counter like which the environment
%      shall be numbered.
% #5 = numbered within=name of counter which is superordinate
%      to the environment's counter and whose stepping resets
%      the environment's counter.
% #6 = existed environment name (the environment to copy)
    \IfBooleanTF{#1}{%
        \IfValueTF{#4}
            {\@firstoftwo}
            {\IfValueTF{#5}{\@firstoftwo}{\@secondoftwo}}%
    }{%
        \IfValueTF{#4}
            {\IfValueTF{#5}{\@firstoftwo}{\@secondoftwo}}{
            \@secondoftwo}
    }%
    {%
        \GenericError{}%
        {\string\CreateTheorem\space syntax error\on@line}{%
        You cannot call the starred variant with optional argument,\MessageBreak
        nor call the unstarred variant with several optional arguments.}%
        {%
            Allowed usage:\MessageBreak\MessageBreak
            \CreateTheorem*{(name of environment)}\MessageBreak
            \CreateTheorem{(name of environment)}\MessageBreak
            \CreateTheorem{(name of environment)}[(numbered like)]\MessageBreak
            \CreateTheorem{(name of environment)}<(numbered within)>\MessageBreak
            \CreateTheorem{(name of environment)}((existed environment))\MessageBreak
        }%
    }{%
        \IfValueTF{#6}{%
            \IfBooleanTF{#1}{%
                \ifcsmacro{#2#3}%
                {\renewenvironment{#2#3}{\begin{#6*}}{\end{#6*}}}%
                {\newenvironment{#2#3}{\begin{#6*}}{\end{#6*}}}%
            }{%
                \ifcsmacro{#2#3}%
                {\renewenvironment{#2#3}{\begin{#6}}{\end{#6}}}%
                {\newenvironment{#2#3}{\begin{#6}}{\end{#6}}}%
            }
        }{%
            \IfBooleanTF{#1}{%
%                 \newtheorem*{#2EN#3}{\csname#2nameEN\endcsname}%
%                 \newtheorem*{#2FR#3}{\csname#2nameFR\endcsname}%
%                 \newtheorem*{#2DE#3}{\csname#2nameDE\endcsname}%
%                 \newtheorem*{#2IT#3}{\csname#2nameIT\endcsname}%
%                 \newtheorem*{#2PT#3}{\csname#2namePT\endcsname}%
%                 \newtheorem*{#2BR#3}{\csname#2nameBR\endcsname}%
%                 \newtheorem*{#2ES#3}{\csname#2nameES\endcsname}%
%                 \newtheorem*{#2CN#3}{\csname#2nameCN\endcsname}%
%                 \newtheorem*{#2TC#3}{\csname#2nameTC\endcsname}%
%                 \newtheorem*{#2JP#3}{\csname#2nameJP\endcsname}%
%                 \newtheorem*{#2RU#3}{\csname#2nameRU\endcsname}%
                \expandafter\PassFirstToSecond\expandafter{\csname#2nameEN\endcsname}{\newtheorem*{#2EN#3}}%
                \expandafter\PassFirstToSecond\expandafter{\csname#2nameFR\endcsname}{\newtheorem*{#2FR#3}}%
                \expandafter\PassFirstToSecond\expandafter{\csname#2nameDE\endcsname}{\newtheorem*{#2DE#3}}%
                \expandafter\PassFirstToSecond\expandafter{\csname#2nameIT\endcsname}{\newtheorem*{#2IT#3}}%
                \expandafter\PassFirstToSecond\expandafter{\csname#2namePT\endcsname}{\newtheorem*{#2PT#3}}%
                \expandafter\PassFirstToSecond\expandafter{\csname#2nameBR\endcsname}{\newtheorem*{#2BR#3}}%
                \expandafter\PassFirstToSecond\expandafter{\csname#2nameES\endcsname}{\newtheorem*{#2ES#3}}%
                \expandafter\PassFirstToSecond\expandafter{\csname#2nameCN\endcsname}{\newtheorem*{#2CN#3}}%
                \expandafter\PassFirstToSecond\expandafter{\csname#2nameTC\endcsname}{\newtheorem*{#2TC#3}}%
                \expandafter\PassFirstToSecond\expandafter{\csname#2nameJP\endcsname}{\newtheorem*{#2JP#3}}%
                \expandafter\PassFirstToSecond\expandafter{\csname#2nameRU\endcsname}{\newtheorem*{#2RU#3}}%
            }{%
                \IfValueTF{#5}{%
                    \newcounter{#2#3}[{#5}]%
                    \expandafter\renewcommand\expandafter*%
                        \csname the#2#3\expandafter\endcsname%
                        \expandafter{\csname the#5\endcsname.\arabic{#2#3}}%
                }{%
                    \IfValueTF{#4}
                        {\newaliascnt{#2#3}{#4}}
                        {\newcounter{#2#3}}%
                }%
                %---------------------------------------------------------------
                \CreateTheoremNumberedLikeAliasCounter{#2}{EN}{#3}%
                \CreateTheoremNumberedLikeAliasCounter{#2}{FR}{#3}%
                \CreateTheoremNumberedLikeAliasCounter{#2}{DE}{#3}%
                \CreateTheoremNumberedLikeAliasCounter{#2}{IT}{#3}%
                \CreateTheoremNumberedLikeAliasCounter{#2}{PT}{#3}%
                \CreateTheoremNumberedLikeAliasCounter{#2}{BR}{#3}%
                \CreateTheoremNumberedLikeAliasCounter{#2}{ES}{#3}%
                \CreateTheoremNumberedLikeAliasCounter{#2}{CN}{#3}%
                \CreateTheoremNumberedLikeAliasCounter{#2}{TC}{#3}%
                \CreateTheoremNumberedLikeAliasCounter{#2}{JP}{#3}%
                \CreateTheoremNumberedLikeAliasCounter{#2}{RU}{#3}%
                %---------------------------------------------------------------
            }%
            \NewDocumentEnvironment{#2#3}{}
                {\csname#2\csname\languagename ABBR\endcsname#3\endcsname}%
                {\csname end#2\csname\languagename ABBR\endcsname#3\endcsname}%
        }%
    }%
}%
\NewDocumentCommand{\CreateTheoremNumberedLikeAliasCounter}{mmm}{%
    \newaliascnt{#1#2#3}{#1#3}%
%     \newtheorem{#1#2#3}[{#1#2#3}]{\csname#1name#2\endcsname}%
    \expandafter\PassFirstToSecond\expandafter{\csname#1name#2\endcsname}{\newtheorem{#1#2#3}[{#1#2#3}]}%
    \aliascntresetthe{#1#2#3}%
%     \crefname{#1#2#3}%
%         {\csname#1name#2\endcsname}%
%         {\csname#1name#2\endcsname}%
%     \Crefname{#1#2#3}%
%         {\csname#1name#2\endcsname}%
%         {\csname#1name#2\endcsname}%
    \expandafter\PassFirstToSecond\expandafter{\csname#1name#2\endcsname}%
    {%
        \expandafter\PassFirstToSecond\expandafter{\csname#1name#2\endcsname}%
        {\crefname{#1#2#3}}%
    }%
    \expandafter\PassFirstToSecond\expandafter{\csname#1name#2\endcsname}%
    {%
        \expandafter\PassFirstToSecond\expandafter{\csname#1name#2\endcsname}%
        {\Crefname{#1#2#3}}%
    }%
}%
\fi

%% English theorems names
\def\theoremnameEN{{Theorem}}
\def\lemmanameEN{{Lemma}}
\def\propositionnameEN{{Proposition}}
\def\corollarynameEN{{Corollary}}
\def\propertynameEN{{Property}}
\def\factnameEN{{Fact}}
\def\conjecturenameEN{{Conjecture}}
\def\definitionnameEN{{Definition}}
\def\axiomnameEN{{Axiom}}
\def\assumptionnameEN{{Assumption}}
\def\conventionnameEN{{Convention}}
\def\hypothesisnameEN{{Hypothesis}}
\def\notationnameEN{{Notation}}
\def\examplenameEN{{Example}}
\def\problemnameEN{{Problem}}
\def\questionnameEN{{Question}}
\def\exercisenameEN{{Exercise}}
\def\remarknameEN{{Remark}}
\def\observationnameEN{{Observation}}
\expandafter\def\csname definition-propositionnameEN\endcsname{\definitionnameEN-\propositionnameEN}
\expandafter\def\csname definition-theoremnameEN\endcsname{\definitionnameEN-\theoremnameEN}

%% French theorems names
\def\theoremnameFR{{Théorème}}
\def\lemmanameFR{{Lemme}}
\def\propositionnameFR{{Proposition}}
\def\corollarynameFR{{Corollaire}}
\def\propertynameFR{{Propriété}}
\def\factnameFR{{Fait}}
\def\conjecturenameFR{{Conjecture}}
\def\definitionnameFR{{Définition}}
\def\axiomnameFR{{Axiome}}
\def\assumptionnameFR{{Supposition}}
\def\conventionnameFR{{Convention}}
\def\hypothesisnameFR{{Hypothèse}}
\def\notationnameFR{{Notation}}
\def\examplenameFR{{Exemple}}
\def\problemnameFR{{Problème}}
\def\questionnameFR{{Question}}
\def\exercisenameFR{{Exercice}}
\def\remarknameFR{{Remarque}}
\def\observationnameFR{{Observation}}
\expandafter\def\csname definition-propositionnameFR\endcsname{\definitionnameFR-\propositionnameFR}
\expandafter\def\csname definition-theoremnameFR\endcsname{\definitionnameFR-\theoremnameFR}

%% German theorems names
\def\theoremnameDE{{Satz}}
\def\lemmanameDE{{Lemma}}
\def\propositionnameDE{{Proposition}}
\def\corollarynameDE{{Korollar}}
\def\propertynameDE{{Eigenschaft}}
\def\factnameDE{{Fakt}}
\def\conjecturenameDE{{Vermutung}}
\def\definitionnameDE{{Definition}}
\def\axiomnameDE{{Axiom}}
\def\assumptionnameDE{{Annahme}}
\def\conventionnameDE{{Konvention}}
\def\hypothesisnameDE{{Hypothese}}
\def\notationnameDE{{Notation}}
\def\examplenameDE{{Beispiel}}
\def\problemnameDE{{Problem}}
\def\questionnameDE{{Frage}}
\def\exercisenameDE{{Übung}}
\def\remarknameDE{{Bemerkung}}
\def\observationnameDE{{Beobachtung}}
\expandafter\def\csname definition-propositionnameDE\endcsname{\definitionnameDE-\propositionnameDE}
\expandafter\def\csname definition-theoremnameDE\endcsname{\definitionnameDE-\theoremnameDE}

%% Italian theorems names
\def\theoremnameIT{{Teorema}}
\def\lemmanameIT{{Lemma}}
\def\propositionnameIT{{Proposizione}}
\def\corollarynameIT{{Corollario}}
\def\propertynameIT{{Proprietà}}
\def\factnameIT{{Fatto}}
\def\conjecturenameIT{{Congettura}}
\def\definitionnameIT{{Definizione}}
\def\axiomnameIT{{Assioma}}
\def\assumptionnameIT{{Supposizione}}
\def\conventionnameIT{{Convenzione}}
\def\hypothesisnameIT{{Ipotesi}}
\def\notationnameIT{{Notazione}}
\def\examplenameIT{{Esempio}}
\def\problemnameIT{{Problema}}
\def\questionnameIT{{Domanda}}
\def\exercisenameIT{{Esercizio}}
\def\remarknameIT{{Nota}}
\def\observationnameIT{{Osservazione}}
\expandafter\def\csname definition-propositionnameIT\endcsname{\definitionnameIT-\propositionnameIT}
\expandafter\def\csname definition-theoremnameIT\endcsname{\definitionnameIT-\theoremnameIT}

%% Portuguese theorems names
\def\theoremnamePT{{Teorema}}
\def\lemmanamePT{{Lema}}
\def\propositionnamePT{{Proposição}}
\def\corollarynamePT{{Corolário}}
\def\propertynamePT{{Propriedade}}
\def\factnamePT{{Facto}}
\def\conjecturenamePT{{Conjetura}}
\def\definitionnamePT{{Definição}}
\def\axiomnamePT{{Axioma}}
\def\assumptionnamePT{{Suposição}}
\def\conventionnamePT{{Convenção}}
\def\hypothesisnamePT{{Hipótese}}
\def\notationnamePT{{Notação}}
\def\examplenamePT{{Exemplo}}
\def\problemnamePT{{Problema}}
\def\questionnamePT{{Pergunta}}
\def\exercisenamePT{{Exercício}}
\def\remarknamePT{{Comentário}}
\def\observationnamePT{{Observação}}
\expandafter\def\csname definition-propositionnamePT\endcsname{\definitionnamePT-\propositionnamePT}
\expandafter\def\csname definition-theoremnamePT\endcsname{\definitionnamePT-\theoremnamePT}

%% Brazilian theorems names
\def\theoremnameBR{{Teorema}}
\def\lemmanameBR{{Lema}}
\def\propositionnameBR{{Proposição}}
\def\corollarynameBR{{Corolário}}
\def\propertynameBR{{Propriedade}}
\def\factnameBR{{Facto}}
\def\conjecturenameBR{{Conjetura}}
\def\definitionnameBR{{Definição}}
\def\axiomnameBR{{Axioma}}
\def\assumptionnameBR{{Suposição}}
\def\conventionnameBR{{Convenção}}
\def\hypothesisnameBR{{Hipótese}}
\def\notationnameBR{{Notação}}
\def\examplenameBR{{Exemplo}}
\def\problemnameBR{{Problema}}
\def\questionnameBR{{Pergunta}}
\def\exercisenameBR{{Exercício}}
\def\remarknameBR{{Comentário}}
\def\observationnameBR{{Observação}}
\expandafter\def\csname definition-propositionnameBR\endcsname{\definitionnameBR-\propositionnameBR}
\expandafter\def\csname definition-theoremnameBR\endcsname{\definitionnameBR-\theoremnameBR}

%% Spanish theorems names
\def\theoremnameES{{Teorema}}
\def\lemmanameES{{Lema}}
\def\propositionnameES{{Proposición}}
\def\corollarynameES{{Corolario}}
\def\propertynameES{{Propiedad}}
\def\factnameES{{Hecho}}
\def\conjecturenameES{{Conjetura}}
\def\definitionnameES{{Definición}}
\def\axiomnameES{{Axioma}}
\def\assumptionnameES{{Suposición}}
\def\conventionnameES{{Convención}}
\def\hypothesisnameES{{Hipótesis}}
\def\notationnameES{{Notación}}
\def\examplenameES{{Ejemplo}}
\def\problemnameES{{Problema}}
\def\questionnameES{{Pregunta}}
\def\exercisenameES{{Ejercicio}}
\def\remarknameES{{Comentario}}
\def\observationnameES{{Observación}}
\expandafter\def\csname definition-propositionnameES\endcsname{\definitionnameES-\propositionnameES}
\expandafter\def\csname definition-theoremnameES\endcsname{\definitionnameES-\theoremnameES}

%% Chinese theorems names
\def\theoremnameCN{{定理}}
\def\lemmanameCN{{引理}}
\def\propositionnameCN{{命题}}
\def\corollarynameCN{{推论}}
\def\propertynameCN{{性质}}
\def\factnameCN{{事实}}
\def\conjecturenameCN{{猜想}}
\def\definitionnameCN{{定义}}
\def\axiomnameCN{{公理}}
\def\assumptionnameCN{{假设}}
\def\conventionnameCN{{约定}}
\def\hypothesisnameCN{{假设}}
\def\notationnameCN{{记号}}
\def\examplenameCN{{例}}
\def\problemnameCN{{问题}}
\def\questionnameCN{{问题}}
\def\exercisenameCN{{练习}}
\def\remarknameCN{{备注}}
\def\observationnameCN{{观察}}
\expandafter\def\csname definition-propositionnameCN\endcsname{\definitionnameCN-\propositionnameCN}
\expandafter\def\csname definition-theoremnameCN\endcsname{\definitionnameCN-\theoremnameCN}

\def\theoremnameTC{{定理}}
\def\lemmanameTC{{引理}}
\def\propositionnameTC{{命題}}
\def\corollarynameTC{{推論}}
\def\propertynameTC{{性質}}
\def\factnameTC{{事實}}
\def\conjecturenameTC{{猜想}}
\def\definitionnameTC{{定義}}
\def\axiomnameTC{{公理}}
\def\assumptionnameTC{{假設}}
\def\conventionnameTC{{約定}}
\def\hypothesisnameTC{{假設}}
\def\notationnameTC{{記號}}
\def\examplenameTC{{例}}
\def\problemnameTC{{問題}}
\def\questionnameTC{{問題}}
\def\exercisenameTC{{練習}}
\def\remarknameTC{{備註}}
\def\observationnameTC{{觀察}}
\expandafter\def\csname definition-propositionnameTC\endcsname{\definitionnameTC-\propositionnameTC}
\expandafter\def\csname definition-theoremnameTC\endcsname{\definitionnameTC-\theoremnameTC}

%% Japanese theorems names
\def\theoremnameJP{{定理}}
\def\lemmanameJP{{補題}}
\def\propositionnameJP{{命題}}
\def\corollarynameJP{{系}}
\def\propertynameJP{{性質}}
\def\factnameJP{{事実}}
\def\conjecturenameJP{{予想}}
\def\definitionnameJP{{定義}}
\def\axiomnameJP{{公理}}
\def\assumptionnameJP{{仮定}}
\def\conventionnameJP{{慣例}}
\def\hypothesisnameJP{{仮設}}
\def\notationnameJP{{記法}}
\def\examplenameJP{{例}}
\def\problemnameJP{{問題}}
\def\questionnameJP{{問題}}
\def\exercisenameJP{{練習}}
\def\remarknameJP{{注釈}}
\def\observationnameJP{{観察}}
\expandafter\def\csname definition-propositionnameJP\endcsname{\definitionnameJP-\propositionnameJP}
\expandafter\def\csname definition-theoremnameJP\endcsname{\definitionnameJP-\theoremnameJP}

%% Russian theorems names
\def\theoremnameRU{{Теорема}} % Теоре́ма
\def\lemmanameRU{{Лемма}} % Ле́мма
\def\propositionnameRU{{Предложение}} % Предложе́ние
\def\corollarynameRU{{Следствие}} % Сле́дствие
\def\propertynameRU{{Имущество}} % Иму́щество
\def\factnameRU{{Факт}}
\def\conjecturenameRU{{Гипотеза}} % Гипо́теза
\def\definitionnameRU{{Определение}} % Определе́ние
\def\axiomnameRU{{Аксиома}} % Аксио́ма
\def\assumptionnameRU{{Предположение}} % Предположе́ние
\def\conventionnameRU{{Конвенция}} % Конве́нция
\def\hypothesisnameRU{{Гипотеза}} % Гипо́теза
\def\notationnameRU{{Нотация}} % Нота́ция
\def\examplenameRU{{Пример}} % Приме́р
\def\problemnameRU{{Проблема}} % Пробле́ма
\def\questionnameRU{{Вопрос}} % Вопро́с
\def\exercisenameRU{{Упражнение}} % Упражне́ние
\def\remarknameRU{{Замечание}} % Замеча́ние
\def\observationnameRU{{Наблюдение}} % Наблюде́ние
\expandafter\def\csname definition-propositionnameRU\endcsname{\definitionnameRU-\propositionnameRU}
\expandafter\def\csname definition-theoremnameRU\endcsname{\definitionnameRU-\theoremnameRU}

\newif\ifPJLthm@IsBook
\ifdefined\c@chapter\PJLthm@IsBooktrue\else\PJLthm@IsBookfalse\fi
%% Theorem environments
\ifbool{PJLthm@IsBook}{
    \newaliascnt{PJLthm@highest}{chapter}
}{
    \newaliascnt{PJLthm@highest}{section}
}
\if@PJLthm@nothms\else
\CreateTheorem{theorem}<PJLthm@highest>
\CreateTheorem{lemma}[theorem]
\CreateTheorem{proposition}[theorem]
\CreateTheorem{corollary}[theorem]
\CreateTheorem{definition-proposition}[theorem]
\CreateTheorem{definition-theorem}[theorem]
\CreateTheorem{property}[theorem]
\CreateTheorem{fact}[theorem]
\CreateTheorem{conjecture}[theorem]
\CreateTheorem*{theorem*}
\CreateTheorem*{lemma*}
\CreateTheorem*{proposition*}
\CreateTheorem*{corollary*}
\CreateTheorem*{definition-proposition*}
\CreateTheorem*{definition-theorem*}
\CreateTheorem*{property*}
\CreateTheorem*{fact*}
\CreateTheorem*{conjecture*}

\theoremstyle{definition}
\CreateTheorem{definition}[theorem]
\CreateTheorem{axiom}[theorem]
\CreateTheorem{assumption}[theorem]
\CreateTheorem{convention}[theorem]
\CreateTheorem{hypothesis}[theorem]
\CreateTheorem{notation}[theorem]
\CreateTheorem{example}[theorem]
\CreateTheorem{problem}[theorem]
\CreateTheorem{question}[theorem]
\CreateTheorem{exercise}[theorem]
\CreateTheorem*{definition*}
\CreateTheorem*{axiom*}
\CreateTheorem*{assumption*}
\CreateTheorem*{convention*}
\CreateTheorem*{hypothesis*}
\CreateTheorem*{notation*}
\CreateTheorem*{example*}
\CreateTheorem*{problem*}
\CreateTheorem*{question*}
\CreateTheorem*{exercise*}

\theoremstyle{remark}
\CreateTheorem{remark}<PJLthm@highest>
\CreateTheorem*{remark*}
\CreateTheorem{observation}<PJLthm@highest>
\CreateTheorem*{observation*}
\fi

\numberwithin{equation}{PJLthm@highest}

% Some localization of cref
\gappto{\PJLlang@langconfig@chinese}{%
    \crefname{equation}{式}{式}%
    \crefname{figure}{图}{图}%
    \crefname{table}{表}{表}%
    \crefname{appendix}{附录}{附录}%
    \Crefname{equation}{式}{式}%
    \Crefname{figure}{图}{图}%
    \Crefname{table}{表}{表}%
    \Crefname{appendix}{附录}{附录}%
    \def\crefpairconjunction{、}%
    \def\crefmiddleconjunction{、}%
    \def\creflastconjunction{~和~}%
    \def\crefpairgroupconjunction{~和~}%
    \def\crefmiddlegroupconjunction{、}%
    \def\creflastgroupconjunction{~和~}%
    \def\crefrangeconjunction{～}%
}
\gappto{\PJLlang@langconfig@tchinese}{%
    \crefname{equation}{式}{式}%
    \crefname{figure}{圖}{圖}%
    \crefname{table}{表}{表}%
    \crefname{appendix}{附錄}{附錄}%
    \Crefname{equation}{式}{式}%
    \Crefname{figure}{圖}{圖}%
    \Crefname{table}{表}{表}%
    \Crefname{appendix}{附錄}{附錄}%
    \def\crefpairconjunction{、}%
    \def\crefmiddleconjunction{、}%
    \def\creflastconjunction{~與~}%
    \def\crefpairgroupconjunction{~與~}%
    \def\crefmiddlegroupconjunction{、}%
    \def\creflastgroupconjunction{~與~}%
    \def\crefrangeconjunction{～}%
}
\gappto{\PJLlang@langconfig@japanese}{%
    \crefname{equation}{式}{式}%
    \crefname{figure}{図}{図}%
    \crefname{table}{表}{表}%
    \Crefname{appendix}{付録}{付録}%
    \Crefname{equation}{式}{式}%
    \Crefname{figure}{図}{図}%
    \Crefname{table}{表}{表}%
    \Crefname{appendix}{付録}{付録}%
    \def\crefpairconjunction{~と~}%
    \def\crefmiddleconjunction{~と~}%
    \def\creflastconjunction{~と~}%
    \def\crefpairgroupconjunction{~と~}%
    \def\crefmiddlegroupconjunction{~と~}%
    \def\creflastgroupconjunction{~と~}%
    \def\crefrangeconjunction{〜}%
}
\gappto{\PJLlang@langconfig@russian}{%
    \crefname{equation}{уравнение}{уравнения}%
    \crefname{figure}{рис.}{рис.}%
    \crefname{table}{таблица}{таблицы}%
    \crefname{appendix}{приложение}{приложения}%
    \Crefname{equation}{Уравнение}{Уравнения}%
    \Crefname{figure}{Рис.}{Рис.}%
    \Crefname{table}{Таблица}{Таблицы}%
    \Crefname{appendix}{Приложение}{Приложения}%
    \def\crefpairconjunction{~и~}%
    \def\crefmiddleconjunction{,~}%
    \def\creflastconjunction{~и~}%
    \def\crefpairgroupconjunction{~и~}%
    \def\crefmiddlegroupconjunction{,~}%
    \def\creflastgroupconjunction{~и~}%
    \def\crefrangeconjunction{~\textasciitilde~}%
}
\gappto{\PJLlang@langconfig@portuguese}{%
    \crefname{equation}{eq.}{eqs.}%
    \crefname{figure}{fig.}{figs.}%
    \crefname{table}{tabela}{tabelas}%
    \crefname{appendix}{apêndice}{apêndices}%
    \Crefname{equation}{Eq.}{Eqs.}%
    \Crefname{figure}{Fig.}{Figs.}%
    \Crefname{table}{Tabela}{Tabelas}%
    \Crefname{appendix}{Apêndice}{Apêndices}%
    \def\crefpairconjunction{ e\nobreakspace}%
    \def\crefmiddleconjunction{, }%
    \def\creflastconjunction{ e\nobreakspace}%
    \def\crefpairgroupconjunction{ e\nobreakspace}%
    \def\crefmiddlegroupconjunction{, }%
    \def\creflastgroupconjunction{ e\nobreakspace}%
    \def\crefrangeconjunction{ a\nobreakspace}%
}
%</PJLthm>
%
%<*ProjLib,PJLtoolkit>
\SetupKeyvalOptions{
    family = @PJLtoolkit,
    prefix = @PJLtoolkit@,
}
\DeclareBoolOption[false]{draft}
\DeclareBoolOption[false]{fast}
\DeclareBoolOption[false]{author}
\DeclareBoolOption[false]{amssim}
\DeclareBoolOption[false]{nothms}
\DeclareBoolOption[false]{regionalref}
\DeclareBoolOption[false]{useosf}
\DeclareBoolOption[false]{palatino}
\DeclareBoolOption[false]{times}
\DeclareBoolOption[false]{garamond}
\DeclareBoolOption[false]{biolinum}
\ProcessKeyvalOptions*\relax
\if@PJLtoolkit@draft
    \@PJLtoolkit@fasttrue
\fi
\if@PJLtoolkit@fast
    \PassOptionsToPackage{fast}{PJLdate}
    \PassOptionsToPackage{fast}{PJLdraft}
    \PassOptionsToPackage{fast}{PJLlogo}
    \PassOptionsToPackage{fast}{PJLthm}
\fi
\if@PJLtoolkit@nothms
    \PassOptionsToPackage{nothms}{PJLthm}
\fi
\if@PJLtoolkit@regionalref
    \PassOptionsToPackage{regionalref}{PJLthm}
\fi

\if@PJLtoolkit@author
    \RequirePackage{PJLauthor}
\fi
\if@PJLtoolkit@amssim
    \RequirePackage{PJLamssim}
\fi
\RequirePackage{PJLdate}
\RequirePackage{PJLdraft}
\RequirePackage{PJLlogo}
\RequirePackage{PJLpaper}
\RequirePackage{PJLthm}

% \RequirePackage{iftex}
% \ifPDFTeX
% \RequirePackage[T1]{fontenc}
% \RequirePackage{inputenc}
% \fi
%
\RequirePackage{mathtools}

% \PJL@font@alreadyset should contain the current font name
% A message can then be shown as: Font "(font name)" has been set
\ifdefined\PJL@font@alreadyset\else

\if@PJLtoolkit@palatino
    \RequirePackage{amssymb}
    \RequirePackage{mathpazo}
    \PassOptionsToPackage{defaultsups}{newpxtext}
    \RequirePackage{newpxtext}
    \RequirePackage{newpxmath}
    \let\openbox\relax
    \PJLsetlinespacing{\setstretch{1.07}}
    \if@PJLtoolkit@useosf\useosf\fi
\fi

\if@PJLtoolkit@times
    \RequirePackage{amssymb}
    \PassOptionsToPackage{defaultsups}{newtxtext}
    \RequirePackage{newtxtext}
    \RequirePackage{newtxmath}
    \let\openbox\relax
    \PJLsetlinespacing{\setstretch{1.00}}
    \if@PJLtoolkit@useosf\useosf\fi
\fi

\if@PJLtoolkit@garamond
    \RequirePackage{amssymb}
    \if@PJLtoolkit@useosf\else
        \PassOptionsToPackage{lining}{ebgaramond}
    \fi
    \RequirePackage{ebgaramond-maths}
    \RequirePackage{ebgaramond}
    % \RequirePackage{garamondlibre}
    \PJLsetlinespacing{\setstretch{1.00}}
\fi

\if@PJLtoolkit@biolinum
    \RequirePackage{amssymb}
    % \RequirePackage{mathpazo}
    % \RequirePackage[sansmath]{libertinust1math}
    \ifPDFTeX
        \if@PJLtoolkit@useosf
            \PassOptionsToPackage{osf}{biolinum}
        \fi
        \RequirePackage{biolinum}
        \renewcommand*\familydefault{\biolinum@family}
    \else
        \PassOptionsToPackage{no-math}{fontspec}
        \RequirePackage{fontspec}
        \setmainfont{LinBiolinum_R.otf}[
            BoldFont       = LinBiolinum_RB.otf ,
            ItalicFont     = LinBiolinum_RI.otf ,
            BoldItalicFont = LinBiolinum_RBO.otf,
            \if@PJLtoolkit@useosf Numbers = OldStyle\fi ]
    \fi
    \PJLsetlinespacing{\setstretch{1.05}}
    \RequirePackage[italic,defaultmathsizes]{mathastext}
\fi

\fi

\RequirePackage{microtype}
%</ProjLib,PJLtoolkit>

\endinput