\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{jlreq-trimmarks}[2020/05/01 jlreq-trimmarks]
\RequirePackage{xkeyval,etoolbox}
\RequirePackage{jlreq-helpers}

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

\newcommand*{\jlreq@trimmarks@undeferr}[1]{\PackageError{jlreq-trimmarks}{Trying to delete \string#1 even though it is not defined, may be a bug}{\@ehc}}
\newcommand*{\jlreq@trimmarks@afterpkg@addtodeletecs}[1]{%
  \appto\jlreq@trimmarks@afterpkg@deletecslist{\jlreq@helper@undefcs{#1}{\jlreq@trimmarks@undeferr}}%
}
\newcommand*{\jlreq@trimmarks@afterpkg@addtodeleteif}[1]{%
  \appto\jlreq@trimmarks@afterpkg@deletecslist{\jlreq@helper@undefif{#1}{\jlreq@trimmarks@undeferr}}%
}
\jlreq@trimmarks@afterpkg@addtodeletecs{\jlreq@trimmarks@afterpkg@addtodeletecs}
\jlreq@trimmarks@afterpkg@addtodeletecs{\jlreq@trimmarks@afterpkg@addtodeleteif}
\AtEndOfPackage{%
  \jlreq@trimmarks@afterpkg@deletecslist
  \jlreq@helper@undefcs{\jlreq@trimmarks@afterpkg@deletecslist}{\jlreq@trimmarks@undeferr}%
  \undef{\jlreq@trimmarks@undeferr}%
}

\newcommand*{\jlreq@trimmarks@DeclareOption}[2]{%
  \DeclareOptionX{#1}{%
    \jlreq@ifempty{##1}{}{\PackageError{jlreq-trimmarks}{The option #1 should have no value}{\@ehc}}%
    #2%
  }%
}
\jlreq@trimmarks@afterpkg@addtodeletecs{\jlreq@trimmarks@DeclareOption}

\@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
\jlreq@trimmarks@DeclareOption{dvipdfmx}{\let\jlreq@trimmarks@driver=f}
\jlreq@trimmarks@DeclareOption{dvips}{\let\jlreq@trimmarks@driver=s}
\jlreq@trimmarks@DeclareOption{dviout}{\let\jlreq@trimmarks@driver=o}
\let\jlreq@trimmarks@engine=\jlreq@engine
\jlreq@trimmarks@DeclareOption{lualatex}{\let\jlreq@trimmarks@engine=l}
\jlreq@trimmarks@DeclareOption{uplatex}{\let\jlreq@trimmarks@engine=u}
\jlreq@trimmarks@DeclareOption{platex}{\let\jlreq@trimmarks@engine=p}

\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}}\csexpandonce{jlreq@helper@papersizelist@#2}}%
  \@tempa
}
\newcommand*{\jlreq@trimmarks@addpapersize@@}[3]{%
  \@for\@tempa:=#1\do{%
    \eappto\jlreq@trimmarks@switchpapersize{{\expandonce{\@tempa}}{\unexpanded{\def\jlreq@resulta{#2}\def\jlreq@resultb{#3}}}}%
  }%
}
\jlreq@trimmarks@afterpkg@addtodeletecs{\jlreq@trimmarks@switchpapersize}
\jlreq@trimmarks@afterpkg@addtodeletecs{\jlreq@trimmarks@addpapersize}
\jlreq@trimmarks@afterpkg@addtodeletecs{\jlreq@trimmarks@addpapersize@}
\jlreq@trimmarks@afterpkg@addtodeletecs{\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}{
    \expandonce{\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{\jlreq@trimmarks@analyzepapersize}

\def\jlreq@trimmarks@option@papersize{+2in}
\DeclareOptionX{trimmarks_paper}{\def\jlreq@trimmarks@option@papersize{#1}}
\jlreq@trimmarks@afterpkg@addtodeletecs{\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

\DeclareOptionX{show}{%
  \jlreq@trimmarks@option@showtrue
  \jlreq@ifempty{#1}{
    \jlreq@trimmarks@showtrue\tombowdatetrue\jlreq@trimmarks@digitaltrue
  }{
    \jlreq@trimmarks@showfalse\tombowdatefalse\jlreq@trimmarks@digitalfalse
    \@for\jlreq@trimmarks@tempa:=#1\do{%
      \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}]
    }
  }
}
\@for\jlreq@tempa:=top,bottom,gutter,fore-edge\do{%
  \expandafter\def\csname jlreq@trimmarks@bleed@\jlreq@tempa\endcsname{3mm}
}
\DeclareOptionX{bleed_margin}{%
  \begingroup
    \def\jlreq@do{}%
    \jlreq@parsekeyval@nokey{
      \ifjlreq@parsekeyval@nokey@novalue{%
        \@for\jlreq@tempa:=top,bottom,gutter,fore-edge\do{%
        \epreto\jlreq@do{%
            \noexpand\def\expandonce{\csname jlreq@trimmarks@bleed@\jlreq@tempa\endcsname}{##1}%
          }%
        }%
      }{%
        \ifthenelse{\equal{##1}{top} \OR \equal{##1}{bottom} \OR \equal{##1}{gutter} \OR \equal{##1}{fore-edge}}{%
          \eappto\jlreq@do{%
            \noexpand\def\expandonce{\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
\jlreq@trimmarks@DeclareOption{landscape}{\jlreq@trimmarks@landscapetrue}
\jlreq@trimmarks@afterpkg@addtodeleteif{\ifjlreq@trimmarks@landscape}

\let\jlreq@temporary@original@@removeelement=\@removeelement
\let\@removeelement=\jlreq@helper@removeelement
\ProcessOptionsX*\relax
\let\@removeelement=\jlreq@temporary@original@@removeelement
\let\jlreq@temporary@original@@removeelement=\@undefined

\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{\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}{\appto\jlreq@do{\jlreq@trimmarks@setbanner@@{yoko@#1}{yoko@#2}{##2}}}
          {horizontal}{\appto\jlreq@do{\jlreq@trimmarks@setbanner@@{yoko@#1}{yoko@#2}{##2}}}
          {tate}{\appto\jlreq@do{\jlreq@trimmarks@setbanner@@{tate@#1}{tate@#2}{##2}}}
          {vertial}{\appto\jlreq@do{\jlreq@trimmarks@setbanner@@{tate@#1}{tate@#2}{##2}}}
          {corner}{\appto\jlreq@do{\jlreq@trimmarks@setbanner@@{corner@#1}{corner@#2}{##2}}}
          {in-yoko}{\appto\jlreq@do{\jlreq@trimmarks@setbanner@@{inyoko@#1}{inyoko@#2}{##2}}}
          {in-horizontal}{\appto\jlreq@do{\jlreq@trimmarks@setbanner@@{inyoko@#1}{inyoko@#2}{##2}}}
          {in-tate}{\appto\jlreq@do{\jlreq@trimmarks@setbanner@@{intate@#1}{intate@#2}{##2}}}
          {in-vertial}{\appto\jlreq@do{\jlreq@trimmarks@setbanner@@{intate@#1}{intate@#2}{##2}}}
        }%
      }%
    }{#3}%
    \jlreq@if{\ifx\jlreq@do\@empty\fi}{%
      \appto\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}{\appto\jlreq@do{\jlreq@trimmarks@setbanner@@{before@#1}{before@#2}{##2}}}
          {right}{\appto\jlreq@do{\jlreq@trimmarks@setbanner@@{after@#1}{after@#2}{##2}}}
          {above}{\appto\jlreq@do{\jlreq@trimmarks@setbanner@@{before@#1}{before@#2}{##2}}}
          {below}{\appto\jlreq@do{\jlreq@trimmarks@setbanner@@{after@#1}{after@#2}{##2}}}
          {in}{\appto\jlreq@do{\jlreq@trimmarks@setbanner@@{in@#1}{in@#2}{##2}}}
        }%
      }%
    }{#3}%
    \jlreq@if{\ifx\jlreq@do\@empty\fi}{
      \appto\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}{\appto\jlreq@do{\expandafter\edef\csname jlreq@trimmarks@banner@odd@#1\endcsname{\unexpanded{##2}}}}
          {even}{\appto\jlreq@do{\expandafter\edef\csname jlreq@trimmarks@banner@even@#2\endcsname{\unexpanded{##2}}}}
        }%
      }%
    }{#3}%
    \jlreq@if{\ifx\jlreq@do\@empty\fi}{
      \appto\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
}

\newcommand{\jlreqtrimmarkssetup}[1]{%
  \jlreq@parsekeyval[jlreqtrimmarkssetup]{
    {banner}{%
      \@for\@tempa:=odd,even\do{%
        \@for\jlreq@tempa:=tate,yoko,corner,inyoko,intate\do{%
          \@for\jlreq@tempb:=top,bottom\do{%
            \@for\jlreq@tempc:=left,right\do{%
              \@namedef{jlreq@trimmarks@banner@\@tempa @\jlreq@tempa @\jlreq@tempb @\jlreq@tempc}{}%
            }%
          }%
        }%
        \@for\jlreq@tempa:=before,after\do{%
          \@for\jlreq@tempb:=top,bottom,in\do{%
            \@namedef{jlreq@trimmarks@banner@\@tempa @\jlreq@tempa @\jlreq@tempb @center}{}%
          }%
          \@for\jlreq@tempb:=left,right,in\do{%
            \@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}{\appto\jlreq@do{\jlreq@trimmarks@setbanner{top@left}{top@left}{####2}}}
            {left-top}{\appto\jlreq@do{\jlreq@trimmarks@setbanner{top@left}{top@left}{####2}}}
            {top-right}{\appto\jlreq@do{\jlreq@trimmarks@setbanner{top@right}{top@right}{####2}}}
            {right-top}{\appto\jlreq@do{\jlreq@trimmarks@setbanner{top@right}{top@right}{####2}}}
            {top-gutter}{\appto\jlreq@do{\jlreq@trimmarks@setbanner{top@\jlreq@gutterodd}{top@\jlreq@guttereven}{####2}}}
            {gutter-top}{\appto\jlreq@do{\jlreq@trimmarks@setbanner{top@\jlreq@gutterodd}{top@\jlreq@guttereven}{####2}}}
            {top-fore-edge}{\appto\jlreq@do{\jlreq@trimmarks@setbanner{top@\jlreq@guttereven}{top@\jlreq@gutterodd}{####2}}}
            {fore-edge-top}{\appto\jlreq@do{\jlreq@trimmarks@setbanner{top@\jlreq@guttereven}{top@\jlreq@gutterodd}{####2}}}
            {bottom-left}{\appto\jlreq@do{\jlreq@trimmarks@setbanner{bottom@left}{bottom@left}{####2}}}
            {left-bottom}{\appto\jlreq@do{\jlreq@trimmarks@setbanner{bottom@left}{bottom@left}{####2}}}
            {bottom-right}{\appto\jlreq@do{\jlreq@trimmarks@setbanner{bottom@right}{bottom@right}{####2}}}
            {right-bottom}{\appto\jlreq@do{\jlreq@trimmarks@setbanner{bottom@right}{bottom@right}{####2}}}
            {bottom-gutter}{\appto\jlreq@do{\jlreq@trimmarks@setbanner{bottom@\jlreq@gutterodd}{bottom@\jlreq@guttereven}{####2}}}
            {gutter-bottom}{\appto\jlreq@do{\jlreq@trimmarks@setbanner{bottom@\jlreq@gutterodd}{bottom@\jlreq@guttereven}{####2}}}
            {bottom-fore-edge}{\appto\jlreq@do{\jlreq@trimmarks@setbanner{bottom@\jlreq@guttereven}{bottom@\jlreq@gutterodd}{####2}}}
            {fore-edge-bottom}{\appto\jlreq@do{\jlreq@trimmarks@setbanner{bottom@\jlreq@guttereven}{bottom@\jlreq@gutterodd}{####2}}}
            {top-center}{\appto\jlreq@do{\jlreq@trimmarks@setbanner@{top@center}{top@center}{####2}}}
            {center-top}{\appto\jlreq@do{\jlreq@trimmarks@setbanner@{top@center}{top@center}{####2}}}
            {bottom-center}{\appto\jlreq@do{\jlreq@trimmarks@setbanner@{bottom@center}{bottom@center}{####2}}}
            {center-bottom}{\appto\jlreq@do{\jlreq@trimmarks@setbanner@{bottom@center}{bottom@center}{####2}}}
            {center-right}{\appto\jlreq@do{\jlreq@trimmarks@setbanner@{center@right}{center@right}{####2}}}
            {right-center}{\appto\jlreq@do{\jlreq@trimmarks@setbanner@{center@right}{center@right}{####2}}}
            {center-left}{\appto\jlreq@do{\jlreq@trimmarks@setbanner@{center@left}{center@left}{####2}}}
            {left-center}{\appto\jlreq@do{\jlreq@trimmarks@setbanner@{center@left}{center@left}{####2}}}
            {center-gutter}{\appto\jlreq@do{\jlreq@trimmarks@setbanner@{center@\jlreq@gutterodd}{center@\jlreq@guttereven}{####2}}}
            {gutter-center}{\appto\jlreq@do{\jlreq@trimmarks@setbanner@{center@\jlreq@gutterodd}{center@\jlreq@guttereven}{####2}}}
            {center-fore-edge}{\appto\jlreq@do{\jlreq@trimmarks@setbanner@{center@\jlreq@guttereven}{center@\jlreq@gutterodd}{####2}}}
            {fore-edge-center}{\appto\jlreq@do{\jlreq@trimmarks@setbanner@{center@\jlreq@guttereven}{center@\jlreq@gutterodd}{####2}}}
          }%
        }%
      }{##1}%
      \jlreq@if{\ifx\jlreq@do\@empty\fi}{
        \appto\jlreq@do{\jlreq@trimmarks@setbanner{top@left}{top@left}{##1}}%
      }{}%
      \jlreq@do
    }
    {banner_font}{\def\jlreq@trimmarks@bannerfont{##1}}
    {trimmarks_width}{\setlength{\@tombowwidth}{##1}}
    {color}{%
      \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
          }%
        }%
      }%
    }%
  }{#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{%
  \ifjlreq@trimmarks@tate{%
    \jlreq@if{\ifnum 0\ifodd\c@page 1\fi\if@twoside\else 1\fi>0 \fi}{\@secondoftwo}{\@firstoftwo}%
  }{%
    \jlreq@if{\ifnum 0\ifodd\c@page 1\fi\if@twoside\else 1\fi>0 \fi}{\@firstoftwo}{\@secondoftwo}%
  }%
}
\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{\jlreq@trimmarks@pttobp}
  \jlreq@trimmarks@afterpkg@addtodeletecs{\jlreq@trimmarks@trimboxsize}
  \jlreq@trimmarks@afterpkg@addtodeletecs{\jlreq@trimmarks@bleedboxsize@odd}
  \jlreq@trimmarks@afterpkg@addtodeletecs{\jlreq@trimmarks@bleedboxsize@even}
  \jlreq@trimmarks@afterpkg@addtodeletecs{\jlreq@trimmarks@pdfattribute@odd}
  \jlreq@trimmarks@afterpkg@addtodeletecs{\jlreq@trimmarks@pdfattribute@even}

  \begingroup
    \c@page=1
    \jlreq@tempdima=\jlreq@trimmarks@bleed@left
    \c@page=2
    \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
      \epreto\@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
      \epreto\@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
      \epreto\@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
      \epreto\@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


\endinput
