%%% MyCommands ... My commands and environment generically used in all tex files.
%%% Separated from my-all-head.tex 2014-08-28
\makeatletter
\def\MyCommands@Revision{Time-stamp: "2017/04/20"}
\ProvidesPackage{majin}

%%%%%%%%%%%%% box examples %%%%%%%%%%%%%%%%%
%\newcommand{\onebox}[1]{\freebox{13}{1.8}{4.8}{#1}}
%\newcommand{\scorebox}[1]{\freebox{28}{3}{14}{#1}}
%\newcommand{\normalbox}[1]{\framebox[2cm]{\rule[-2mm]{0mm}{6mm}#1}}
%\newcommand{\longbox}[1]{\framebox[6cm]{\rule[-2mm]{0mm}{6mm}#1}}
%\newcommand{\minibox}[1]{\framebox[1cm]{\rule[-1mm]{0mm}{4mm}{#1}}}
%\newcommand{\halfbigbox}{\framebox[6cm]{\rule[-8mm]{0mm}{20mm}{}}}
%\newcommand{\halfBigbox}{\framebox[6cm]{\rule[-12mm]{0mm}{24mm}{}}}
%\newcommand{\Bigbox}{\framebox[16.5cm]{\rule[-12mm]{0mm}{24mm}{}}}
%\newcommand{\Hugebox}{\framebox[17cm]{\rule[-3mm]{0mm}{80mm}{}}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newsavebox{\tmp@box}
\newdimen{\tmp@ht}
\newdimen{\tmp@rdp}
\newdimen{\tmp@dp}
% \newdimen{\tmp@dim@ne}
% \newdimen{\tmp@dimtw@}
%\newcommand{\numbox}{\framebox[10mm]{\rule[-1.0mm]{0mm}{9.0mm}}}
%\newcommand{\tenchi}[1]{\ensuremath{{}^t\!\!{#1}}}
% \newcommand{\tenchi}[1]{\ensuremath{{}^t\mkern-4mu{#1}}}
\newcommand{\tenchi}[1]{%
  \sbox{\tmp@box}{$#1$}%
  \tmp@ht=\ht\tmp@box%\relax\tmp@dp=\dp\tmp@box%
  \ensuremath{{\rule[0pt]{0pt}{\tmp@ht}}^t\mkern-2mu}\usebox{\tmp@box}}%
\newcommand{\Tenchi}[1]{\mathord{\mathopen{{\vphantom{#1}}^t}\!#1}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%% boldsymbol or mathbb %%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\tmp@w#1#2{
  \expandafter\gdef\csname #2\endcsname{\ensuremath{\boldsymbol{#1}}}
}
\@for\x:={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,0}\do{%
  \edef\tmp@a{\x}% \tmp@a = {a,b,...}
  \edef\tmp@b{W\x}% \tmp@b = {Wa,Wb,...}
  \expandafter\tmp@w\expandafter{\tmp@a}{\tmp@b}
}
%%%% MathBB or Boldy R, C, Z, etc...
\newif\ifUseMathBB
\def\tmp@W#1#2{
  \expandafter\gdef\csname #2\endcsname{\ensuremath{\ifUseMathBB{\mathbb #1}%
      \else\boldsymbol{#1}\fi}}
}
\@for\x:={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}\do{%
  \edef\tmp@a{\x}% \tmp@a = {a,b,...}
  \edef\tmp@b{W\x}% \tmp@b = {Wa,Wb,...}
  \expandafter\tmp@W\expandafter{\tmp@a}{\tmp@b}
}
\def\UseMathBB{%
  \UseMathBBtrue%
  \@for\x:={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}\do{%
    \edef\tmp@a{\x}% \tmp@a = {a,b,...}
    \edef\tmp@b{W\x}% \tmp@b = {Wa,Wb,...}
    \expandafter\tmp@W\expandafter{\tmp@a}{\tmp@b}
  }%
}
\newcommand{\W}[1]{\ensuremath{\ifUseMathBB{\mathbb #1}\else\boldsymbol{#1}\fi}}
\newcommand{\BeamerVec}[1]{\hbox to 0pt{$#1$}\kern.5pt$#1$}
\newcommand{\zero}{\ensuremath{\boldsymbol{0}}}
\newcommand{\Exists}{\ensuremath{{}^{\exists}}}
\newcommand{\ForAll}{\ensuremath{{}^{\forall}}}
%%%%%%%%%%%%%%%%%%%%%%%%
%%%%% operatorname %%%%%
%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\SIN}{\ensuremath{\operatorname{Sin}}}
\newcommand{\COS}{\ensuremath{\operatorname{Cos}}}
\newcommand{\TAN}{\ensuremath{\operatorname{Tan}}}
\newcommand{\Limit}{\ensuremath{\displaystyle\lim}}
\newcommand{\Majiwari}{\ensuremath{\mathop{\bigcap}}}
\let\Intersection\Majiwari
\newcommand{\Union}{\ensuremath{\operatorname{\bigcup}}}
\newcommand{\rank}{\ensuremath{\operatorname{rank}}}
\newcommand{\Ker}{\ensuremath{\operatorname{Ker}}}
\newcommand{\Image}{\ensuremath{\operatorname{Im}}}
\newcommand{\RE}{\ensuremath{\operatorname{Re}}}
\newcommand{\IM}{\ensuremath{\operatorname{Im}}}
\newcommand{\Id}{\ensuremath{\operatorname{Id}}}
\newcommand{\trace}{\ensuremath{\operatorname{tr}}}
\newcommand{\GL}{\ensuremath{\operatorname{GL}}}
\newcommand{\SL}{\ensuremath{\operatorname{SL}}}
\newcommand{\dsum}{\displaystyle\sum}
\let\Dsum\dsum%% analogus to \Dint
\newcommand{\Dint}{\displaystyle\int}
\newcommand{\dprod}{\displaystyle\prod}
\let\Dprod\dprod
\newcommand{\norm}[1]{\ensuremath{\left\Vert{#1}\right\Vert}}


\newcommand{\dettwo}[4]{%
  \ensuremath{\left|\begin{matrix}#1&#2\\#3&#4\end{matrix}\right|}}
\newcommand{\detthree}[9]{\ensuremath{\left|\begin{matrix}#1&#2&#3\\#4&#5&#6
\\#7&#8&#9\end{matrix}\right|}}
\newcommand{\ppmatrix}[4]{\ensuremath{\begin{pmatrix}#1&#2\\#3&#4\end{pmatrix}}}
\newcommand{\vvmatrix}[4]{\ensuremath{\begin{vmatrix}#1&#2\\#3&#4\end{vmatrix}}}
\newcommand{\pppmatrix}[9]%
 {\ensuremath{\begin{pmatrix}#1&#2&#3\\#4&#5&#6\\#7&#8&#9\end{pmatrix}}}
\newcommand{\vvvmatrix}[9]%
 {\ensuremath{\begin{vmatrix}#1&#2&#3\\#4&#5&#6\\#7&#8&#9\end{vmatrix}}}
\newcommand{\ppppmatrix}[4]%
 {\ensuremath{\begin{pmatrix}#1\\#2\\#3\\#4\end{pmatrix}}}
\newcommand{\pppppmatrix}[5]%
 {\ensuremath{\begin{pmatrix}#1\\#2\\#3\\#4\\#5\end{pmatrix}}}
\newcommand{\vvvvmatrix}[4]%
 {\ensuremath{\begin{vmatrix}#1\\#2\\#3\\#4\end{vmatrix}}}
\newcommand{\REtube}[4]{\ensuremath{\begin{pmatrix}#1\\#2\\#3\\#4\end{pmatrix}}}
\newcommand{\RETube}[5]{\ensuremath{\begin{pmatrix}#1\\#2\\#3\\#4\\#5\end{pmatrix}}}
\newcommand{\RETUbe}[6]{\ensuremath{\begin{pmatrix}#1\\#2\\#3\\#4\\#5\\#6\end{pmatrix}}}
\newcommand{\RETUBe}[7]{\ensuremath{\begin{pmatrix}#1\\#2\\#3\\#4\\#5\\#6\\#7%
\end{pmatrix}}}
\newcommand{\RETUBE}[8]{\ensuremath{\begin{pmatrix}#1\\#2\\#3\\#4\\#5\\#6\\#7%
\\#8\end{pmatrix}}}

%\newcommand{\shortbox}[1]{\framebox[2.2cm]{\rule[-2mm]{0mm}{6mm}#1}}
%d
%\newcommand{\LONGbox}[1]{\framebox[14cm]{\rule[-2mm]{0mm}{6mm}#1}}
%\newcommand{\longbox}[1]{\framebox[12cm]{\rule[-2mm]{0mm}{6mm}#1}}
%\newcommand{\highbox}[1]{\framebox[4cm]{\rule[-2mm]{0mm}{14mm}#1}}
%\newcommand{\highlongbox}[1]{\framebox[8cm]{\rule[-16mm]{0mm}{18mm}#1}}

%\newcommand{\smallbox}[1]{\framebox[2cm]{\rule[-1mm]{0mm}{4mm}{#1}}}
%\newcommand{\minibox}[1]{\framebox[1cm]{\rule[-1mm]{0mm}{4mm}{#1}}}

%\newcommand{\bigbox}[1]{\framebox[16cm]{\rule[-2mm]{0mm}{1.7cm}{#1}}}
%\newcommand{\Bigbox}[1]{\framebox[16cm]{\rule[-2mm]{0mm}{2.8cm}{#1}}}
%\newcommand{\BIgbox}[1]{\framebox[16cm]{\rule[-2mm]{0mm}{4.3cm}{#1}}}
%\newcommand{\BIGbox}[1]{\framebox[16cm]{\rule[-2mm]{0mm}{6cm}{#1}}}
%\newcommand{\BIGBox}[1]{\framebox[16cm]{\rule[-2mm]{0mm}{8.5cm}{#1}}}
%\newcommand{\BIGBOx}[1]{\framebox[16cm]{\rule[-2mm]{0mm}{10cm}{#1}}}
%\newcommand{\BIGBOX}[1]{\framebox[16cm]{\rule[-2mm]{0mm}{12cm}{#1}}}
%\newcommand{\largebox}{\framebox[14cm]{\rule[-2mm]{0mm}{9.5cm}}}
%\newcommand{\Largebox}{\framebox[14cm]{\rule[-2mm]{0mm}{12cm}}}
%\newcommand{\ulitem}[1]{\raisebox{-.4em}{\small (#1)}}

\newcommand{\dummybox}[4]{\let\orgfboxsep\fboxsep\fboxsep=.5zw%
\makebox[#1mm]{\rule[-#2mm]{0mm}{#3mm}#4}\fboxsep=\orgfboxsep}
\newcommand{\freebox}[4]{\let\orgfboxsep\fboxsep\fboxsep=.5zw%
\framebox[#1mm]{\rule[-#2mm]{0mm}{#3mm}#4}\fboxsep=\orgfboxsep}
\newcommand{\Freebox}[5]{\let\orgfboxsep\fboxsep\fboxsep=#1mm%
\framebox[#2mm]{\rule[-#3mm]{0mm}{#4mm}#5}\fboxsep=\orgfboxsep}

\newsavebox{\TmpAnsBox}
\newcommand{\setans}[1]{%
  \begin{lrbox}{\TmpAnsBox} \parbox{15cm}{#1} \end{lrbox}}
%  \savebox{\TmpAnsBox}[15cm]{#1}}
\newcommand{\putans}{\usebox{\TmpAnsBox}}
\newcommand{\ifans}[2]{\ifcase#1\or#2\fi}
\newcommand{\ifnotans}[2]{\ifcase#1#2\fi}
\newcommand{\caseans}[2]{\ifcase\ansmode#1\or#2\fi}
\newcommand{\ifamd}[1]{\ifcase\ansmode\or#1\fi}
\newcommand{\ifnotamd}[1]{\ifcase\ansmode#1\fi}
%\newcounter{ansmode}
%\newcommand{\setansmode}{\setcounter{ansmode}{1}}
%\newcommand{\noansmode}{\setcounter{ansmode}{2}}
%\newcommand*\ifansmode[1]{\ifcase ansmode\or%
%  {#1}\or{}\fi}

%%% use \renewcommand{\tmpskip}{\vspace{...em}}
\newcommand{\tmpskip}{\bigskip}
\newcounter{ansitem}
\newcommand{\ansitem}{%
  \setcounter{ansitem}{\value{ansitem}+1}\ (\arabic{ansitem})\ \ }
\newcommand{\resetans}{\setcounter{ansitem}{0}}
\newcounter{tensencnt}
\newcommand\tensen[1]{%
\setcounter{tensencnt}{0}
\whiledo{\value{tensencnt}<#1}{%
--\hfill\stepcounter{tensencnt}
}--}
\let\olddfrac\dfrac
\def\dfrac#1#2{\olddfrac{\,#1\,}{\,#2\,}}

\newcommand{\LNbox}[5]{\caseans{\freebox{#1}{#2}{#3}{#4}}{\freebox{#1}{#2}{#3}{\color{red}{#5}}}}
%\let\orgfboxsep\fboxsep\fboxsep=.5zw\fbox{#2}\fboxsep=\orgfboxsep}}
\newcommand{\Ans}[1]{\caseans{\vspace{1em}}{\par\noindent%
\rule[.3zh]{.08\columnwidth}{.4pt}%
\parbox[c]{.08\columnwidth}{\hfill＜解＞\hfill\ }%
\rule[.3zh]{.78\columnwidth}{.4pt}%
\newline\vspace{.5zh}
\resetcounter{ansitem}{\parbox[t]{.92\columnwidth}{#1}}
\newline\vspace{-.3zh}
\noindent\hspace{-.005\columnwidth}%
%\noindent\hspace{-.02\columnwidth}%
\rule[.3zh]{.95\columnwidth}{.4pt}}}

\newcommand{\Dummy}[1]{\empty}
\newcommand{\numbox}{\framebox[7mm]{\rule[-1.0mm]{0mm}{6.5mm}}}
\newcommand{\ExamHeadAuto}[5]{%%% New Version
\begin{center}
  \hfill
  {\Large {#1}}
  \hfill\caseans{\freebox{24}{9.5}{14}{#2}}%
  {\phantom{\freebox{24}{9.5}{14}{}}}\hspace{-0.8cm}\phantom{1}\hfill%
\end{center}
\vspace{-3em}
\begin{flushright}
  \underline{{\@stnum}番号\ {\Large #4}\ \ }
  \ \underline{氏名\qquad \parbox[t]{36mm}{\Large #5}\qquad}%
\hspace{5em}\phantom{1111111}
\end{flushright}
}
\newcommand{\ExamHead}[4]{%%% New Version: score box freestyle
  \def\tmpA{#3}\def\tmpB{}
\begin{center}
  \hfill
  {\Large {#1}}
  \hfill\caseans{\freebox{24}{9.5}{14}{\parbox[t]{22mm}{#2}}}%
  {\phantom{\freebox{24}{9.5}{14}{}}}\hspace{-0.6cm}\phantom{1}\hfill%
\end{center}
\vspace{-4em}
\caseans{
  \ifx\tmpA\tmpB
  \begin{center}
    \underline{\hspace{30em}}
  \end{center}
  \else
  \begin{flushright}
    \underline{{#3}番号 {#4}}
    \ \underline{氏名\raisebox{-2.2mm}{\hspace{5.7cm}}}%
    \hspace{5em}\phantom{1}
  \end{flushright}
  \fi
}{\begin{center}〜解答例〜\end{center}}}
\makeatletter
\newcommand{\examheadauto}[5]{
  \parbox[t]{186mm}{%
    \begin{center}
      \hfill{\Large {#1}}
      \hfill\caseans{\freebox{24}{9.5}{14}{\hfill{\raisebox{-8mm}{\small /#2}}}}%
      {\phantom{\freebox{24}{9.5}{14}{}}}\hspace{-0.6cm}\phantom{1}\hfill%
    \end{center}
    \vspace{-3em}
    \begin{flushright}
      \underline{{#3}番号\ {\Large #4}\ \ }
      \underline{氏名\qquad \parbox[t]{36mm}{\Large #5}\qquad}%
      \hspace{5em}\phantom{1111111}
    \end{flushright}}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\examhead#1#2#3#4{
  \edef\tmp@A{#3}\edef\tmp@C{#2}
  \relax\vspace{-1.5zw}%
  \begin{center}
    \ \\
    {\Large {#1}}
  \end{center}
  \vspace{-3zw}
  \parbox[b]{.9\linewidth}{%
    \begin{flushleft}
      \ifx\empty\tmp@A
      \underline{番号\hspace{9em}\rule{0pt}{10pt}}\qquad
      \underline{氏名\hspace{18em}\rule{0pt}{10pt}}%\hspace{8em}
      \else
      \underline{{#3}番号 {#4}}
      \ \underline{氏名\raisebox{-2.2mm}{
          \caseans{\hspace{5.7cm}}%
          {\raisebox{2.2mm}{\hbox to 5.7cm{\color{red}\qquad 解答例\qquad }}}}}%
      \hspace{5em}\phantom{1}
      \fi
    \end{flushleft}
  }
  \raisebox{1.2zw}{\parbox[b]{.1\linewidth}{
    \if\IsInteger{\tmp@C}
    \ifnum\tmp@C=0
    \hfill%
    {\phantom{\freebox{24}{9.5}{14}{}}}\hspace{-0.8cm}\phantom{1}\hfill%
    \else\ifnum\tmp@C=999
    \hfill\freebox{24}{9.5}{14}{}\hspace{-0.8cm}\phantom{1}\hfill
    \else
    \hfill\caseans{\freebox{24}{9.5}{14}%
      {\hfill{\raisebox{-8mm}{\scalebox{2}{/}\tmp@C}}}}%
    {\phantom{\freebox{24}{9.5}{14}{}}}\hspace{-0.8cm}\phantom{1}\hfill
    \fi\fi
    \else
    \hfill\caseans{\freebox{24}{9.5}{14}{\parbox[t]{22mm}{\tmp@C}}}%
    {\phantom{\freebox{24}{9.5}{14}{}}}\hspace{-0.8cm}\phantom{1}\hfill%
    \fi
  }}\relax\vspace{-3.5zw}%
}
%%%%%%%%%%%%%%%%%%%%
\newcommand{\examheadprobonly}[1]{
\begin{center} {\Large {#1}} \end{center}
%\vspace{-4em}
\ifamd{\begin{center}〜解答例〜\end{center}}}

%%%%% ITEMS %%%%%
\newcounter{msitem}
\newcommand{\msitem}{\setcounter{msitem}{\value{msitem}+1}%
	\fbox{\ (\arabic{msitem})\ }\ }
\newcounter{Sitem}
\newlength{\preSitemskip}\setlength{\preSitemskip}{0.5em}
\newlength{\postSitemskip}\setlength{\postSitemskip}{0.8em}
\newcommand{\Sitembox}{%
  \fbox{\setcounter{Sitem}{\value{Sitem}+1}\ (\alph{Sitem})\ }}
\newcommand{\Sitem}{%
  \setcounter{Sitem}{\value{Sitem}+1}\hspace{\preSitemskip}%
  (\alph{Sitem})\hspace{\postSitemskip}}
\newcommand{\resetSitem}{\setcounter{Sitem}{0}}

\def\DispCoeff#1#2{\ensuremath{
\ifnum#1>1 +#1 #2
\else\ifnum#1=1 + #2
\else\ifnum#1=-1- #2
\else\ifnum#1<-1#1 #2
\fi\fi\fi\fi
}}

\def\DispCoeffTop#1#2{\ensuremath{
\ifnum#1>1 #1 #2
\else\ifnum#1=1 #2
\else\ifnum#1=-1 - #2
\else\ifnum#1<-1 #1 #2
\fi\fi\fi\fi
}}

%DispPower{x}{1} -> x, {x}{2} -> x^2, {x}{0} -> 1, {x}^{-1} -> \bunsuu1{x}
\def\DispPower#1#2{\ensuremath{
\ifnum#2>1 #1^{#2}
\else\ifnum#2=1 #1
\else\ifnum#2=0 1
\else\ifnum#2=-1 \bunsuu1{#1}
\else\IMul\#2{-1}\TmpN \bunsuu1{#1^{\TmpN}}
\fi\fi\fi\fi
}}

%%
%\def\compiletimetdus={%
%\makeatletter\the\year-\two@digits\month-\two@digits\day\ \two@digits\hour:
%\two@digits\minute:\two@digits\second\makeatother}
\def\compiletimeid{%
\the\year\two@digits\month\two@digits\day\two@digits\hour%
\two@digits\minute}
%%%%%%%%%%%%%%%%%%%%%%
%%%%% List 処理: %%%%%
%%%%%%%%%%%%%%%%%%%%%%
% リスト #1 が空かどうかを判定する
% \if\IsListEmpty\list hogehogetrue \else hogehogefalse\fi
\let\EmptyList\@empty
\def\IsListEmpty#1{TT\fi
  \def\@arg{#1}%
  \ifx#1\@empty
}
\let\EmptyList\@empty
% リスト #1 の先頭に #2 を追加する
\def\PushList#1#2{\edef#1{#2,#1}}
% リスト #1 の末尾に #2 を追加する
\def\AppendList#1#2{\edef#1{#1,#2}}
% リスト #1 の先頭から要素を一つ取り除く
\def\PopList#1{\@tempcnta=\z@
   \let\list@save@list\@empty
   \@for\member:=#1\do{%
      \ifnum\@tempcnta=\z@
         \member
      \else
        \ifnum\@tempcnta=\@ne
           \edef\list@save@list{\member}
        \else
           \edef\list@save@list{\list@save@list,\member}%
        \fi
      \fi
      \advance\@tempcnta\@ne
   }%
   \edef#1{\list@save@list}%
}
% リスト #1 のサイズを求める
\def\SizeList#1{%
   \@tempcnta=\z@
   \@for\member:=#1\do{\advance\@tempcnta\@ne}%
   \number\@tempcnta}
% リスト #1 を逆順に並び替える
\def\ReverseList#1#2{
   \@tempcnta=\z@
   \let\list@save@list\@empty
   \@for\member:=#1\do{%
      \ifnum\@tempcnta=\z@
         \edef\list@save@list{\member}%
      \else
         \edef\list@save@list{\member,\list@save@list}%
      \fi
     \advance\@tempcnta\@ne
   }%
   \edef#2{\list@save@list}%
}
\def\ReverseListSelf#1{%
   \@tempcnta=\z@
   \let\list@save@list\@empty
   \@for\member:=#1\do{%
      \ifnum\@tempcnta=\z@
         \edef\list@save@list{\member}%
      \else
         \edef\list@save@list{\member,\list@save@list}%
      \fi
     \advance\@tempcnta\@ne
   }%
   \edef#1{\list@save@list}%
}
% リスト #1 の直和を表示する
\def\SumList#1{\@tempcnta=\z@
   \@for\member:=#1\do{\advance \@tempcnta \member}%
   \number\@tempcnta}
% リスト #1 の直積を表示する
\def\ProdList#1{\@tempcnta=\@ne
   \@for\member:=#1\do{\multiply \@tempcnta \member}%
   \number\@tempcnta}
% リストの要素を表示する
\def\ShowList{\@ifnextchar[{\@list@show}{\@list@show[\@empty]}}
% 書式 #1 付で リスト #2 を表示する
\def\@list@show[#1]#2{\@tempcnta=\z@
   \@for\member:=#2\do{\advance\@tempcnta\@ne}%
   \@for\member:=#2\do{%%%
     \ifnum\@tempcnta>\@ne
         \member#1%%
      \else
         \member%%
      \fi
      \advance\@tempcnta\m@ne
   }}
%% \jobs
\def\StripPrefix#1>{}%% same as \stripg@prefix of latex
\def\jobis#1{TT\fi
  \def\predicate{#1}%
  \@onelevel@sanitize\predicate% this is the same as below
  % \edef\predicate{\expandafter\StripPrefix\meaning\predicate}%
  \edef\job{\jobname}%
  \ifx\job\predicate
  % \ifx\jobname\predicate
}
%% isanumber? etc.
\def\IsPositive#1{TT\fi
  \ifcat_\ifnum0<0#1 _\else A\fi
}
\def\IsNonNegative#1{TT\fi
  \ifcat_\ifnum9<1#1 _\else A\fi
}
\def\gobbleminus#1{\ifx-#1\else#1\fi}
\def\IsInteger#1{TT\fi
  \ifcat_\ifnum9<1\gobbleminus#1 _\else A\fi
}
%%% http://tex.stackexchange.com/questions/43341/how-to-make-an-infix-if-variant
\def\IsShape#1{TT\fi% italic = it, bold = n
  \def\f@shapetest{#1}%
  \ifx\f@shape\f@shapetest
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%% WordCount : macro argument does work!! %%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\WordCount#1{%\@tempcnta\z@\relax%%%
  \edef\@tmp@s{#1}%%%
  \expandafter\@word@count\@tmp@s\relax%%%
}
\def\@word@count#1\relax{\@tempcnta\z@\relax%%%
  \@tfor\@x:=#1\do{%%%
    \advance\@tempcnta\@ne
  }%%%
  \number\@tempcnta%%%
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%% color definitions (xcolor) %%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \RequirePackage[dvipdfmx]{xcolor}
% \definecolor{gray95}{gray}{0.95}
% \definecolor{gray90}{gray}{0.90}
% \definecolor{gray85}{gray}{0.85}
% \definecolor{gray80}{gray}{0.80}
% \definecolor{gray70}{gray}{0.70}
% \definecolor{gray60}{gray}{0.60}
% \definecolor{gray55}{gray}{0.55}
% \definecolor{gray50}{gray}{0.50}
% \definecolor{gray40}{gray}{0.40}
% \definecolor{gray30}{gray}{0.30}
% \definecolor{gray20}{gray}{0.20}
% \definecolor{gray10}{gray}{0.10}

%%%%%%%%%%%%%%%%%%%%%
%%%%% Underline %%%%%
%%%%%%%%%%%%%%%%%%%%%
\def\udline#1{\ {\setlength{\unitlength}{0.25em}
    \IMul{#1}{4}\len
  \begin{picture}(\len,0)
    % \put(0,0){debug:\len}
    \dottedline{0.7}(0,-1.5)(\len,-1.5)
  \end{picture}}\ }

%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%% Counter related %%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcounter{Problem}
\newenvironment{Problem}%
{\begin{list}{\fbox{\arabic{Problem}}}{\usecounter{Problem}%
\setlength{\leftmargin}{2em}\setlength{\itemsep}{0pt}}}{\end{list}}

\newcounter{sub}
\newenvironment{sub}%
{\begin{list}{(\arabic{sub})}{\usecounter{sub}%
\setlength{\leftmargin}{2em}}}{\end{list}}
\newcommand{\ritem}{\addtocounter{sub}{1}\quad(\arabic{sub})\ \,}

\newcounter{subindex}
\newcommand{\subidx}[1]{\addtocounter{subindex}{1}${#1}_{\arabic{subindex}}$}
\newcommand{\resetsubidx}{\setcounter{subindex}{0}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%% kana for Counter %%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\Kana#1{\expandafter\@Kana\csname c@#1\endcsname}
\def\@Kana#1{%
  \ifcase#1\or い\or ろ\or は\or に\or ほ\or へ\or と
           \or ち\or り\or ぬ\or る\or を
           \or わ\or か\or よ\or た\or れ\or そ
           \or つ\or ね\or な\or ら\or む
           \or う\or ゐ\or の\or お\or く\or や\or ま\or け\or ふ\or こ\or え\or て
           \or あ\or さ\or き\or ゆ\or め\or み\or し\or ゑ\or ひ\or も\or せ\or す\or ん
  \else\@ctrerr\fi}
\def\KANA#1{\expandafter\@KANA\csname c@#1\endcsname}
\def\@KANA#1{%
  \ifcase#1\or イ\or ロ\or ハ\or ニ\or ホ\or ヘ\or ト
           \or チ\or リ\or ヌ\or ル\or ヲ
           \or ワ\or カ\or ヨ\or タ\or レ\or ソ
           \or ツ\or ネ\or ナ\or ラ\or ム
           \or ウ\or ノ\or オ\or ク\or ヤ\or マ\or ケ\or フ\or コ\or エ\or テ
           \or ア\or サ\or キ\or ユ\or メ\or ミ\or シ\or ヒ\or モ\or セ\or ス\or ン
  \else\@ctrerr\fi}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%% ifAns, AnsHW etc. %%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\@ifundefined{Anstrue}{\newif\ifAns}{}
% imported from LA2-head.tex / 2014.01.15
% AnsDHW is defined for only compatibility. Use AnsHW strongly recommended
\def\AnsDHW{\@ifnextchar[{\@AnsDHW}{\@AnsDHW[t]}}
\long\def\@AnsDHW[#1]#2#3#4#5{% Depth:#1(pt),Height:#2(pt),Width:#3(mm),Answer:#4
  \rule[-#2mm]{0pt}{#3mm}
  \ifAns\parbox[#1]{#4mm}{{\color{red} #5}}
  \else\hspace{#4mm}\fi}
\long\def\AnsHW#1#2#3{% #1 = total height, #2 = width, centering only
  \savebox{\tmp@box}{\parbox[c]{#2mm}{\color{red}\large #3}}%
  \tmp@ht=\ht\tmp@box\relax\tmp@dp=\dp\tmp@box%
  \tmp@rdp=#1mm\addtolength\tmp@rdp{-\tmp@ht}
  \addtolength\tmp@rdp{\tmp@dp}%
  \divide\tmp@rdp by 2
  \rule[-\tmp@rdp]{0pt}{#1mm}%
  \ifAns\usebox{\tmp@box}\else\rule[0mm]{#2mm}{0mm}\fi
}
\def\NewSeq#1#2{%
  \@tempcnta=\z@%
  \@for\@a:=#2\do{% start from index 0
    \edef\@@i{\number\@tempcnta}%
    \expandafter\xdef\csname #1:\@@i\endcsname{\@a}
    % {#1:\@@i}\csname #1:\@@i\endcsname
    \advance\@tempcnta\@ne
  }
  \expandafter\gdef\csname #1\endcsname##1{%
    \csname #1:##1\endcsname
  }
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%% emath Extentions              %%%%%
%%%%% will be moved to emathExt.sty %%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% depend on emath 
\newcommand{\InsertKaitou}{\closeKaiFile
  {\footnotesize\noindent【解答】\inputKaiFile}}
\newcommand{\InsertKaitouVfill}{\closeKaiFile
  \vfill{\footnotesize\noindent【解答】\inputKaiFile}}
\newcommand{\InsertKaitouRotate}{\closeKaiFile
  \vfill{\rotatebox{180}{\parbox[t]{\linewidth}{
        \footnotesize\noindent【解答】\inputKaiFile}}}}
%% http://ls-al.jp/blog2/item_1779.html
\def\XopenKaiFile{
\newwrite\boostream
\def\KaiFile{\jobname.csv}
\immediate\openout\boostream=\KaiFile
}
\def\XwriteKaiFile#1{%
  \edef\myTxt{#1}%
  \immediate\write\boostream{\myTxt}%
}
\def\XcloseKaiFile{
  \immediate\closeout\boostream%
}

\def\YopenKaiFile{
\newwrite\boostream
\edef\YKaiFile{\jobname-\compiletimeid.csv}
\immediate\openout\boostream=\YKaiFile
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \ifdefined\org@matrix\else% same as latex.ltx
%   \def\org@matrix#1{\null\,\vcenter{\normalbaselines\m@th
%       \ialign{\hfil$##$\hfil&&\quad\hfil$##$\hfil\crcr
%         \mathstrut\crcr\noalign{\kern-\baselineskip}
%         #1\crcr\mathstrut\crcr\noalign{\kern-\baselineskip}}}\,}\fi
\newlength{\retubecolsep}\retubecolsep=1.5pt

\def\retube#1#2{%
  \ensuremath{\begin{pmatrix}\kern\retubecolsep#1\kern\retubecolsep%
      \\#2\end{pmatrix}}}
\def\Retube#1#2#3{%
  \ensuremath{\begin{pmatrix}\kern\retubecolsep#1\kern\retubecolsep%
      \\#2\\#3\end{pmatrix}}}
\def\REtube#1#2#3#4{%
  \ensuremath{\begin{pmatrix}\kern\retubecolsep#1\kern\retubecolsep%
      \\#2\\#3\\#4\end{pmatrix}}}
\def\RETube#1#2#3#4#5{%
  \ensuremath{\begin{pmatrix}\kern\retubecolsep#1\kern\retubecolsep%
      \\#2\\#3\\#4\\#5\end{pmatrix}}}
\def\RETUbe#1#2#3#4#5#6{%
  \ensuremath{\begin{pmatrix}\kern\retubecolsep#1\kern\retubecolsep%
      \\#2\\#3\\#4\\#5\\#6\end{pmatrix}}}
% \def\Retube#1#2#3{%
%   \left(\org@matrix{\,#1\,\\\,#2\,\\\,#3\,}\right)}
% \@ifundefined{retube}{\def\retube#1#2{%
%     
% \@ifundefined{Retube}{\def\Retube#1#2#3{%
%     \ensuremath{\left(\org@matrix{\,#1\,\\\,#2\,\\\,#3\,}\right)}}}{}
% \@ifundefined{REtube}{\def\REtube#1#2#3#4{%
%     \ensuremath{\left(\org@matrix{\,#1\,\\\,#2\,\\\,#3\,\\\,#4\,}\right)}}}{}
\makeatother
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%% EOF of MyCommands.tex %%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
