\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{blackboardbeamerjapanese}[2020/09/23 Shinichiroh Matsuo]

%==============================================================================%

\LoadClass[hyperref=unicode,8pt,t]{beamer}
%t -> Place text of slides at the (vertical) top of the slides.

%==============================================================================%
% フォント

\RequirePackage{zxjatype}

\setjamainfont[BoldFont=UD Digi Kyokasho N Medium]{UD Digi Kyokasho N-R}
\setjasansfont[BoldFont=UD Digi Kyokasho N Medium]{UD Digi Kyokasho N-R}
\setjamonofont[BoldFont=UD Digi Kyokasho N Medium]{UD Digi Kyokasho N-R}
% N  -> 全てが等幅．
% NP -> 漢字とひらがなが等幅かつ欧文がプロポーショナル．
% NK -> 全てがプロポーショナル．

\CJKsetecglue{}
\CJKspace
\renewcommand{\emph}[1]{{\bfseries \sffamily #1}}

\setsansfont[ItalicFont=UDDigikyoItalic-R]{UDDigikyoLatin-R}

\usefonttheme{professionalfonts}
\RequirePackage[euler-digits, euler-hat-accent]{eulervm}
%\RequirePackage{lmodern}
%\RequirePackage{arevmath}
\everymath{\displaystyle}

% \setjasansfont{ShigotoMemogaki}
% \setsansfont{Neucha}
%
% \setjasansfont{BIZ-UDShinGoCsiz}
% \setjasansfont{BIZ-UDShinGoCeiz}
%
% \setsansfont{Optima}

%==============================================================================%

% frameの基本構造

\setbeamersize{text margin left=2mm}
\setbeamersize{text margin right=2mm}

\setbeamertemplate{navigation symbols}{}
\setbeamertemplate{footline}[frame number]

\RequirePackage[parfill]{parskip}
\renewcommand{\baselinestretch}{1.1}

% 色

\usecolortheme{owl}

\definecolor{blackboard}{HTML}{264435}
\definecolor{thickblackboard}{RGB}{0,32,0}
\definecolor{chalkwhite}{RGB}{255,255,224}

\setbeamercolor*{background canvas}{bg=blackboard}
\setbeamercolor*{normal text}{fg=white}

\RequirePackage{xcolor}

% タイトルページ

\makeatletter
   \def\hrulefill{\leavevmode\leaders\hrule\@height1pt\hfill\kern\z@}
\makeatother
\setbeamertemplate{title page}{
  \vfill
  {\Huge \inserttitle} \\
  \vspace{\baselineskip}
  {\Huge \insertdate}
  {\color{OwlRed}\rule{\linewidth}{1pt}\vspace{\baselineskip}}
  {\Huge \insertauthor \\ \smallskip \insertinstitute} \\
  \vfill
}

\def\maketitle{\frame[plain, noframenumbering]{\titlepage}}

% 目次ページ

\setbeamertemplate{section in toc}[sections numbered]
\setbeamertemplate{subsection in toc}[subsections numbered]
\setbeamertemplate{subsubsection in toc}[subsubsections numbered]

\AtBeginPart
{
  \begin{frame}[plain, noframenumbering, c]\centering\Huge
    \insertpart
  \end{frame}
}

\AtBeginSection[] % [] -> Do nothing for \section*.
{
  \begin{frame}[plain, noframenumbering, c]\centering\Huge
    \insertsectionnumber. \insertsection
  \end{frame}
}

% \AtBeginSubsection[] % [] -> Do nothing for \subsection*.
% {
%   \begin{frame}[plain, noframenumbering, c]\centering\Huge
%     \insertsectionnumber. \insertsection \\
        \bigskip
%     \insertsectionnumber.\insertsubsectionnumber. \insertsubsection
%   \end{frame}
% }

% frametitle

\setbeamercolor*{frametitle}{fg=white, bg=blackboard}
\newcommand\thickunderline[3][-1pt]{{%
  \setbox0=\hbox{#3}
  \ooalign{\copy0\cr\rule[\dimexpr#1-#2\relax]{\wd0}{#2}}}
  }
\setbeamertemplate{frametitle}{\LARGE\thickunderline[-1.5pt]{1pt}{\insertframetitle}\par}

% itemize環境

\setbeamertemplate{itemize items}[circle]

%==============================================================================%
% 定理型環境

\RequirePackage{tcolorbox}
\tcbuselibrary{theorems,breakable}

\RequirePackage{multicol}

\tcbset{basestyle@blackboard/.style={
  coltext=white,
  colback=blackboard,
  colbacktitle=blackboard,
  titlerule=0mm,
  boxrule=0.5pt,
  size=small,
  parbox=false,
  }
}

\tcbset{blockstyle@blackboard/.style={
  basestyle@blackboard,
  }
}

\tcbset{thmstyle@blackboard/.style={
  basestyle@blackboard,
  theorem style=break,
  separator sign none,
  terminator sign none,
  }
}

\tcbset{prfstyle@blackboard/.style={
  thmstyle@blackboard,
  theorem style=plain,
  terminator sign none,
  size=minimal,
  breakable,
  }
}

\newtcolorbox{redblock}{colframe=OwlRed,blockstyle@blackboard}
\newtcolorbox{yellowblock}{colframe=OwlYellow,blockstyle@blackboard}
\newtcolorbox{blueblock}{colframe=OwlBlue,blockstyle@blackboard}

\newtcbtheorem[number within=section]{dfn@blackboard}{定義}{
    colframe=OwlYellow,
    coltitle=OwlYellow,
    thmstyle@blackboard,
  }{definition}

\newtcbtheorem[use counter from=dfn@blackboard]{thm@blackboard}{定理}{
  colframe=OwlRed,
  coltitle=OwlRed,
  thmstyle@blackboard,
}{theorem}

\newtcbtheorem[use counter from=dfn@blackboard]{prop@blackboard}{命題}{
  colframe=OwlRed,
  coltitle=OwlRed,
  thmstyle@blackboard,
}{proposition}

\newtcbtheorem[use counter from=dfn@blackboard]{lem@blackboard}{補題}{
  colframe=OwlRed,
  coltitle=OwlRed,
  thmstyle@blackboard,
}{lemma}

\newtcbtheorem[use counter from=dfn@blackboard]{cor@blackboard}{系}{
  colframe=OwlRed,
  coltitle=OwlRed,
  thmstyle@blackboard,
}{corollary}

\newtcbtheorem{prf@blackboard}{（証明）}{prfstyle@blackboard}{proof}

\newtcbtheorem[use counter from=dfn@blackboard]{rmk@blackboard}{注意}{
  colframe=OwlYellow,
  coltitle=OwlYellow,
  thmstyle@blackboard,theorem style=plain,terminator sign=：
}{remark}

\newtcbtheorem[use counter from=dfn@blackboard]{exmpl@blackboard}{例}{
  colframe=OwlBlue,
  coltitle=OwlBlue,
  thmstyle@blackboard,theorem style=plain,terminator sign=：
}{example}

\renewenvironment{definition}[1][]{\begin{dfn@blackboard}{#1}{}}{\end{dfn@blackboard}}
\renewenvironment{theorem}[1][]{\begin{thm@blackboard}{#1}{}}{\end{thm@blackboard}}
\newenvironment{proposition}[1][]{\begin{prop@blackboard}{#1}{}}{\end{prop@blackboard}}
\renewenvironment{lemma}[1][]{\begin{lem@blackboard}{#1}{}}{\end{lem@blackboard}}
\renewenvironment{corollary}[1][]{\begin{cor@blackboard}{#1}{}}{\end{cor@blackboard}}

\renewenvironment{proof}{\begin{prf@blackboard*}{}{}}{\end{prf@blackboard*}}
\newenvironment{proof2}{\begin{multicols}{2}\begin{proof}}{\end{proof}\end{multicols}}

\newenvironment{remark}[1][]{\begin{rmk@blackboard}{#1}{}}{\end{rmk@blackboard}}

\renewenvironment{example}[1][]{\begin{exmpl@blackboard}{#1}{}}{\end{exmpl@blackboard}}

%==============================================================================%
% 数式

\usepackage{mathtools}
\mathtoolsset{showonlyrefs=true}
\usepackage{nccmath}
