% エンジン非依存のマクロ集

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{jlreq-helpers}[2022/11/28 jlreq-helpers]

\ExplSyntaxOn
%. helper1
\newcount\jlreq@tempcnta
\newcount\jlreq@tempcntb
\newcount\jlreq@tempcntc
\newdimen\jlreq@tempdima
\newdimen\jlreq@tempdimb
\newdimen\jlreq@tempdimc
\newskip\jlreq@tempskipa
\newskip\jlreq@tempskipb
\newskip\jlreq@tempskipc
\newif\ifjlreq@tempa
\newif\ifjlreq@tempb
\newif\ifjlreq@tempc
\newbox\jlreq@tempboxa
\newbox\jlreq@tempboxb
\newbox\jlreq@tempboxc
% 計算結果を返すための変数
\newdimen\jlreq@resultdimen
\newskip\jlreq@resultskip
\newbox\jlreq@resultbox
\newif\ifjlreq@result
\newcount\jlreq@resultcnt

\def\jlreq@uniqtoken{\jlreq@uniqtoken@may@be@a@bug}
\def\jlreq@endmark{\jlreq@endmark@may@be@a@bug}
\long\def\jlreq@deleteuntileendmark#1\jlreq@endmark{}

\def\jlreq@expandafter@ii{\expandafter\expandafter\expandafter}
\edef\jlreq@expandafter@iii{\exp_not:o {\jlreq@expandafter@ii}\noexpand\expandafter\exp_not:o {\jlreq@expandafter@ii}}
\edef\jlreq@expandtwice#1{\exp_not:o {\jlreq@expandafter@ii}\noexpand\unexpanded\exp_not:o {\jlreq@expandafter@ii}{#1}}
\edef\jlreq@expand@three#1{\exp_not:o {\jlreq@expandafter@iii}\noexpand\unexpanded\exp_not:o {\jlreq@expandafter@iii}{#1}}

% \jlreq@getfirsttoken#1\jlreq@uniqtoken{}\jlreq@endmark@の形で使う
% 二回展開すると，#1の先頭（ただし空白は無視される）を取り出す．#1が空の場合は\jlreq@uniqtoken，先頭が{の場合は\bgroupとなる
\def\jlreq@endmark@{\jlreq@endmark@@may@be@a@bug} % \jlreq@getfirsttokenだけのためのendmark
\long\def\jlreq@getfirsttoken#1#{\jlreq@getfirsttoken@#1\bgroup\jlreq@endmark@}
\long\def\jlreq@getfirsttoken@#1#2\jlreq@endmark@#3\jlreq@endmark@{#1}
% 与えられたトークン列が空か（展開はしないでチェック）
\long\def\jlreq@ifempty#1{\expandafter\ifx\expandafter\relax\detokenize{#1}\relax\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi}
% #1の先頭トークンが#2か（ただし#1が空ならば#2=\jlreq@uniqtoken，#1={ならば#2=\bgroupでTRUEとなる）
\long\edef\jlreq@iffirsttoken#1#2{%
  % スペースチェック
  \unexpanded{\expandafter\expandafter\expandafter\jlreq@deleteuntileendmark\expandafter\ifx\expandafter}\exp_not:o {\space}\noexpand\detokenize{#1}\unexpanded{\@undefined\jlreq@endmark\expandafter\@firstoftwo\else\jlreq@endmark\expandafter\@secondoftwo\fi}{%
    \noexpand\ifx\exp_not:o {\space}#2\unexpanded{\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi}%
  }{%
    \noexpand\jlreq@iffirsttoken@ignorespaces{#1}{#2}%
  }%
}
% こちらは先頭のスペースを読み飛ばす
\long\def\jlreq@iffirsttoken@ignorespaces#1#2{%
  \expandafter\expandafter\expandafter\ifx\jlreq@getfirsttoken#1\jlreq@uniqtoken{}\jlreq@endmark@#2\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi
}

% #1が\jlreq@endmarkか
\long\def\jlreq@ifendmark#1{\jlreq@iffirsttoken{#1}{\jlreq@endmark}}

% 条件．\jlreq@if{\ifnum\@count=1 \fi}{<TRUE>}{<FALSE>}みたいに使う
\def\jlreq@if@endmark{\jlreq@if@endmark}
\long\def\jlreq@if#1{\jlreq@if@#1\jlreq@if@endmark}
\@gobbletwo\if\if
\long\def\jlreq@if@#1\fi\jlreq@if@endmark{#1\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi}

% #1の先頭が引数なしのマクロか
\long\def\jlreq@ifmacro@noargument#1{%
  \jlreq@ifempty{#1}{\@secondoftwo}{%
    \jlreq@iffirsttoken{#1}{~}{\@secondoftwo}{%
      \expandafter\expandafter\expandafter\jlreq@ifmacro@noargument@\jlreq@getfirsttoken#1\jlreq@uniqtoken{}\jlreq@endmark@
}}}
\long\def\jlreq@ifmacro@noargument@#1{\expandafter\jlreq@ifmacro@noargument@@\expandafter{\meaning #1}}
\def\@tempa#1{%
  \def\jlreq@ifmacro@noargument@@##1{\jlreq@ifmacro@noargument@@@##1#1\noexpand\jlreq@endmark}
  \def\jlreq@ifmacro@noargument@@@##1#1##2\jlreq@endmark{\jlreq@ifempty{##1}}
}
\edef\jlreq@do{\noexpand\@tempa{\detokenize{macro:->}}}
\jlreq@do
% こちらは単にマクロか
\def\@tempa#1{%
  \long\def\jlreq@ifmacro##1{\jlreq@ifempty{##1}{\@secondoftwo}{\expandafter\jlreq@ifmacro@i\meaning##1#1\jlreq@endmark}}
  \long\def\jlreq@ifmacro@i##1#1##2\jlreq@endmark{\jlreq@ifempty{##1}}
}
\edef\jlreq@do{\noexpand\@tempa{\detokenize{macro:}}}
\jlreq@do



% #1（skipレジスタ）が0か（展開不可）．
\newcommand*\jlreq@ifgluezero[1]{%
  \begingroup
    \edef\@tempa{\the#1}%
    \edef\@tempb{\detokenize{0.0pt}}%
    \edef\jlreq@do{\ifx\@tempa\@tempb\noexpand\@firstoftwo\else\noexpand\@secondoftwo\fi}%
  \expandafter\endgroup
  \jlreq@do
}

% #1が#2で終わるか（展開不可）
\newcommand*{\jlreq@ifendswith}[2]{%
  \jlreq@ifempty{#2}{\@firstoftwo}{%
    \begingroup
      \def\jlreq@tempa##1#2\jlreq@uniqtoken##2\jlreq@endmark{%
        \edef\jlreq@do{\jlreq@ifempty{##2}{\noexpand\@secondoftwo}{\noexpand\@firstoftwo}}%
      }%
      \jlreq@tempa#1\jlreq@uniqtoken#2\jlreq@uniqtoken\jlreq@endmark
    \expandafter\endgroup
    \jlreq@do
  }%
}
% #1が#2で始まるか（展開不可）
\newcommand*{\jlreq@ifstartswith}[2]{%
  \jlreq@ifempty{#2}{\@firstoftwo}{%
    \jlreq@ifempty{#1}{\@secondoftwo}{%
      \begingroup
        \def\jlreq@tempa##1#2##2\jlreq@endmark{%
          \edef\jlreq@do{\jlreq@ifempty{##1}{\noexpand\@firstoftwo}{\noexpand\@secondoftwo}}%
        }%
        \jlreq@tempa#1#2\jlreq@endmark
      \expandafter\endgroup
      \jlreq@do
    }%
  }%
}
% #1が#2を含むか（展開不可）{}内に#2があってもFALSE判定．
\newcommand*{\jlreq@ifcontains}[2]{%
  \jlreq@ifempty{#2}{\@firstoftwo}{%
    \begingroup
      \def\jlreq@tempa##1#2##2\jlreq@endmark{%
        \edef\jlreq@do{\jlreq@ifempty{##2}{\noexpand\@secondoftwo}{\noexpand\@firstoftwo}}%
      }%
      \jlreq@tempa#1#2\jlreq@endmark
    \expandafter\endgroup
    \jlreq@do
  }%
}

% @removeelementの括弧があっても動くかもしれない版
% #2から#1を消して#3に入れる
\newcommand*{\jlreq@helper@removeelement}[3]{%
  \begingroup
    \edef\jlreq@tempa{\unexpanded{#1}}% 消したいやつ
    \def\jlreq@tempb{}% 消していない分を放り込んでいく
    \jlreq@tempatrue% 最初の\jlreq@tempbへの追加か．
    \jlreq@helper@removeelement@#2,\jlreq@endmark,%
    \edef\jlreq@do{\unexpanded{\def#3}{\exp_not:o {\jlreq@tempb}}}%
  \expandafter\endgroup
  \jlreq@do
}
\def\jlreq@helper@removeelement@#1,{%
  \jlreq@ifendmark{#1}{}{%
    \edef\@tempa{\unexpanded{#1}}%
    \ifx\jlreq@tempa\@tempa\expandafter\@gobble\else\expandafter\@firstofone\fi{%
      \tl_put_right:Nx \jlreq@tempb{\ifjlreq@tempa\else,\fi\unexpanded{#1}}%
      \jlreq@tempafalse
    }%
    \jlreq@helper@removeelement@
  }%
}

% 空白を無視しない\@ifnextchar
\newcommand{\jlreq@ifnextchar}[3]{%
  \let\reserved@d=#1%
  \edef\reserved@a{\unexpanded{#2}}%
  \edef\reserved@b{\unexpanded{#3}}%
  \futurelet\jlreq@nextchar\jlreq@ifnextchar@
}
\def\jlreq@ifnextchar@{%
  \ifx\jlreq@nextchar\reserved@d\let\reserved@b\reserved@a\fi
  \reserved@b
}
% 空白を無視しない\@ifsart
\newcommand*{\jlreq@ifstar}[2]{\jlreq@ifnextchar *{\edef\reserved@a*{\unexpanded{#1}}\reserved@a}{#2}}

% カンマで区切って，その前と後ろを\jlreq@resulta,\jlreq@resultbに入れる
% もしカンマがない場合は\ifjlreq@resultがfalseになる．
\newcommand*{\jlreq@helper@dividebycomma}[1]{\jlreq@helper@dividebycomma@#1,\jlreq@endmark}
\long\def\jlreq@helper@dividebycomma@#1,#2\jlreq@endmark{%
  \jlreq@helper@trim{#1}{\jlreq@resulta}%
  \jlreq@helper@trim{#2}{\jlreq@resultb}%
  \jlreq@if{\ifx\jlreq@resultb\@empty\fi}{%
    \jlreq@resultfalse
  }{%
    \jlreq@resulttrue
    \expandafter\def\expandafter\jlreq@resultb\expandafter{\jlreq@helper@removelastcomma#2\jlreq@endmark}%
    \expandafter\jlreq@helper@trim\expandafter{\jlreq@resultb}{\jlreq@resultb}%
  }%
}
\long\def\jlreq@helper@removelastcomma#1,\jlreq@endmark{#1}

% vbox #1の最後を\jlreq@resultboxに入れる
% #1の最後の行は消える
\newcommand*{\jlreq@getlastbox}[1]{%
  \setbox#1=\vbox{\unvbox#1\relax
    \unskip\unskip\unpenalty\global\setbox\jlreq@resultbox=\lastbox}%
  \ifhbox\jlreq@resultbox
    \global\setbox\jlreq@resultbox=\hbox{%
      \unhbox\jlreq@resultbox\unskip\unskip\unpenalty}%
  \else
    \global\setbox\jlreq@resultbox=\copy\voidb@x
  \fi
}

% キー指定しないkeyval（独自実装）
% \jlreq@parsekeyval@nokey{<action>}{<parse対象>}
% action内では#1=key, #2=val
% \ifjlreq@parsekeyval@nokey@novalue{<true code>}{<false code>}でvalueがないか判定できる．
% *つきは<parse対象>を一回だけ展開する．
\def\jlreq@parsekeyval@nokey{\@ifstar{\jlreq@parsekeyval@nokey@{*}}{\jlreq@parsekeyval@nokey@{}}}
\newcommand{\jlreq@parsekeyval@nokey@}[3]{%
  \begingroup
    \long\def\jlreq@do{}%
    \long\def\jlreq@parsekeyval@nokey@execute##1##2{#2}%
    \jlreq@ifempty{#1}{%
      \jlreq@parsekeyval@nokey@i@wuniq\jlreq@uniqtoken#3,\jlreq@endmark,%
    }{%
      \expandafter\jlreq@parsekeyval@nokey@i@wuniq\expandafter\jlreq@uniqtoken#3,\jlreq@endmark,%
    }%
  \expandafter\endgroup
  \jlreq@do
}
\long\def\jlreq@parsekeyval@nokey@i@wuniq#1,{\expandafter\jlreq@parsekeyval@nokey@i\expandafter{\@gobble#1}}
\long\def\jlreq@parsekeyval@nokey@i#1{\jlreq@ifendmark{#1}{}{\jlreq@parsekeyval@nokey@ii@wuniq\jlreq@uniqtoken#1=\jlreq@endmark}}
\long\def\jlreq@parsekeyval@nokey@ii@wuniq#1=#2\jlreq@endmark{\expandafter\jlreq@parsekeyval@nokey@ii\expandafter{\@gobble#1}{#2}}%
\long\def\jlreq@parsekeyval@nokey@ii#1#2{%
  \jlreq@ifempty{#2}{\jlreq@parsekeyval@nokey@iii{*}{#2}{#1}}{%
    \edef\jlreq@tempa{%
      \noexpand\jlreq@parsekeyval@nokey@iii{}{\jlreq@parsekeyval@nokey@removeequal{#2}}{\unexpanded{#1}}%
    }%
    \jlreq@tempa
  }%
}
% valueが与えられていない場合は#1=*になる．そうでなければ#1は空
\long\def\jlreq@parsekeyval@nokey@iii#1#2#3{%
  \jlreq@remove@spaceandbracket{#2}{\jlreq@tempa}%
  \jlreq@remove@spaceandbracket{#3}{\jlreq@tempb}%
  \ifx\jlreq@tempb\@empty\else
    \edef\@tempa{\noexpand\jlreq@parsekeyval@nokey@iv{#1}{\exp_not:o {\jlreq@tempb}}{\exp_not:o {\jlreq@tempa}}}%
    \@tempa
  \fi
  \jlreq@parsekeyval@nokey@i@wuniq\jlreq@uniqtoken
}
\long\def\jlreq@parsekeyval@nokey@iv#1#2#3{%
  \tl_put_right:Nx \jlreq@do{%
    \unexpanded{\let\ifjlreq@parsekeyval@nokey@novalue}\jlreq@ifempty{#1}{\noexpand\@secondoftwo}{\noexpand\@firstoftwo}%
    \exp_not:o {\jlreq@parsekeyval@nokey@execute{#2}{#3}}%
  }%
}
\long\def\jlreq@parsekeyval@nokey@removeequal#1{\jlreq@parsekeyval@nokey@removeequal@\jlreq@uniqtoken#1\jlreq@endmark}
\long\def\jlreq@parsekeyval@nokey@removeequal@#1=\jlreq@endmark{\expandafter\unexpanded\expandafter{\@gobble#1}}

% #1の先頭のスペースを削除し，#2に入れる．
\long\def\jlreq@helper@trim#1#2{\edef#2{\tl_trim_spaces:n{#1}}}

\long\def\jlreq@remove@spaceandbracket#1#2{%
  \begingroup
    \jlreq@helper@trim{#1}{\jlreq@tempa}%
    \edef\jlreq@do{\unexpanded{\jlreq@remove@spaceandbracket@{#2}}\exp_not:o {\jlreq@tempa}\noexpand\jlreq@endmark}%
  \expandafter\endgroup
  \jlreq@do
}
\long\def\jlreq@remove@spaceandbracket@#1#2\jlreq@endmark{\edef#1{\unexpanded{#2}}}

% \jlreq@switch{str}{
%   {str}{abcd}
%   {str1}{xyz}
%}[default: input = #1] -> abcd
%または
%
% \jlreq@switch{str}{
%   {str}{abcd}
%   {str1}{xyz}
%   {default} % ここは#1を受け付けない（パラメータトークンを受け付けたい場合のため）．
%} -> abcd
% strは\edefで展開されるが，\jlreq@switch*の場合は展開されない．
% 第一引数は\jlreq@tempaに入れておく．
\long\def\jlreq@helper@switch@executeoption#1[#2]{%
  \begingroup
    \def\jlreq@do##1{#2}%
  \expandafter\endgroup
  \jlreq@do{#1}%
}
\long\def\jlreq@helper@removeoption[#1]{}
\newcommand{\jlreq@switch}{\@ifstar{\jlreq@switch@{*}}{\jlreq@switch@{}}}
\newcommand{\jlreq@switch@}[3]{%
  \begingroup
    \let\jlreq@do\@undefined
    \edef\jlreq@tempa{\jlreq@ifempty{#1}{#2}{\unexpanded{#2}}}% ループ中ずっと保存する
    \jlreq@helper@switch@{#1}#3\jlreq@endmark
    \ifx\jlreq@do\@undefined
      \edef\jlreq@do{\unexpanded{\jlreq@ifnextchar[{\jlreq@helper@switch@executeoption{#2}}{}}}%
    \else
      \tl_put_right:Nn \jlreq@do{\@ifnextchar[{\jlreq@helper@removeoption}{}}%
    \fi
  \expandafter\endgroup
  \jlreq@do
}
\long\def\jlreq@helper@switch@#1#2{%
  \jlreq@ifendmark{#2}{}{\jlreq@helper@switch@@{#1}{#2}}%
}

\long\def\jlreq@helper@switch@@#1#2#3{%
  \jlreq@ifendmark{#3}{%
    \edef\jlreq@do{\unexpanded{#2}}%
  }{%
    \edef\jlreq@tempb{\jlreq@ifempty{#1}{#2}{\unexpanded{#2}}}%
    \jlreq@if{\ifx\jlreq@tempa\jlreq@tempb\fi}{%
      \edef\jlreq@do{\unexpanded{#3}}%
      \jlreq@deleteuntileendmark
    }{%
      \jlreq@helper@switch@{#1}%
    }%
  }%
}

% オレオレラベル……
% \jlreq@reference@ref{ラベル名}{デフォルト値}
\def\jlreq@reference@ref#1{\jlreq@if{\expandafter\unless\expandafter\ifx\csname jlreq@reference@#1\endcsname\relax\fi}{\csname jlreq@reference@#1\endcsname}}
% \jlreq@reference@label{ラベル名}{値}
\long\def\jlreq@reference@label#1#2{\protected@write\@auxout{}{\string\@newl@bel{jlreq@reference}{#1}{#2}}}%
\long\def\jlreq@reference@immediate@write#1#2{\immediate\write\@auxout{\string\@newl@bel{jlreq@reference}{#1}{#2}}}%
\long\def\jlreq@reference@ifexist#1{\jlreq@if{\expandafter\unless\expandafter\ifx\csname jlreq@reference@#1\endcsname\relax\fi}}

% 自動生成されるラベル用の番号
\newcount\jlreq@reference@count
\jlreq@reference@count=0

% 現在のページを得る
\newcount\jlreq@currentpage
\newcommand*{\jlreq@setcurrentpage}{%
  \global\advance\jlreq@reference@count by 1
  \jlreq@reference@label{jlreq@currentpage.\the\jlreq@reference@count}{\noexpand\arabic{page}}%
  \global\jlreq@currentpage=\jlreq@reference@ref{jlreq@currentpage.\the\jlreq@reference@count}{\the\c@page}\relax
}

% 先頭にあるマクロを展開しまくった結果の先頭を#2に入れる．
\newcommand{\jlreq@getfirsttoken@expandmacros}[2]{%
  \jlreq@iffirsttoken{#1}{~}{\def#2{~}}{%
    \jlreq@ifempty{#1}{\def#2{}}{%
      \jlreq@ifmacro@noargument{#1}{%
        \expandafter\jlreq@getfirsttoken@expandmacros\expandafter{#1}{#2}%
      }{%
        \expandafter\expandafter\expandafter\jlreq@getfirsttoken@expandmacros@\jlreq@getfirsttoken#1\jlreq@uniqtoken{}\jlreq@endmark@{#2}%
      }%
    }%
  }%
}
\long\def\jlreq@getfirsttoken@expandmacros@#1#2{\def#2{#1}}

\long\def\jlreq@helper@checktokenlist#1#2{%
  \jlreq@ifendmark{#2}{\@firstoftwo}%
  {%
    \jlreq@if{\ifnum0#1{#2}>0~\fi}%
      {\jlreq@helper@checktokenlist{#1}}%
      {\expandafter\@secondoftwo\jlreq@deleteuntileendmark}%
  }%
}
\def\jlreq@helper@chknumlist#1{\ifx#101\fi\ifx#111\fi\ifx#121\fi\ifx#131\fi\ifx#141\fi\ifx#151\fi\ifx#161\fi\ifx#171\fi\ifx#181\fi\ifx#191\fi}
\def\jlreq@helper@chkfloatlist#1{\jlreq@helper@chknumlist{#1}\ifx#1.1\fi}
% #1が[0-9\.]*に当てはまるか．
\newcommand*{\jlreq@iffloat}[1]{\jlreq@helper@checktokenlist{\jlreq@helper@chkfloatlist}#1\jlreq@endmark}
\newcommand*{\jlreq@ifnumber}[1]{\jlreq@helper@checktokenlist{\jlreq@helper@chknumlist}#1\jlreq@endmark}

% \jlreq@ifprimitive#1#2#3: #1がprimitiveならば#2を，そうでなければ#3を実行する
% （\if(pdf)primitiveを避けるようにしている．）
\newcommand*{\jlreq@ifprimitive}[1]{%
  \begingroup
    \edef\@tempa{\string#1}%
    \edef\@tempb{\meaning#1}%
  \expandafter\endgroup
  \ifx\@tempa\@tempb\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi
}

\newcommand*{\jlreq@helper@guessengine}{%
  \token_if_primitive:NTF \directlua {
    \let\jlreq@result=l
  }{
    \let\jlreq@result=p
    \token_if_primitive:NT \ucs {
      \int_compare:nT { \ucs"FA4A = "FA4A } {
        \let\jlreq@result=u
      }
    }
  }
}

% #1を\@undefinedに，既に\@undefinedならば#2{#1}を呼ぶ
\newcommand*{\jlreq@helper@undefcs}[2]{%
  \@ifundefined{\expandafter\@gobble\string #1}{#2{#1}}{\cs_undefine:N #1}%
}
% \if版
\newcommand*{\jlreq@helper@undefif}[2]{%
  \@ifundefined{\expandafter\@gobble\string #1}{%
    \edef\@tempa{\expandafter\@gobble\string#1}%
    \edef\@tempa{\expandafter\@gobbletwo\@tempa}%
    \cs_undefine:N #1%
    \cs_undefine:c {\@tempa true}
    \cs_undefine:c {\@tempa false}
  }%
}

% 紙サイズ一覧
\@namedef{jlreq@helper@papersizelist@a0paper}{{841mm}{1189mm}}
\@namedef{jlreq@helper@papersizelist@a1paper}{{594mm}{841mm}}
\@namedef{jlreq@helper@papersizelist@a2paper}{{420mm}{594mm}}
\@namedef{jlreq@helper@papersizelist@a3paper}{{297mm}{420mm}}
\@namedef{jlreq@helper@papersizelist@a4paper}{{210mm}{297mm}}
\@namedef{jlreq@helper@papersizelist@a5paper}{{148mm}{210mm}}
\@namedef{jlreq@helper@papersizelist@a6paper}{{105mm}{148mm}}
\@namedef{jlreq@helper@papersizelist@a7paper}{{74mm}{105mm}}
\@namedef{jlreq@helper@papersizelist@a8paper}{{52mm}{74mm}}
\@namedef{jlreq@helper@papersizelist@a9paper}{{37mm}{52mm}}
\@namedef{jlreq@helper@papersizelist@a10paper}{{26mm}{37mm}}

\@namedef{jlreq@helper@papersizelist@b0paper}{{1000mm}{1414mm}}
\@namedef{jlreq@helper@papersizelist@b1paper}{{707mm}{1000mm}}
\@namedef{jlreq@helper@papersizelist@b2paper}{{500mm}{707mm}}
\@namedef{jlreq@helper@papersizelist@b3paper}{{353mm}{500mm}}
\@namedef{jlreq@helper@papersizelist@b4paper}{{250mm}{353mm}}
\@namedef{jlreq@helper@papersizelist@b5paper}{{176mm}{250mm}}
\@namedef{jlreq@helper@papersizelist@b6paper}{{125mm}{176mm}}
\@namedef{jlreq@helper@papersizelist@b7paper}{{88mm}{125mm}}
\@namedef{jlreq@helper@papersizelist@b8paper}{{63mm}{88mm}}
\@namedef{jlreq@helper@papersizelist@b9paper}{{44mm}{63mm}}
\@namedef{jlreq@helper@papersizelist@b10paper}{{31mm}{44mm}}

\@namedef{jlreq@helper@papersizelist@b0j}{{1030mm}{1456mm}}
\@namedef{jlreq@helper@papersizelist@b1j}{{728mm}{1030mm}}
\@namedef{jlreq@helper@papersizelist@b2j}{{515mm}{728mm}}
\@namedef{jlreq@helper@papersizelist@b3j}{{364mm}{515mm}}
\@namedef{jlreq@helper@papersizelist@b4j}{{257mm}{364mm}}
\@namedef{jlreq@helper@papersizelist@b5j}{{182mm}{257mm}}
\@namedef{jlreq@helper@papersizelist@b6j}{{128mm}{182mm}}
\@namedef{jlreq@helper@papersizelist@b7j}{{91mm}{128mm}}
\@namedef{jlreq@helper@papersizelist@b8j}{{64mm}{91mm}}
\@namedef{jlreq@helper@papersizelist@b9j}{{45mm}{64mm}}
\@namedef{jlreq@helper@papersizelist@b10j}{{32mm}{45mm}}

\@namedef{jlreq@helper@papersizelist@c2paper}{{458mm}{648mm}}
\@namedef{jlreq@helper@papersizelist@c3paper}{{324mm}{458mm}}
\@namedef{jlreq@helper@papersizelist@c4paper}{{229mm}{324mm}}
\@namedef{jlreq@helper@papersizelist@c5paper}{{162mm}{229mm}}
\@namedef{jlreq@helper@papersizelist@c6paper}{{114mm}{162mm}}
\@namedef{jlreq@helper@papersizelist@c7paper}{{81mm}{114mm}}
\@namedef{jlreq@helper@papersizelist@c8paper}{{57mm}{81mm}}

\@namedef{jlreq@helper@papersizelist@a4var}{{210mm}{283mm}}
\@namedef{jlreq@helper@papersizelist@b5var}{{182mm}{230mm}}

\@namedef{jlreq@helper@papersizelist@letterpaper}{{8.5in}{11in}}
\@namedef{jlreq@helper@papersizelist@legalpaper}{{8.5in}{14in}}
\@namedef{jlreq@helper@papersizelist@executivepaper}{{7.25in}{10.5in}}
\@namedef{jlreq@helper@papersizelist@hagaki}{{100mm}{148mm}}

\@namedef{jlreq@helper@papersizelist@ansiapaper}{{8.5in}{11in}}
\@namedef{jlreq@helper@papersizelist@ansibpaper}{{11in}{17in}}
\@namedef{jlreq@helper@papersizelist@ansicpaper}{{17in}{22in}}
\@namedef{jlreq@helper@papersizelist@ansidpaper}{{22in}{34in}}
\@namedef{jlreq@helper@papersizelist@ansiepaper}{{34in}{44in}}


% #1÷#2を\jlreq@resultdimenに入れる．（#1,#2は寸法を与える．）
\newcommand*{\jlreq@helper@divide}[2]{%
  \begingroup
    \@tempdima=\dimexpr#1\relax\@tempdimb=\dimexpr#2\relax
    % 分母を正にする
    \ifdim\@tempdimb<0pt \@tempdima=-\@tempdima\@tempdimb=-\@tempdimb\fi
    % \jlreq@tempdima*\@tempdimb <= \@tempdima < (\jlreq@tempdima + 1)*\@tempdimb
    % となる整数\jlreq@tempdimaを捜し，\jlreq@tempdimb=\jlreq@tempdima + 1とする
    \jlreq@tempdima=0pt
    \ifdim\@tempdima<0pt
      \loop\ifdim\strip@pt\jlreq@tempdima\@tempdimb>\@tempdima\advance\jlreq@tempdima by -1pt\repeat
    \else
      \loop\ifdim\strip@pt\jlreq@tempdima\@tempdimb<\@tempdima\advance\jlreq@tempdima by 1pt\repeat
      \ifdim\strip@pt\jlreq@tempdima\@tempdimb=\@tempdima\else\advance\jlreq@tempdima by -1pt\fi
    \fi
    \jlreq@tempdimb=\dimexpr\jlreq@tempdima + 1pt\relax
    % \jlreq@tempdimaと\jlreq@tempdimbで挟んでいく二分法
    \jlreq@tempcnta=0 % 無限ループを避けるためのカウンタ
    \loop\ifnum\numexpr\ifdim\dimexpr\jlreq@tempdimb - \jlreq@tempdima\relax>1sp 1\else0\fi*\ifnum\jlreq@tempcnta<100~1\else 0\fi\relax=1
      \jlreq@tempdimc=\dimexpr(\jlreq@tempdima+\jlreq@tempdimb)/2\relax
      \ifdim\strip@pt\jlreq@tempdimc\@tempdimb>\@tempdima\jlreq@tempdimb=\jlreq@tempdimc
      \else\jlreq@tempdima=\jlreq@tempdimc\fi
      \advance\jlreq@tempcnta by 1\relax
    \repeat
    \edef\jlreq@do{\noexpand\jlreq@resultdimen=\the\jlreq@tempdima\noexpand\relax}%
  \expandafter\endgroup
  \jlreq@do
}


\def\jlreq@helper@swap#1#2{%
  \let\jlreq@helper@swaptoken=#1%
  \let#1=#2%
  \let#2=\jlreq@helper@swaptoken
  \let\jlreq@helper@swaptoken=\@undefined
}
\def\jlreq@helper@swap@register#1#2{%
  \edef\jlreq@helper@swaptoken{\the#1}%
  #1=#2%
  #2=\jlreq@helper@swaptoken\relax
  \let\jlreq@helper@swaptoken=\@undefined
}
\ExplSyntaxOff

\endinput

