\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{jlreq-trimmarks}[2021/08/12 jlreq-trimmarks]
\RequirePackage{l3keys2e}
\RequirePackage{jlreq-helpers}

\ExplSyntaxOn
% check \tombowdatetrue
\ifx\tombowdatetrue\@undefined
  \PackageError{jlreq-trimmarks}{This~package~only~works~with~pLaTeX,~upLaTeX~or~LuaTeX-ja}{\@ehc}
\fi

\cs_set:Nn \__jlreq_trimmarks_undeferr:n {\ClassError{jlreq-trimmarks}{Trying~to~delete~\string#1~even~though~it~is~not~defined,~may~be~a~bug}{\@ehc}}
% クラスファイル内でしか使わないマクロをクラスファイル終了時に未定義にする
\seq_new:N \g__jlreq_trimmarks_afterpkg_deletecs_seq
\seq_new:N \g__jlreq_trimmarks_afterpkg_deleteif_seq
\cs_set:Nn \__jlreq_trimmarks_afterpkg_addtodeletecs:N {
  \seq_gput_right:Nn \g__jlreq_trimmarks_afterpkg_deletecs_seq {#1}
}
\__jlreq_trimmarks_afterpkg_addtodeletecs:N \__jlreq_trimmarks_afterpkg_addtodeletecs:N
\cs_set:Nn \__jlreq_trimmarks_afterpkg_addtodeleteif:N {
  \seq_gput_right:Nn \g__jlreq_trimmarks_afterpkg_deleteif_seq {#1}
}
\__jlreq_trimmarks_afterpkg_addtodeletecs:N \__jlreq_trimmarks_afterpkg_addtodeleteif:N
\AtEndOfPackage{%
  \seq_map_inline:Nn \g__jlreq_trimmarks_afterpkg_deletecs_seq {
    \jlreq@helper@undefcs{#1}{\__jlreq_trimmarks_undeferr:n}
  }
  \seq_map_inline:Nn \g__jlreq_trimmarks_afterpkg_deleteif_seq {
    \jlreq@helper@undefif{#1}{\__jlreq_trimmarks_undeferr:n}
  }
  \cs_undefine:N \g__jlreq_trimmarks_afterpkg_deletecs_seq
  \cs_undefine:N \g__jlreq_trimmarks_afterpkg_deleteif_seq
  \cs_undefine:N \__jlreq_trimmarks_undeferr:n
}

\@ifclassloaded{jlreq}{\let\ifjlreq@trimmarks@jlreqloaded=\@firstoftwo}{\let\ifjlreq@trimmarks@jlreqloaded=\@secondoftwo}

\def\ifjlreq@trimmarks@tate@{\jlreq@if{\if@tate\fi}}%
% \@firstoftwo when \if@tate is defined and \if@tate=\iftrue
\def\ifjlreq@trimmarks@tate{%
  \jlreq@if{\ifnum0\ifx\if@tate\@undefined 1\fi\ifx\if@tate\relax 1\fi>0~\fi}{\@secondoftwo}{\ifjlreq@trimmarks@tate@}%
}

% dvipdfmx=f，dvips=s，dviout = o, lualatex = l
\keys_define:nn { jlreq-trimmarks } { dvipdfmx .code:n = {\let\jlreq@trimmarks@driver=f}, .value_forbidden:n = true }
\keys_define:nn { jlreq-trimmarks } { dvips .code:n = {\let\jlreq@trimmarks@driver=s}, .value_forbidden:n = true }
\keys_define:nn { jlreq-trimmarks } { dviout .code:n = {\let\jlreq@trimmarks@driver=o}, .value_forbidden:n = true }
\let\jlreq@trimmarks@engine=\jlreq@engine
\keys_define:nn { jlreq-trimmarks } { lualatex .code:n = {\let\jlreq@trimmarks@engine=l}, .value_forbidden:n = true }
\keys_define:nn { jlreq-trimmarks } { uplatex .code:n = {\let\jlreq@trimmarks@engine=u}, .value_forbidden:n = true }
\keys_define:nn { jlreq-trimmarks } { platex .code:n = {\let\jlreq@trimmarks@engine=p}, .value_forbidden:n = true }

\def\jlreq@trimmarks@switchpapersize{}
\def\jlreq@trimmarks@addpapersize#1{%
  \@ifnextchar[{\jlreq@trimmarks@addpapersize@{#1}}{\jlreq@trimmarks@addpapersize@@{#1}}
}
\def\jlreq@trimmarks@addpapersize@#1[#2]{%
  \edef\@tempa{\unexpanded{\jlreq@trimmarks@addpapersize@@{#1}}\exp_not:v {jlreq@helper@papersizelist@#2}}%
  \@tempa
}
\newcommand*{\jlreq@trimmarks@addpapersize@@}[3]{%
  \clist_map_variable:nNn {#1} \@tempa {
    \tl_put_right:Nx \jlreq@trimmarks@switchpapersize {{\exp_not:o {\@tempa}}{\unexpanded{\def\jlreq@resulta{#2}\def\jlreq@resultb{#3}}}}%
  }%
}
\__jlreq_trimmarks_afterpkg_addtodeletecs:N \jlreq@trimmarks@switchpapersize
\__jlreq_trimmarks_afterpkg_addtodeletecs:N \jlreq@trimmarks@addpapersize
\__jlreq_trimmarks_afterpkg_addtodeletecs:N \jlreq@trimmarks@addpapersize@
\__jlreq_trimmarks_afterpkg_addtodeletecs:N \jlreq@trimmarks@addpapersize@@

\jlreq@trimmarks@addpapersize{a0,A0}[a0]
\jlreq@trimmarks@addpapersize{a1,A1}[a1]
\jlreq@trimmarks@addpapersize{a2,A2}[a2]
\jlreq@trimmarks@addpapersize{a3,A3}[a3]
\jlreq@trimmarks@addpapersize{a4,A4}[a4]
\jlreq@trimmarks@addpapersize{a5,A5}[a5]
\jlreq@trimmarks@addpapersize{a6,A6}[a6]
\jlreq@trimmarks@addpapersize{a7,A7}[a7]
\jlreq@trimmarks@addpapersize{a8,A8}[a8]
\jlreq@trimmarks@addpapersize{a9,A9}[a9]
\jlreq@trimmarks@addpapersize{a10,A10}[a10]

\jlreq@trimmarks@addpapersize{b0,B0}[b0]
\jlreq@trimmarks@addpapersize{b1,B1}[b1]
\jlreq@trimmarks@addpapersize{b2,B2}[b2]
\jlreq@trimmarks@addpapersize{b3,B3}[b3]
\jlreq@trimmarks@addpapersize{b4,B4}[b4]
\jlreq@trimmarks@addpapersize{b5,B5}[b5]
\jlreq@trimmarks@addpapersize{b6,B6}[b6]
\jlreq@trimmarks@addpapersize{b7,B7}[b7]
\jlreq@trimmarks@addpapersize{b8,B8}[b8]
\jlreq@trimmarks@addpapersize{b9,B9}[b9]
\jlreq@trimmarks@addpapersize{b10,B10}[b10]

\jlreq@trimmarks@addpapersize{c2,C2}[c2]
\jlreq@trimmarks@addpapersize{c3,C3}[c3]
\jlreq@trimmarks@addpapersize{c4,C4}[c4]
\jlreq@trimmarks@addpapersize{c5,C5}[c5]
\jlreq@trimmarks@addpapersize{c6,C6}[c6]
\jlreq@trimmarks@addpapersize{c7,C7}[c7]
\jlreq@trimmarks@addpapersize{c8,C8}[c8]

\jlreq@trimmarks@addpapersize{a4var}[a4var]
\jlreq@trimmarks@addpapersize{b5var}[b5var]

\jlreq@trimmarks@addpapersize{letter}[letter]
\jlreq@trimmarks@addpapersize{legal}[legal]
\jlreq@trimmarks@addpapersize{executive}[executive]
\jlreq@trimmarks@addpapersize{hagaki}[hagaki]

% width -> \jlreq@resulta, height -> \jlreq@resultb
\edef\jlreq@trimmarks@analyzepapersize#1{
  \noexpand\jlreq@switch{#1}{
    \exp_not:o {\jlreq@trimmarks@switchpapersize}%
    {%
      \noexpand\jlreq@helper@dividebycomma{#1}%
      \unexpanded{\ifjlreq@result\else}%
        \unexpanded{\def\jlreq@resulta}{#1}%
        \unexpanded{\def\jlreq@resultb}{#1}%
      \noexpand\fi
    }%
  }\noexpand\relax
}
\__jlreq_trimmarks_afterpkg_addtodeletecs:N \jlreq@trimmarks@analyzepapersize

\keys_define:nn { jlreq-trimmarks } { trimmarks_paper .tl_set:N = \jlreq@trimmarks@option@papersize }
\__jlreq_trimmarks_afterpkg_addtodeletecs:N \jlreq@trimmarks@option@papersize

\newif\ifjlreq@trimmarks@digital \jlreq@trimmarks@digitaltrue
\newif\ifjlreq@trimmarks@show \jlreq@trimmarks@showtrue
\newif\ifjlreq@trimmarks@show@artbox \jlreq@trimmarks@show@artboxfalse
\tombowdatetrue
% flag: `show` is specified or not
\newif\ifjlreq@trimmarks@option@show \jlreq@trimmarks@option@showfalse

\keys_define:nn { jlreq-trimmarks } {
  show .code:n = {
    \jlreq@trimmarks@option@showtrue
    \jlreq@ifempty{#1}{
      \jlreq@trimmarks@showtrue\tombowdatetrue\jlreq@trimmarks@digitaltrue
    }{
      \jlreq@trimmarks@showfalse\tombowdatefalse\jlreq@trimmarks@digitalfalse
      \clist_map_variable:nNn {#1} \jlreq@trimmarks@tempa {
        \expandafter\jlreq@helper@trim\expandafter{\jlreq@trimmarks@tempa}{\jlreq@trimmarks@tempa}
        \jlreq@switch{\jlreq@trimmarks@tempa}{
          {trimmarks}{\jlreq@trimmarks@showtrue}
          {banner}{\tombowdatetrue}
          {digital}{\jlreq@trimmarks@digitaltrue}
          {digital*}{\jlreq@trimmarks@digitaltrue\jlreq@trimmarks@show@artboxtrue}
          {no}{\tombowdatefalse\jlreq@trimmarks@showfalse\jlreq@trimmarks@digitalfalse}
        }[\PackageError{jlreq-trimmarks}{Unknown~value~`##1'~in~the~option~`show'}{\@ehc}]
      }
    }
  }
}
\keys_define:nn { jlreq-trimmarks } {
  bleed_margin .code:n = {
    \begingroup
      \def\jlreq@do{}%
      \jlreq@parsekeyval@nokey{
        \ifjlreq@parsekeyval@nokey@novalue{%
          \clist_map_variable:nNn { top,bottom,gutter,fore-edge } \jlreq@tempa {
          \epreto\jlreq@do{%
              \noexpand\def\exp_not:o {\csname jlreq@trimmarks@bleed@\jlreq@tempa\endcsname}{##1}%
            }%
          }%
        }{%
          \bool_if:nTF {
            \str_if_eq_p:nn {##1} {top} || \str_if_eq_p:nn {##1} {bottom} ||
            \str_if_eq_p:nn {##1} {gutter} || \str_if_eq_p:nn {##1} {fore-edge}
          }{
            \tl_put_right:Nx \jlreq@do{%
              \noexpand\def\exp_not:o {\csname jlreq@trimmarks@bleed@##1\endcsname}{##2}%
            }%
          }{%
            \PackageError{jlreq-trimmarks}{Unknown~position~`##1'~in~bleed_margin}{\@ehc}
          }%
        }%
      }{#1}%
    \expandafter\endgroup
    \jlreq@do
  }
}

\newif\ifjlreq@trimmarks@landscape \jlreq@trimmarks@landscapefalse
\keys_define:nn { jlreq-trimmarks } { landscape .code:n = {\jlreq@trimmarks@landscapetrue}, .value_forbidden:n = true }
\__jlreq_trimmarks_afterpkg_addtodeleteif:N \ifjlreq@trimmarks@landscape

\keys_set:nn { jlreq-trimmarks } {
  trimmarks_paper = {+2in},
  bleed_margin = { top = 3mm, bottom = 3mm, gutter = 3mm, fore-edge = 3mm },
}
\ProcessKeysOptions { jlreq-trimmarks }

\ifjlreq@trimmarks@option@show\else
  \ifx o\jlreq@trimmarks@driver
    \jlreq@trimmarks@digitalfalse
    \jlreq@trimmarks@showtrue
    \jlreq@trimmarks@show@artboxfalse
  \fi
\fi

\def\jlreq@trimmarks@setpapersize#1{
  \jlreq@ifcontains{#1}{+}{
    \def\@tempa##1+##2\jlreq@endmark{
      \jlreq@helper@trim{##1}{\jlreq@trimmarks@tempa}
      \jlreq@helper@trim{##2}{\jlreq@trimmarks@tempb}
      \ifx\jlreq@trimmarks@tempa\@empty
        \let\jlreq@tempa=\paperwidth
        \let\jlreq@tempb=\paperheight
      \else
        \expandafter\jlreq@trimmarks@analyzepapersize\expandafter{\jlreq@trimmarks@tempa}
        \let\jlreq@tempa=\jlreq@resulta
        \let\jlreq@tempb=\jlreq@resultb
        \ifjlreq@trimmarks@landscape\jlreq@helper@swap{\jlreq@tempa}{\jlreq@tempb}\fi
      \fi
      \expandafter\jlreq@trimmarks@analyzepapersize\expandafter{\jlreq@trimmarks@tempb}
      \ifjlreq@trimmarks@landscape\jlreq@helper@swap{\jlreq@resulta}{\jlreq@resultb}\fi
      \edef\jlreq@trimmarks@paperwidth{\the\dimexpr\jlreq@tempa + \jlreq@resulta\relax}
      \edef\jlreq@trimmarks@paperheight{\the\dimexpr\jlreq@tempb + \jlreq@resultb\relax}
    }
    \@tempa#1\jlreq@endmark
  }{
    \jlreq@trimmarks@analyzepapersize{#1}
    \ifjlreq@trimmarks@landscape\jlreq@helper@swap{\jlreq@resulta}{\jlreq@resultb}\fi
    \edef\jlreq@trimmarks@paperwidth{\jlreq@resulta}
    \edef\jlreq@trimmarks@paperheight{\jlreq@resultb}
  }
}
\__jlreq_trimmarks_afterpkg_addtodeletecs:N \jlreq@trimmarks@setpapersize
\expandafter\jlreq@trimmarks@setpapersize\expandafter{\jlreq@trimmarks@option@papersize}

\ifx o\jlreq@trimmarks@driver
  \ifjlreq@trimmarks@digital
    \PackageError{jlreq-trimmarks}{`show=digital'~can't~be~used~with~the~driver~`dviout'}{\@ehc}
  \fi
\fi

\long\def\jlreq@trimmarks@setbanner#1#2#3{%
  \begingroup
    \def\jlreq@do{}%
    \jlreq@parsekeyval@nokey{%
      \ifjlreq@parsekeyval@nokey@novalue{}{%
        \jlreq@switch{##1}{
          {yoko}{\tl_put_right:Nn \jlreq@do{\jlreq@trimmarks@setbanner@@{yoko@#1}{yoko@#2}{##2}}}
          {horizontal}{\tl_put_right:Nn \jlreq@do{\jlreq@trimmarks@setbanner@@{yoko@#1}{yoko@#2}{##2}}}
          {tate}{\tl_put_right:Nn \jlreq@do{\jlreq@trimmarks@setbanner@@{tate@#1}{tate@#2}{##2}}}
          {vertial}{\tl_put_right:Nn \jlreq@do{\jlreq@trimmarks@setbanner@@{tate@#1}{tate@#2}{##2}}}
          {corner}{\tl_put_right:Nn \jlreq@do{\jlreq@trimmarks@setbanner@@{corner@#1}{corner@#2}{##2}}}
          {in-yoko}{\tl_put_right:Nn \jlreq@do{\jlreq@trimmarks@setbanner@@{inyoko@#1}{inyoko@#2}{##2}}}
          {in-horizontal}{\tl_put_right:Nn \jlreq@do{\jlreq@trimmarks@setbanner@@{inyoko@#1}{inyoko@#2}{##2}}}
          {in-tate}{\tl_put_right:Nn \jlreq@do{\jlreq@trimmarks@setbanner@@{intate@#1}{intate@#2}{##2}}}
          {in-vertial}{\tl_put_right:Nn \jlreq@do{\jlreq@trimmarks@setbanner@@{intate@#1}{intate@#2}{##2}}}
        }%
      }%
    }{#3}%
    \jlreq@if{\ifx\jlreq@do\@empty\fi}{%
      \tl_put_right:Nn \jlreq@do{\jlreq@trimmarks@setbanner@@{yoko@#1}{yoko@#2}{#3}}%
    }{}%
  \expandafter\endgroup
  \jlreq@do
}

\long\def\jlreq@trimmarks@setbanner@#1#2#3{%
  \begingroup
    \def\jlreq@do{}%
    \jlreq@parsekeyval@nokey{%
      \ifjlreq@parsekeyval@nokey@novalue{}{%
        \jlreq@switch*{##1}{
          {left}{\tl_put_right:Nn \jlreq@do{\jlreq@trimmarks@setbanner@@{before@#1}{before@#2}{##2}}}
          {right}{\tl_put_right:Nn \jlreq@do{\jlreq@trimmarks@setbanner@@{after@#1}{after@#2}{##2}}}
          {above}{\tl_put_right:Nn \jlreq@do{\jlreq@trimmarks@setbanner@@{before@#1}{before@#2}{##2}}}
          {below}{\tl_put_right:Nn \jlreq@do{\jlreq@trimmarks@setbanner@@{after@#1}{after@#2}{##2}}}
          {in}{\tl_put_right:Nn \jlreq@do{\jlreq@trimmarks@setbanner@@{in@#1}{in@#2}{##2}}}
        }%
      }%
    }{#3}%
    \jlreq@if{\ifx\jlreq@do\@empty\fi}{
      \tl_put_right:Nn \jlreq@do{\jlreq@trimmarks@setbanner@@{before@#1}{before@#2}{#3}}%
    }{}%
  \expandafter\endgroup
  \jlreq@do
}

% #1 = odd, #2 = even
\long\def\jlreq@trimmarks@setbanner@@#1#2#3{%
  \begingroup
    \def\jlreq@do{}%
    \jlreq@parsekeyval@nokey{%
      \ifjlreq@parsekeyval@nokey@novalue{}{%
        \jlreq@switch*{##1}{
          {odd}{\tl_put_right:Nn \jlreq@do{\expandafter\edef\csname jlreq@trimmarks@banner@odd@#1\endcsname{\unexpanded{##2}}}}
          {even}{\tl_put_right:Nn \jlreq@do{\expandafter\edef\csname jlreq@trimmarks@banner@even@#2\endcsname{\unexpanded{##2}}}}
        }%
      }%
    }{#3}%
    \jlreq@if{\ifx\jlreq@do\@empty\fi}{
      \tl_put_right:Nn \jlreq@do{%
        \expandafter\edef\csname jlreq@trimmarks@banner@odd@#1\endcsname{\unexpanded{#3}}%
        \expandafter\edef\csname jlreq@trimmarks@banner@even@#2\endcsname{\unexpanded{#3}}%
      }%
    }{}%
  \expandafter\endgroup
  \jlreq@do
}

\keys_define:nn { jlreqtrimmarkssetup } {
  banner .code:n = {
    \clist_map_variable:nNn { odd,even } \@tempa {
      \clist_map_variable:nNn { tate,yoko,corner,inyoko,intate } \jlreq@tempa {
        \clist_map_variable:nNn {top,bottom} \jlreq@tempb {
          \clist_map_variable:nNn {left,right} \jlreq@tempc {
            \@namedef{jlreq@trimmarks@banner@\@tempa @\jlreq@tempa @\jlreq@tempb @\jlreq@tempc}{}%
          }%
        }%
      }%
      \clist_map_variable:nNn {before,after} \jlreq@tempa {
        \clist_map_variable:nNn {top,bottom,in} \jlreq@tempb {
          \@namedef{jlreq@trimmarks@banner@\@tempa @\jlreq@tempa @\jlreq@tempb @center}{}%
        }%
        \clist_map_variable:nNn {left,right,in} \jlreq@tempb {
          \@namedef{jlreq@trimmarks@banner@\@tempa @\jlreq@tempa @center@\jlreq@tempb}{}%
        }%
      }%
    }%
    \def\jlreq@do{}%
    \jlreq@parsekeyval@nokey{%
      \ifjlreq@parsekeyval@nokey@novalue{}{%
        \edef\jlreq@gutterodd{\ifjlreq@trimmarks@tate{right}{left}}%
        \if@twoside
          \edef\jlreq@guttereven{\ifjlreq@trimmarks@tate{left}{right}}%
        \else
          \let\jlreq@guttereven\jlreq@gutterodd
        \fi
        \jlreq@switch*{##1}{
          {top-left}{\tl_put_right:Nn \jlreq@do{\jlreq@trimmarks@setbanner{top@left}{top@left}{##2}}}
          {left-top}{\tl_put_right:Nn \jlreq@do{\jlreq@trimmarks@setbanner{top@left}{top@left}{##2}}}
          {top-right}{\tl_put_right:Nn \jlreq@do{\jlreq@trimmarks@setbanner{top@right}{top@right}{##2}}}
          {right-top}{\tl_put_right:Nn \jlreq@do{\jlreq@trimmarks@setbanner{top@right}{top@right}{##2}}}
          {top-gutter}{\tl_put_right:Nn \jlreq@do{\jlreq@trimmarks@setbanner{top@\jlreq@gutterodd}{top@\jlreq@guttereven}{##2}}}
          {gutter-top}{\tl_put_right:Nn \jlreq@do{\jlreq@trimmarks@setbanner{top@\jlreq@gutterodd}{top@\jlreq@guttereven}{##2}}}
          {top-fore-edge}{\tl_put_right:Nn \jlreq@do{\jlreq@trimmarks@setbanner{top@\jlreq@guttereven}{top@\jlreq@gutterodd}{##2}}}
          {fore-edge-top}{\tl_put_right:Nn \jlreq@do{\jlreq@trimmarks@setbanner{top@\jlreq@guttereven}{top@\jlreq@gutterodd}{##2}}}
          {bottom-left}{\tl_put_right:Nn \jlreq@do{\jlreq@trimmarks@setbanner{bottom@left}{bottom@left}{##2}}}
          {left-bottom}{\tl_put_right:Nn \jlreq@do{\jlreq@trimmarks@setbanner{bottom@left}{bottom@left}{##2}}}
          {bottom-right}{\tl_put_right:Nn \jlreq@do{\jlreq@trimmarks@setbanner{bottom@right}{bottom@right}{##2}}}
          {right-bottom}{\tl_put_right:Nn \jlreq@do{\jlreq@trimmarks@setbanner{bottom@right}{bottom@right}{##2}}}
          {bottom-gutter}{\tl_put_right:Nn \jlreq@do{\jlreq@trimmarks@setbanner{bottom@\jlreq@gutterodd}{bottom@\jlreq@guttereven}{##2}}}
          {gutter-bottom}{\tl_put_right:Nn \jlreq@do{\jlreq@trimmarks@setbanner{bottom@\jlreq@gutterodd}{bottom@\jlreq@guttereven}{##2}}}
          {bottom-fore-edge}{\tl_put_right:Nn \jlreq@do{\jlreq@trimmarks@setbanner{bottom@\jlreq@guttereven}{bottom@\jlreq@gutterodd}{##2}}}
          {fore-edge-bottom}{\tl_put_right:Nn \jlreq@do{\jlreq@trimmarks@setbanner{bottom@\jlreq@guttereven}{bottom@\jlreq@gutterodd}{##2}}}
          {top-center}{\tl_put_right:Nn \jlreq@do{\jlreq@trimmarks@setbanner@{top@center}{top@center}{##2}}}
          {center-top}{\tl_put_right:Nn \jlreq@do{\jlreq@trimmarks@setbanner@{top@center}{top@center}{##2}}}
          {bottom-center}{\tl_put_right:Nn \jlreq@do{\jlreq@trimmarks@setbanner@{bottom@center}{bottom@center}{##2}}}
          {center-bottom}{\tl_put_right:Nn \jlreq@do{\jlreq@trimmarks@setbanner@{bottom@center}{bottom@center}{##2}}}
          {center-right}{\tl_put_right:Nn \jlreq@do{\jlreq@trimmarks@setbanner@{center@right}{center@right}{##2}}}
          {right-center}{\tl_put_right:Nn \jlreq@do{\jlreq@trimmarks@setbanner@{center@right}{center@right}{##2}}}
          {center-left}{\tl_put_right:Nn \jlreq@do{\jlreq@trimmarks@setbanner@{center@left}{center@left}{##2}}}
          {left-center}{\tl_put_right:Nn \jlreq@do{\jlreq@trimmarks@setbanner@{center@left}{center@left}{##2}}}
          {center-gutter}{\tl_put_right:Nn \jlreq@do{\jlreq@trimmarks@setbanner@{center@\jlreq@gutterodd}{center@\jlreq@guttereven}{##2}}}
          {gutter-center}{\tl_put_right:Nn \jlreq@do{\jlreq@trimmarks@setbanner@{center@\jlreq@gutterodd}{center@\jlreq@guttereven}{##2}}}
          {center-fore-edge}{\tl_put_right:Nn \jlreq@do{\jlreq@trimmarks@setbanner@{center@\jlreq@guttereven}{center@\jlreq@gutterodd}{##2}}}
          {fore-edge-center}{\tl_put_right:Nn \jlreq@do{\jlreq@trimmarks@setbanner@{center@\jlreq@guttereven}{center@\jlreq@gutterodd}{##2}}}
        }%
      }%
    }{#1}%
    \jlreq@if{\ifx\jlreq@do\@empty\fi}{
      \tl_put_right:Nn \jlreq@do{\jlreq@trimmarks@setbanner{top@left}{top@left}{#1}}%
    }{}%
    \jlreq@do
  },
  banner_font .tl_set:N = \jlreq@trimmarks@bannerfont,
  trimmarks_width .code:n = {\setlength{\@tombowwidth}{#1}},
  color .code:n = {
    \jlreq@ifempty{#1}{%
      \def\jlreq@trimmarks@color{\normalcolor}%
    }{%
      \@ifundefined{color}{%
        \PackageError{jlreq-trimmarks}{`\string\color'~is~not~defined,~please~load~the~package~`color'~or~its~variant~before~this~package}{\@ehc}%
      }%
      \jlreq@switch{#1}{
        {c}{\def\jlreq@trimmarks@color{\color[cmyk]{1,0,0,0}}}
        {m}{\def\jlreq@trimmarks@color{\color[cmyk]{0,1,0,0}}}
        {y}{\def\jlreq@trimmarks@color{\color[cmyk]{0,0,1,0}}}
        {k}{\def\jlreq@trimmarks@color{\color[cmyk]{0,0,0,1}}}
        {cm}{\def\jlreq@trimmarks@color{\color[cmyk]{1,1,0,0}}}
        {cy}{\def\jlreq@trimmarks@color{\color[cmyk]{1,0,1,0}}}
        {ck}{\def\jlreq@trimmarks@color{\color[cmyk]{1,0,0,1}}}
        {my}{\def\jlreq@trimmarks@color{\color[cmyk]{0,1,1,0}}}
        {mk}{\def\jlreq@trimmarks@color{\color[cmyk]{0,1,0,1}}}
        {yk}{\def\jlreq@trimmarks@color{\color[cmyk]{0,0,1,1}}}
        {cmy}{\def\jlreq@trimmarks@color{\color[cmyk]{1,1,1,0}}}
        {cmk}{\def\jlreq@trimmarks@color{\color[cmyk]{1,1,0,1}}}
        {cyk}{\def\jlreq@trimmarks@color{\color[cmyk]{1,0,1,1}}}
        {myk}{\def\jlreq@trimmarks@color{\color[cmyk]{0,1,1,1}}}
        {cmyk}{\def\jlreq@trimmarks@color{\color[cmyk]{1,1,1,1}}}
        {%
          \jlreq@iffirsttoken{##1}{[}{%
            \def\@tempa[####1]####2\jlreq@endmark{\def\jlreq@trimmarks@color{\color[####1]{####2}}}%
          }{%
            \def\@tempa####1\jlreq@endmark{\def\jlreq@trimmarks@color{\color{####1}}}%
          }%
          \@tempa##1\jlreq@endmark
        }%
      }%
    }%
  }%
}
\NewDocumentCommand { \jlreqtrimmarkssetup } { +m } {
  \keys_set:nn { jlreqtrimmarkssetup } {#1}
}
\@onlypreamble\jlreqtrimmarkssetup
\@bannertoken{%
  \jobname\space(\number\year-\two@digits\month-\two@digits\day
  \space\two@digits\hour :\two@digits\minute)%
}
\jlreqtrimmarkssetup{
  banner={\the\@bannertoken},
  banner_font={\@bannerfont},
  color={}
}

\ifx\jlreq@trimmarks@engine\@undefined
  \jlreq@helper@guessengine
  \let\jlreq@trimmarks@engine=\jlreq@result
\fi

\ifx\jlreq@trimmarks@driver\@undefined
  \ifx l\jlreq@trimmarks@engine
    \let\jlreq@trimmarks@driver=l
  \else
    % default: dvipdfmx
    \let\jlreq@trimmarks@driver=f
  \fi
\fi

\ifx l\jlreq@trimmarks@engine
  \setlength{\pagewidth}{\dimexpr\jlreq@trimmarks@paperwidth\relax}
  \setlength{\pageheight}{\dimexpr\jlreq@trimmarks@paperheight\relax}
\else
  \setlength{\pdfpagewidth}{\dimexpr\jlreq@trimmarks@paperwidth\relax}
  \setlength{\pdfpageheight}{\dimexpr\jlreq@trimmarks@paperheight\relax}
\fi

\hoffset=\dimexpr(\jlreq@trimmarks@paperwidth - \paperwidth)/2 - \ifx l\jlreq@trimmarks@engine 1in\else 1truein\fi\relax
\voffset=\dimexpr(\jlreq@trimmarks@paperheight - \paperheight)/2 - \ifx l\jlreq@trimmarks@engine 1in\else 1truein\fi\relax
\ifx l\jlreq@trimmarks@engine\else
  \@ifundefined{@tombowreset@@paper}{
    \AtBeginDocument{%
      \addtolength{\oddsidemargin}{\dimexpr 1truein - 1in\relax}%
      \addtolength{\evensidemargin}{\dimexpr 1truein - 1in\relax}%
      \addtolength{\topmargin}{\dimexpr 1truein - 1in\relax}%
    }
  }{
    \def\@tombowreset@@paper{%
       \@@topmargin\topmargin
       \jlreq@if{\iftombow\fi}{
         \@@paperwidth\paperwidth
         \advance\@@paperwidth 2\dimexpr\@tombowbleed\relax
         \@@paperheight\paperheight \advance\@@paperheight 10mm\relax
         \advance\@@paperheight 2\dimexpr\@tombowbleed\relax
         % 1in -> 1truein
         \advance\@@topmargin 1truein\relax \advance\@themargin 1truein\relax
      }{}%
    }
  }
\fi

\ifx l\jlreq@trimmarks@driver\else
  \jlreq@helper@divide{\the\mag pt}{1000pt}
  \edef\@tempa{\noexpand\AtBeginDvi{\noexpand\special{papersize=\the\dimexpr\strip@pt\jlreq@resultdimen\dimexpr\jlreq@trimmarks@paperwidth\relax\relax, \the\dimexpr\strip@pt\jlreq@resultdimen\dimexpr\jlreq@trimmarks@paperheight\relax\relax}}}
  \@tempa
\fi
\@ifundefined{stockheight}{\newlength{\stockheight}}{}
\@ifundefined{stockwidth}{\newlength{\stockwidth}}{}
\setlength{\stockwidth}{\dimexpr\jlreq@trimmarks@paperwidth\relax}
\setlength{\stockheight}{\dimexpr\jlreq@trimmarks@paperheight\relax}

\def\jlreq@trimmarks@outputbanner#1#2{%
  \jlreq@if{\iftombowdate\fi}{%
    \expandafter\let\expandafter\jlreq@tempa\csname jlreq@trimmarks@banner@\ifodd\c@page odd\else even\fi @#1\endcsname
    \jlreq@if{\ifx\jlreq@tempa\@empty\fi}{}{%
      \def\@tempa##1{#2}%
      \expandafter\@tempa\expandafter{\jlreq@tempa}%
    }%
  }{}%
}
\def\jlreq@trimmarks@bleed{3mm}
% left=gutter?
\def\ifjlreq@trimmarks@leftisgutter{%
  \bool_if:nTF {
    ( \legacy_if_p:n { jlreq@trimmarks@tate } && ( ! ( \int_if_odd_p:n { \c@page } || ! \legacy_if_p:n { @twoside } ) ) ) ||
    ( ! \legacy_if_p:n { jlreq@trimmarks@tate } && ( \int_if_odd_p:n { \c@page } || ! \legacy_if_p:n { @twoside } ) )
  }
}
\def\jlreq@trimmarks@bleed@left{\ifjlreq@trimmarks@leftisgutter{\jlreq@trimmarks@bleed@gutter}{\expandafter\csname jlreq@trimmarks@bleed@fore-edge\endcsname}}
\def\jlreq@trimmarks@bleed@right{\ifjlreq@trimmarks@leftisgutter{\expandafter\csname jlreq@trimmarks@bleed@fore-edge\endcsname}{\jlreq@trimmarks@bleed@gutter}}

\def\jlreq@trimmarks@outputtombow{%
  \vbox to\z@{%
    \kern-\dimexpr 10mm + \jlreq@trimmarks@bleed@top\relax
    \boxmaxdepth\maxdimen
    \moveleft\jlreq@trimmarks@bleed@left\vbox to\@@paperheight{%
      \color@begingroup\jlreq@trimmarks@color
      \hbox to\@@paperwidth{%
        \hskip\jlreq@trimmarks@bleed@left\relax
        \setbox\jlreq@tempboxa=\hbox to\z@{% \@TL
          \yoko\hss
          \vrule width\dimexpr 10mm + \jlreq@trimmarks@bleed@left\relax height\@tombowwidth depth\z@
          \vrule height10mm width\@tombowwidth depth\z@
          \jlreq@trimmarks@outputbanner{yoko@top@left}{%
            \setbox\jlreq@tempboxa=\hbox to\z@{\hskip5mm\jlreq@trimmarks@bannerfont##1\hss}%
            \dp\jlreq@tempboxa=0pt
            \raise 4pt\box\jlreq@tempboxa
          }%
          \jlreq@trimmarks@outputbanner{inyoko@top@left}{%
            \setbox\jlreq@tempboxa=\hbox to 0pt{\jlreq@trimmarks@bannerfont##1\hss}%
            \jlreq@tempdima=\dimexpr\ht\jlreq@tempboxa + \jlreq@trimmarks@bleed@top\relax
            \ht\jlreq@tempboxa=0pt \dp\jlreq@tempboxa=0pt
            \raise-\jlreq@tempdima\box\jlreq@tempboxa
          }%
        }%
        \dp\jlreq@tempboxa=0pt
        \box\jlreq@tempboxa
        \hfill
        \setbox\jlreq@tempboxa=\hbox{% \@TC
          \yoko
          \vrule width10mm height\@tombowwidth depth\z@
          \jlreq@trimmarks@outputbanner{before@top@center}{%
            \setbox\jlreq@tempboxa=\hbox to 0pt{\hss\jlreq@trimmarks@bannerfont##1\hskip 5mm}%
            \ht\jlreq@tempboxa=0pt \dp\jlreq@tempboxa=0pt \wd\jlreq@tempboxa=0pt
            \raise 4pt\box\jlreq@tempboxa
          }%
          \jlreq@trimmarks@outputbanner{in@top@center}{%
            \setbox\jlreq@tempboxa=\hbox{\jlreq@trimmarks@bannerfont##1}%
            \jlreq@tempdima=\dimexpr\ht\jlreq@tempboxa + \jlreq@trimmarks@bleed@top\relax
            \jlreq@tempdimb=0.5\wd\jlreq@tempboxa
            \ht\jlreq@tempboxa=0pt \dp\jlreq@tempboxa=0pt \wd\jlreq@tempboxa=0pt
            \kern-\jlreq@tempdimb\raise-\jlreq@tempdima\box\jlreq@tempboxa\kern\jlreq@tempdimb
          }%
          \vrule height10mm width\@tombowwidth depth\z@
          \jlreq@trimmarks@outputbanner{after@top@center}{%
            \setbox\jlreq@tempboxa=\hbox to 0pt{\hskip 5mm\jlreq@trimmarks@bannerfont##1\hss}%
            \ht\jlreq@tempboxa=0pt \dp\jlreq@tempboxa=0pt \wd\jlreq@tempboxa=0pt
            \raise 4pt\box\jlreq@tempboxa
          }%
          \vrule width10mm height\@tombowwidth depth\z@
        }%
        \dp\jlreq@tempboxa=0pt
        \box\jlreq@tempboxa
        \hfill
        \setbox\jlreq@tempboxa=\hbox to\z@{% \@TR
          \yoko
          \jlreq@trimmarks@outputbanner{yoko@top@right}{%
            \setbox\jlreq@tempboxa=\hbox to 0pt{\yoko\hss\jlreq@trimmarks@bannerfont##1\hskip 5mm}%
            \ht\jlreq@tempboxa=0pt \dp\jlreq@tempboxa=0pt
            \raise 4pt\box\jlreq@tempboxa
          }%
          \jlreq@trimmarks@outputbanner{inyoko@top@right}{%
            \setbox\jlreq@tempboxa=\hbox to 0pt{\yoko\hss\jlreq@trimmarks@bannerfont##1}%
            \jlreq@tempdima=\dimexpr\jlreq@trimmarks@bleed@top + \ht\jlreq@tempboxa\relax
            \ht\jlreq@tempboxa=0pt \dp\jlreq@tempboxa=0pt
            \raise-\jlreq@tempdima\box\jlreq@tempboxa
          }%
          \vrule height10mm width\@tombowwidth depth\z@
          \jlreq@trimmarks@outputbanner{corner@top@right}{%
            \setbox\jlreq@tempboxa=\hbox to 0pt{\hskip\dimexpr\jlreq@trimmarks@bleed@right + 4pt\relax\jlreq@trimmarks@bannerfont##1\hss}%
            \ht\jlreq@tempboxa=0pt \dp\jlreq@tempboxa=0pt
            \raise 4pt\box\jlreq@tempboxa
          }%
          \vrule width\dimexpr 10mm + \jlreq@trimmarks@bleed@right\relax height\@tombowwidth depth\z@\hss
        }%
        \dp\jlreq@tempboxa=0pt
        \box\jlreq@tempboxa
        \hskip\jlreq@trimmarks@bleed@right
      }%
      \kern-10mm
      \hbox to\@@paperwidth{%
        \hbox to\z@{% \@Tl
          \yoko\hss
          \vrule width10mm height\@tombowwidth depth\z@
          \jlreq@trimmarks@outputbanner{corner@top@left}{%
            \setbox\jlreq@tempboxa=\hbox to 0pt{\hss\jlreq@trimmarks@bannerfont##1\hskip 4pt}%
            \dp\jlreq@tempboxa=0pt \ht\jlreq@tempboxa=0pt
            \raise\dimexpr \jlreq@trimmarks@bleed@top + 4pt\relax\box\jlreq@tempboxa
          }%
          \vrule height\dimexpr 10mm + \jlreq@trimmarks@bleed@top\relax width\@tombowwidth depth\z@
          \jlreq@trimmarks@outputbanner{tate@top@left}{%
            \setbox\jlreq@tempboxa=\hbox to 0pt{\tate\adjustbaseline\jlreq@trimmarks@bannerfont##1\hss}%
            \ifx l\jlreq@trimmarks@engine
              \jlreq@tempdima=\dimexpr 4pt + \ht\jlreq@tempboxa\relax
             \else
              \jlreq@tempdima=\dimexpr 4pt + \wd\jlreq@tempboxa\relax
            \fi
            \wd\jlreq@tempboxa=0pt \ht\jlreq@tempboxa=0pt \dp\jlreq@tempboxa=0pt
            \kern-\jlreq@tempdima\raise-5mm\box\jlreq@tempboxa\kern\jlreq@tempdima
          }%
          \jlreq@trimmarks@outputbanner{intate@top@left}{%
            \setbox\jlreq@tempboxa=\hbox to 0pt{\tate\adjustbaseline\jlreq@trimmarks@bannerfont##1\hss}%
            \jlreq@tempdima=\dimexpr\jlreq@trimmarks@bleed@left \ifx l\jlreq@trimmarks@engine + \ht\jlreq@tempboxa\fi\relax
            \wd\jlreq@tempboxa=0pt \ht\jlreq@tempboxa=0pt \dp\jlreq@tempboxa=0pt
            \kern\jlreq@tempdima\box\jlreq@tempboxa\kern-\jlreq@tempdima
          }%
        }%
        \hfill
        \hbox to\z@{% \@Tr
          \yoko
          \jlreq@trimmarks@outputbanner{tate@top@right}{%
            \setbox\jlreq@tempboxa=\hbox to 0pt{\tate\adjustbaseline\jlreq@trimmarks@bannerfont##1\hss}%
            \jlreq@tempdima=\dimexpr 4pt \ifx l\jlreq@trimmarks@engine + \dp\jlreq@tempboxa\fi\relax
            \ht\jlreq@tempboxa=0pt \dp\jlreq@tempboxa=0pt \wd\jlreq@tempboxa=0pt
            \kern\jlreq@tempdima\raise -5mm\box\jlreq@tempboxa\kern-\jlreq@tempdima
          }%
          \jlreq@trimmarks@outputbanner{intate@top@right}{%
            \setbox\jlreq@tempboxa=\hbox to 0pt{\tate\adjustbaseline\jlreq@trimmarks@bannerfont##1\hss}%
            \ifx l\jlreq@trimmarks@engine
              \jlreq@tempdima=\dimexpr\jlreq@trimmarks@bleed@top + \ht\jlreq@tempboxa\relax
            \else
              \jlreq@tempdima=\dimexpr\jlreq@trimmarks@bleed@top + \wd\jlreq@tempboxa\relax
            \fi
            \ht\jlreq@tempboxa=0pt \dp\jlreq@tempboxa=0pt \wd\jlreq@tempboxa=0pt
            \kern-\jlreq@tempdima\box\jlreq@tempboxa\kern\jlreq@tempdima
          }%
          \vrule height\dimexpr 10mm + \jlreq@trimmarks@bleed@top\relax width\@tombowwidth depth\z@
          \vrule width10mm height\@tombowwidth depth\z@
          \hss
        }%
      }%
      \vfill
      \hbox to\@@paperwidth{%
        \hbox to\z@{% \@CL
          \yoko\hss
          \vrule width10mm height.5\@tombowwidth depth.5\@tombowwidth
          \jlreq@trimmarks@outputbanner{before@center@left}{%
            \setbox\jlreq@tempboxa=\hbox to 0pt{\tate\hss\adjustbaseline\jlreq@trimmarks@bannerfont##1\hskip 5mm}%
            \ifx l\jlreq@trimmarks@engine
              \jlreq@tempdima=\dimexpr 4pt + \ht\jlreq@tempboxa\relax
             \else
              \jlreq@tempdima=\dimexpr 4pt + \wd\jlreq@tempboxa\relax
            \fi
            \dp\jlreq@tempboxa=0pt \ht\jlreq@tempboxa=0pt \wd\jlreq@tempboxa=0pt
            \kern-\jlreq@tempdima\box\jlreq@tempboxa\kern\jlreq@tempdima
          }%
          \jlreq@trimmarks@outputbanner{after@center@left}{%
            \setbox\jlreq@tempboxa=\hbox to 0pt{\tate\hskip 5mm\adjustbaseline\jlreq@trimmarks@bannerfont##1\hss}%
            \ifx l\jlreq@trimmarks@engine
              \jlreq@tempdima=\dimexpr 4pt + \ht\jlreq@tempboxa\relax
             \else
              \jlreq@tempdima=\dimexpr 4pt + \wd\jlreq@tempboxa\relax
            \fi
            \dp\jlreq@tempboxa=0pt \ht\jlreq@tempboxa=0pt \wd\jlreq@tempboxa=0pt
            \kern-\jlreq@tempdima\box\jlreq@tempboxa\kern\jlreq@tempdima
          }%
          \vrule height10mm depth10mm width\@tombowwidth
          \jlreq@trimmarks@outputbanner{in@center@left}{%
            \setbox\jlreq@tempboxa=\hbox{\tate\adjustbaseline\jlreq@trimmarks@bannerfont##1}%
            \ifx l\jlreq@trimmarks@engine
              \jlreq@tempdima=\dimexpr\jlreq@trimmarks@bleed@left + \ht\jlreq@tempboxa\relax
              \jlreq@tempdimb=.5\wd\jlreq@tempboxa
             \else
              \jlreq@tempdima=\dimexpr\jlreq@trimmarks@bleed@left\relax
              \jlreq@tempdimb=.5\dimexpr\ht\jlreq@tempboxa + \dp\jlreq@tempboxa\relax
            \fi
            \dp\jlreq@tempboxa=0pt \ht\jlreq@tempboxa=0pt \wd\jlreq@tempboxa=0pt
            \kern\jlreq@tempdima\raise\jlreq@tempdimb\box\jlreq@tempboxa\kern-\jlreq@tempdima
          }%
        }%
        \hfill
        \hbox to\z@{% \@CR
          \yoko
          \jlreq@trimmarks@outputbanner{in@center@right}{%
            \setbox\jlreq@tempboxa=\hbox{\tate\adjustbaseline\jlreq@trimmarks@bannerfont##1}%
            \ifx l\jlreq@trimmarks@engine
              \jlreq@tempdima=\dimexpr\jlreq@trimmarks@bleed@right  + \ht\jlreq@tempboxa\relax
              \jlreq@tempdimb=0.5\wd\jlreq@tempboxa
            \else
              \jlreq@tempdima=\dimexpr\jlreq@trimmarks@bleed@right  + \wd\jlreq@tempboxa\relax
              \jlreq@tempdimb=0.5\dimexpr\ht\jlreq@tempboxa + \dp\jlreq@tempboxa\relax
            \fi
            \dp\jlreq@tempboxa=0pt \ht\jlreq@tempboxa=0pt \wd\jlreq@tempboxa=0pt
            \kern-\jlreq@tempdima\raise\jlreq@tempdimb\box\jlreq@tempboxa\kern\jlreq@tempdima
          }%
          \vrule height10mm depth10mm width\@tombowwidth
          \jlreq@trimmarks@outputbanner{before@center@right}{%
            \setbox\jlreq@tempboxa=\hbox to 0pt{\tate\hss\adjustbaseline\jlreq@trimmarks@bannerfont##1\hskip 5mm}%
            \jlreq@tempdima=\dimexpr 4pt \ifx l\jlreq@trimmarks@engine + \dp\jlreq@tempboxa\fi\relax
            \dp\jlreq@tempboxa=0pt \ht\jlreq@tempboxa=0pt \wd\jlreq@tempboxa=0pt
            \kern\jlreq@tempdima\box\jlreq@tempboxa\kern-\jlreq@tempdima
          }%
          \jlreq@trimmarks@outputbanner{after@center@right}{%
            \setbox\jlreq@tempboxa=\hbox to 0pt{\tate\hskip 5mm\adjustbaseline\jlreq@trimmarks@bannerfont##1\hss}%
            \jlreq@tempdima=\dimexpr 4pt \ifx l\jlreq@trimmarks@engine + \dp\jlreq@tempboxa\fi\relax
            \dp\jlreq@tempboxa=0pt \ht\jlreq@tempboxa=0pt \wd\jlreq@tempboxa=0pt
            \kern\jlreq@tempdima\box\jlreq@tempboxa\kern-\jlreq@tempdima
          }%
          \vrule height.5\@tombowwidth depth.5\@tombowwidth width10mm\hss
        }%
      }%
      \vfill
      \hbox to\@@paperwidth{%
        \hbox to\z@{% \@Bl
          \yoko\hss
          \vrule width10mm depth\@tombowwidth height\z@
          \vrule depth\dimexpr 10mm + \jlreq@trimmarks@bleed@bottom\relax width\@tombowwidth height\z@
          \jlreq@trimmarks@outputbanner{tate@bottom@left}{%
            \setbox\jlreq@tempboxa=\hbox to 0pt{\tate\adjustbaseline\hss\jlreq@trimmarks@bannerfont##1}%
            \ifx l\jlreq@trimmarks@engine
              \jlreq@tempdima=\dimexpr 4pt + \ht\jlreq@tempboxa\relax
             \else
              \jlreq@tempdima=\dimexpr 4pt + \wd\jlreq@tempboxa\relax
            \fi
            \wd\jlreq@tempboxa=0pt \ht\jlreq@tempboxa=0pt \dp\jlreq@tempboxa=0pt
            \kern-\jlreq@tempdima\raise 5mm\box\jlreq@tempboxa\kern\jlreq@tempdima
          }%
          \jlreq@trimmarks@outputbanner{intate@bottom@left}{%
            \setbox\jlreq@tempboxa=\hbox to 0pt{\tate\adjustbaseline\hss\jlreq@trimmarks@bannerfont##1}%
            \jlreq@tempdima=\dimexpr\jlreq@trimmarks@bleed@left \ifx l\jlreq@trimmarks@engine + \ht\jlreq@tempboxa\fi\relax
            \wd\jlreq@tempboxa=0pt \ht\jlreq@tempboxa=0pt \dp\jlreq@tempboxa=0pt
            \kern\jlreq@tempdima\box\jlreq@tempboxa\kern-\jlreq@tempdima
          }%
        }%
        \hfill
        \hbox to\z@{% \@Br
          \yoko
          \jlreq@trimmarks@outputbanner{tate@bottom@right}{%
            \setbox\jlreq@tempboxa=\hbox to 0pt{\tate\adjustbaseline\hss\jlreq@trimmarks@bannerfont##1}%
            \jlreq@tempdima=\dimexpr\ifx l\jlreq@trimmarks@engine\ht\jlreq@tempboxa + \fi 4pt\relax
            \ht\jlreq@tempboxa=0pt \dp\jlreq@tempboxa=0pt \wd\jlreq@tempboxa=0pt
            \kern\jlreq@tempdima\raise5mm\box\jlreq@tempboxa\kern-\jlreq@tempdima
          }%
          \jlreq@trimmarks@outputbanner{intate@bottom@right}{%
            \setbox\jlreq@tempboxa=\hbox to 0pt{\tate\adjustbaseline\hss\jlreq@trimmarks@bannerfont##1}%
            \ifx l\jlreq@trimmarks@engine
              \jlreq@tempdima=\dimexpr\jlreq@trimmarks@bleed@right + \ht\jlreq@tempboxa\relax
            \else
              \jlreq@tempdima=\dimexpr\jlreq@trimmarks@bleed@right + \wd\jlreq@tempboxa\relax
            \fi
            \ht\jlreq@tempboxa=0pt \dp\jlreq@tempboxa=0pt \wd\jlreq@tempboxa=0pt
            \kern-\jlreq@tempdima\box\jlreq@tempboxa\kern\jlreq@tempdima
          }%
          \vrule depth\dimexpr 10mm + \jlreq@trimmarks@bleed@bottom\relax width\@tombowwidth height\z@
          \jlreq@trimmarks@outputbanner{corner@bottom@right}{%
            \setbox\jlreq@tempboxa=\hbox to 0pt{\hskip 4pt\relax\jlreq@trimmarks@bannerfont##1\hss}%
            \jlreq@tempdima=\dimexpr\ht\jlreq@tempboxa  + \jlreq@trimmarks@bleed@bottom + 4pt\relax
            \ht\jlreq@tempboxa=0pt \dp\jlreq@tempboxa=0pt
            \raise-\jlreq@tempdima\box\jlreq@tempboxa
          }%
          \vrule width10mm depth\@tombowwidth height\z@\hss
        }%
      }%
      \kern-10mm
      \hbox to\@@paperwidth{%
        \hskip\jlreq@trimmarks@bleed@left\relax
        \setbox\jlreq@tempboxa=\hbox to\z@{% \@BL
          \yoko\hss
          \vrule width\dimexpr 10mm + \jlreq@trimmarks@bleed@left\relax depth\@tombowwidth height\z@
          \jlreq@trimmarks@outputbanner{corner@bottom@left}{%
            \setbox\jlreq@tempboxa=\hbox to 0pt{\hss\jlreq@trimmarks@bannerfont##1\hskip\dimexpr\jlreq@trimmarks@bleed@left + 4pt\relax}%
            \jlreq@tempdima=\dimexpr\ht\jlreq@tempboxa + 4pt\relax
            \ht\jlreq@tempboxa=0pt \dp\jlreq@tempboxa=0pt
            \raise-\jlreq@tempdima\box\jlreq@tempboxa
          }%
          \vrule depth10mm width\@tombowwidth height\z@
          \jlreq@trimmarks@outputbanner{yoko@bottom@left}{%
            \setbox\jlreq@tempboxa=\hbox to 0pt{\yoko\hskip 5mm\jlreq@trimmarks@bannerfont##1\hss}%
            \jlreq@tempdima=\dimexpr\ht\jlreq@tempboxa + 4pt\relax
            \ht\jlreq@tempboxa=0pt \dp\jlreq@tempboxa=0pt
            \raise-\jlreq@tempdima\box\jlreq@tempboxa
          }%
          \jlreq@trimmarks@outputbanner{inyoko@bottom@left}{%
            \setbox\jlreq@tempboxa=\hbox to 0pt{\yoko\jlreq@trimmarks@bannerfont##1\hss}%
            \jlreq@tempdima=\dimexpr\jlreq@trimmarks@bleed@bottom + \dp\jlreq@tempboxa\relax
            \ht\jlreq@tempboxa=0pt \dp\jlreq@tempboxa=0pt
            \raise\jlreq@tempdima\box\jlreq@tempboxa
          }%
        }%
        \ht\jlreq@tempboxa=0pt
        \box\jlreq@tempboxa
        \hfill
        \setbox\jlreq@tempboxa=\hbox{% \@BC
          \yoko
          \vrule width10mm depth\@tombowwidth height\z@
          \jlreq@trimmarks@outputbanner{before@bottom@center}{%
            \setbox\jlreq@tempboxa=\hbox to 0pt{\hss\jlreq@trimmarks@bannerfont##1\hskip 5mm}%
            \jlreq@tempdima=\dimexpr\ht\jlreq@tempboxa + 4pt\relax
            \ht\jlreq@tempboxa=0pt \dp\jlreq@tempboxa=0pt
            \raise-\jlreq@tempdima\box\jlreq@tempboxa
          }%
          \jlreq@trimmarks@outputbanner{in@bottom@center}{%
            \setbox\jlreq@tempboxa=\hbox{\jlreq@trimmarks@bannerfont##1}%
            \jlreq@tempdima=\dimexpr\dp\jlreq@tempboxa + \jlreq@trimmarks@bleed@bottom\relax
            \jlreq@tempdimb=.5\wd\jlreq@tempboxa
            \ht\jlreq@tempboxa=0pt \dp\jlreq@tempboxa=0pt \wd\jlreq@tempboxa=0pt
            \kern-\jlreq@tempdimb\raise\jlreq@tempdima\box\jlreq@tempboxa\kern\jlreq@tempdimb
          }%
          \vrule depth10mm width\@tombowwidth height\z@
          \jlreq@trimmarks@outputbanner{before@bottom@center}{%
            \setbox\jlreq@tempboxa=\hbox to 0pt{\hskip 5mm\jlreq@trimmarks@bannerfont##1\hss}%
            \jlreq@tempdima=\dimexpr\ht\jlreq@tempboxa + 4pt\relax
            \ht\jlreq@tempboxa=0pt \dp\jlreq@tempboxa=0pt
            \raise-\jlreq@tempdima\box\jlreq@tempboxa
          }%
          \vrule width10mm depth\@tombowwidth height\z@
        }%
        \ht\jlreq@tempboxa=0pt
        \box\jlreq@tempboxa
        \hfill
        \setbox\jlreq@tempboxa=\hbox to 0pt{% \@BR
          \yoko
          \jlreq@trimmarks@outputbanner{yoko@bottom@right}{%
            \setbox\jlreq@tempboxa=\hbox to 0pt{\yoko\hss\jlreq@trimmarks@bannerfont##1\hskip 5mm}%
            \jlreq@tempdima=\dimexpr\ht\jlreq@tempboxa + 4pt\relax
            \ht\jlreq@tempboxa=0pt \dp\jlreq@tempboxa=0pt
            \raise-\jlreq@tempdima\box\jlreq@tempboxa
          }%
          \jlreq@trimmarks@outputbanner{inyoko@bottom@right}{%
            \setbox\jlreq@tempboxa=\hbox to 0pt{\yoko\hss\jlreq@trimmarks@bannerfont##1}%
            \jlreq@tempdima=\dimexpr\dp\jlreq@tempboxa + \jlreq@trimmarks@bleed@bottom\relax
            \ht\jlreq@tempboxa=0pt \dp\jlreq@tempboxa=0pt
            \raise\jlreq@tempdima\box\jlreq@tempboxa
          }%
          \vrule depth10mm width\@tombowwidth height\z@
          \vrule width\dimexpr 10mm + \jlreq@trimmarks@bleed@right\relax depth\@tombowwidth height\z@\hss
        }%
        \ht\jlreq@tempboxa=0pt \dp\jlreq@tempboxa=0pt
        \box\jlreq@tempboxa
        \hskip\jlreq@trimmarks@bleed@right
      }%
    \color@endgroup}\vss
  }%
}
\def\@outputtombow{%
  % 6mm = \@tombowbleed: from plcore
  \@@paperwidth=\dimexpr\@@paperwidth - 6mm + \dimexpr\jlreq@trimmarks@bleed@left + \jlreq@trimmarks@bleed@right\relax\relax
  \@@paperheight=\dimexpr\@@paperheight - 6mm + \dimexpr\jlreq@trimmarks@bleed@top + \jlreq@trimmarks@bleed@bottom\relax\relax
  \ifjlreq@trimmarks@show\expandafter\jlreq@trimmarks@outputtombow\fi
}

\ifjlreq@trimmarks@digital
  \ifx l\jlreq@trimmarks@engine
    \setlength\jlreq@resultdimen{1pt}
  \else
    \jlreq@helper@divide{\the\mag pt}{1000pt}
  \fi
  % 0.9963 = 1pt/1bp (almost)
  \edef\jlreq@trimmarks@pttobp#1{\noexpand\strip@pt\noexpand\dimexpr\strip@pt\jlreq@resultdimen\noexpand\dimexpr0.9963\noexpand\dimexpr#1\unexpanded{\relax\relax\relax}}
  \edef\jlreq@trimmarks@trimboxsize{%
    [%
      \jlreq@trimmarks@pttobp{(\jlreq@trimmarks@paperwidth - \paperwidth)/2}~
      \jlreq@trimmarks@pttobp{(\jlreq@trimmarks@paperheight - \paperheight)/2}~
      \jlreq@trimmarks@pttobp{(\jlreq@trimmarks@paperwidth + \paperwidth)/2}~
      \jlreq@trimmarks@pttobp{(\jlreq@trimmarks@paperheight + \paperheight)/2}%
    ]
  }
  \jlreq@tempcnta=\c@page
  \def\@tempa{%
    [%
      \jlreq@trimmarks@pttobp{(\jlreq@trimmarks@paperwidth - \paperwidth)/2 - \jlreq@trimmarks@bleed@left}~
      \jlreq@trimmarks@pttobp{(\jlreq@trimmarks@paperheight - \paperheight)/2 - \jlreq@trimmarks@bleed@bottom}~
      \jlreq@trimmarks@pttobp{(\jlreq@trimmarks@paperwidth + \paperwidth)/2 + \jlreq@trimmarks@bleed@right}~
      \jlreq@trimmarks@pttobp{(\jlreq@trimmarks@paperheight + \paperheight)/2 + \jlreq@trimmarks@bleed@top}%
    ]
  }
  \c@page=1
  \edef\jlreq@trimmarks@bleedboxsize@odd{\@tempa}
  \c@page=2
  \edef\jlreq@trimmarks@bleedboxsize@even{\@tempa}%
  \c@page=\jlreq@tempcnta
  \edef\jlreq@trimmarks@pdfattribute@odd{%
    /TrimBox~\jlreq@trimmarks@trimboxsize
    \ifjlreq@trimmarks@show@artbox /ArtBox~\jlreq@trimmarks@trimboxsize\fi
    /BleedBox~\jlreq@trimmarks@bleedboxsize@odd
  }
  \edef\jlreq@trimmarks@pdfattribute@even{%
    /TrimBox~\jlreq@trimmarks@trimboxsize
    \ifjlreq@trimmarks@show@artbox /ArtBox~\jlreq@trimmarks@trimboxsize\fi
    /BleedBox~\jlreq@trimmarks@bleedboxsize@even
  }
  \__jlreq_trimmarks_afterpkg_addtodeletecs:N \jlreq@trimmarks@pttobp
  \__jlreq_trimmarks_afterpkg_addtodeletecs:N \jlreq@trimmarks@trimboxsize
  \__jlreq_trimmarks_afterpkg_addtodeletecs:N \jlreq@trimmarks@bleedboxsize@odd
  \__jlreq_trimmarks_afterpkg_addtodeletecs:N \jlreq@trimmarks@bleedboxsize@even
  \__jlreq_trimmarks_afterpkg_addtodeletecs:N \jlreq@trimmarks@pdfattribute@odd
  \__jlreq_trimmarks_afterpkg_addtodeletecs:N \jlreq@trimmarks@pdfattribute@even

  \begingroup
    \c@page=1\relax
    \jlreq@tempdima=\jlreq@trimmarks@bleed@left
    \c@page=2\relax
    \ifdim\jlreq@trimmarks@bleed@left=\jlreq@tempdima
      \global\let\jlreq@tempa\@firstoftwo
    \else
      \global\let\jlreq@tempa\@secondoftwo
    \fi
  \endgroup
  \jlreq@tempa{
    % no difference between odd pages and even pages
    \ifx l\jlreq@trimmarks@driver
      \edef\@tempa{\noexpand\pdfvariable pageattr{\jlreq@trimmarks@pdfattribute@odd}}
      \@tempa
    \fi
    \ifx f\jlreq@trimmarks@driver
      \tl_put_left:Nx \@outputtombow {\noexpand\special{pdf:~put~@thispage~<<\jlreq@trimmarks@pdfattribute@odd>>}}
    \fi
    \ifx s\jlreq@trimmarks@driver
      \edef\@tempa{\noexpand\special{ps:SDict~begin~
        [~/TrimBox~\jlreq@trimmarks@trimboxsize /PAGE~pdfmark~
        \ifjlreq@trimmarks@show@artbox [~/ArtBox~\jlreq@trimmarks@trimboxsize /PAGE~pdfmark~\fi
        [~/BleedBox~\jlreq@trimmarks@bleedboxsize@odd /PAGE~pdfmark~
      end}}%
      \@tempa
    \fi
  }{
    \ifx l\jlreq@trimmarks@driver
      % in \@outputtombow, it's too late
      \tl_put_left:Nx \@outputpage {%
        \unexpanded{\ifodd\c@page\pdfvariable} pageattr{\jlreq@trimmarks@pdfattribute@odd}%
        \unexpanded{\else\pdfvariable} pageattr{\jlreq@trimmarks@pdfattribute@even}\noexpand\fi
      }
    \fi
    \ifx f\jlreq@trimmarks@driver
      \tl_put_left:Nx \@outputtombow {%
        \unexpanded{\ifodd\c@page\special}{pdf:~put~@thispage~<<\jlreq@trimmarks@pdfattribute@odd>>}%
        \unexpanded{\else\special}{pdf:~put~@thispage~<<\jlreq@trimmarks@pdfattribute@even>>}\noexpand\fi
      }
    \fi
    \ifx s\jlreq@trimmarks@driver
      \tl_put_left:Nx \@outputtombow {%
        \unexpanded{\ifodd\c@page\special}{ps:SDict~begin~
          [~/TrimBox~\jlreq@trimmarks@trimboxsize /PAGE~pdfmark~
          \ifjlreq@trimmarks@show@artbox [~/ArtBox~\jlreq@trimmarks@trimboxsize /PAGE~pdfmark~\fi
          [~/BleedBox~\jlreq@trimmarks@bleedboxsize@odd /PAGE~pdfmark~
        end}\unexpanded{\else\special}{ps:SDict~begin~
          [~/TrimBox~\jlreq@trimmarks@trimboxsize /PAGE~pdfmark~
          \ifjlreq@trimmarks@show@artbox [~/ArtBox~\jlreq@trimmarks@trimboxsize /PAGE~pdfmark~\fi
          [~/BleedBox~\jlreq@trimmarks@bleedboxsize@even /PAGE~pdfmark~
        end}\noexpand\fi
      }
    \fi
  }
\fi

% always true
\tombowtrue

\ExplSyntaxOff
\endinput
