From c8f2a113dcdfc0ceb813d1226e800df49a2baf5d Mon Sep 17 00:00:00 2001
From: Karl Berry <karl@freefriends.org>
Date: Mon, 1 Apr 2019 21:08:48 +0000
Subject: jlreq (1apr19)

git-svn-id: svn://tug.org/texlive/trunk@50697 c570f23f-e606-0410-a88d-b1316a301751
---
 .../texmf-dist/tex/latex/jlreq/jlreq-trimmarks.sty | 329 ++++++++++++++-------
 1 file changed, 224 insertions(+), 105 deletions(-)

(limited to 'Master/texmf-dist/tex/latex/jlreq/jlreq-trimmarks.sty')

diff --git a/Master/texmf-dist/tex/latex/jlreq/jlreq-trimmarks.sty b/Master/texmf-dist/tex/latex/jlreq/jlreq-trimmarks.sty
index 19ced9a2072..6ba910a240b 100644
--- a/Master/texmf-dist/tex/latex/jlreq/jlreq-trimmarks.sty
+++ b/Master/texmf-dist/tex/latex/jlreq/jlreq-trimmarks.sty
@@ -1,5 +1,5 @@
 \NeedsTeXFormat{LaTeX2e}
-\ProvidesPackage{jlreq-trimmarks}[2018/12/10 jlreq-trimmarks]
+\ProvidesPackage{jlreq-trimmarks}[2019/04/01 jlreq-trimmarks]
 \RequirePackage{xkeyval,etoolbox}
 \RequirePackage{jlreq-helpers}
 
@@ -33,6 +33,19 @@
 
 \@ifclassloaded{jlreq}{\let\ifjlreq@trimmarks@jlreqloaded=\@firstoftwo}{\let\ifjlreq@trimmarks@jlreqloaded=\@secondoftwo}
 
+\def\ifjlreq@trimmarks@tate@{%
+  \if@tate\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi
+}
+% \@firstoftwo when \if@tate is defined and \if@tate=\iftrue
+\def\ifjlreq@trimmarks@tate{%
+  \ifnum0\ifx\if@tate\@undefined 1\fi\ifx\if@tate\relax 1\fi>0
+    \expandafter\@secondoftwo
+  \else
+    \expandafter\ifjlreq@trimmarks@tate@
+  \fi
+}
+
+
 % 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}
@@ -144,9 +157,32 @@
     }
   }
 }
-\def\jlreq@trimmarks@bleed{3mm}
-\DeclareOptionX{bleed_margin}{\def\jlreq@trimmarks@bleed{#1}}
-
+\@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}
@@ -202,67 +238,68 @@
   \fi
 \fi
 
-\long\def\jlreq@trimmarks@setbanner#1#2{%
+\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}{##2}}}
-          {horizontal}{\appto\jlreq@do{\jlreq@trimmarks@setbanner@@{yoko@#1}{##2}}}
-          {tate}{\appto\jlreq@do{\jlreq@trimmarks@setbanner@@{tate@#1}{##2}}}
-          {vertial}{\appto\jlreq@do{\jlreq@trimmarks@setbanner@@{tate@#1}{##2}}}
-          {corner}{\appto\jlreq@do{\jlreq@trimmarks@setbanner@@{corner@#1}{##2}}}
-          {in-yoko}{\appto\jlreq@do{\jlreq@trimmarks@setbanner@@{inyoko@#1}{##2}}}
-          {in-horizontal}{\appto\jlreq@do{\jlreq@trimmarks@setbanner@@{inyoko@#1}{##2}}}
-          {in-tate}{\appto\jlreq@do{\jlreq@trimmarks@setbanner@@{intate@#1}{##2}}}
-          {in-vertial}{\appto\jlreq@do{\jlreq@trimmarks@setbanner@@{intate@#1}{##2}}}
+          {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}}}
         }%
       }%
-    }{#2}%
+    }{#3}%
     \ifx\jlreq@do\@empty
-      \appto\jlreq@do{\jlreq@trimmarks@setbanner@@{yoko@#1}{#2}}%
+      \appto\jlreq@do{\jlreq@trimmarks@setbanner@@{yoko@#1}{yoko@#2}{#3}}%
     \fi
   \expandafter\endgroup
   \jlreq@do
 }
 
-\long\def\jlreq@trimmarks@setbanner@#1#2{%
+\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}{##2}}}
-          {right}{\appto\jlreq@do{\jlreq@trimmarks@setbanner@@{after@#1}{##2}}}
-          {above}{\appto\jlreq@do{\jlreq@trimmarks@setbanner@@{before@#1}{##2}}}
-          {below}{\appto\jlreq@do{\jlreq@trimmarks@setbanner@@{after@#1}{##2}}}
-          {in}{\appto\jlreq@do{\jlreq@trimmarks@setbanner@@{in@#1}{##2}}}
+          {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}}}
         }%
       }%
-    }{#2}%
+    }{#3}%
     \ifx\jlreq@do\@empty
-      \appto\jlreq@do{\jlreq@trimmarks@setbanner@@{before@#1}{#2}}%
+      \appto\jlreq@do{\jlreq@trimmarks@setbanner@@{before@#1}{before@#2}{#3}}%
     \fi
   \expandafter\endgroup
   \jlreq@do
 }
 
-\long\def\jlreq@trimmarks@setbanner@@#1#2{%
+% #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@#1\endcsname{\unexpanded{##2}}}}
+          {even}{\appto\jlreq@do{\expandafter\edef\csname jlreq@trimmarks@banner@even@#2\endcsname{\unexpanded{##2}}}}
         }%
       }%
-    }{#2}%
+    }{#3}%
     \ifx\jlreq@do\@empty
       \appto\jlreq@do{%
-        \expandafter\edef\csname jlreq@trimmarks@banner@odd@#1\endcsname{\unexpanded{#2}}%
-        \expandafter\edef\csname jlreq@trimmarks@banner@even@#1\endcsname{\unexpanded{#2}}%
+        \expandafter\edef\csname jlreq@trimmarks@banner@odd@#1\endcsname{\unexpanded{#3}}%
+        \expandafter\edef\csname jlreq@trimmarks@banner@even@#2\endcsname{\unexpanded{#3}}%
       }%
     \fi
   \expandafter\endgroup
@@ -294,23 +331,41 @@
       \jlreq@parsekeyval@nokey{%
         \ifjlreq@parsekeyval@nokey@novalue{}{%
           \jlreq@tempafalse
+          \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}{\jlreq@tempatrue\appto\jlreq@do{\jlreq@trimmarks@setbanner{top@left}{####2}}}
-            {left-top}{\jlreq@tempatrue\appto\jlreq@do{\jlreq@trimmarks@setbanner{top@left}{####2}}}
-            {top-right}{\appto\jlreq@do{\jlreq@trimmarks@setbanner{top@right}{####2}}}
-            {right-top}{\appto\jlreq@do{\jlreq@trimmarks@setbanner{top@right}{####2}}}
-            {bottom-left}{\appto\jlreq@do{\jlreq@trimmarks@setbanner{bottom@left}{####2}}}
-            {left-bottom}{\appto\jlreq@do{\jlreq@trimmarks@setbanner{bottom@left}{####2}}}
-            {bottom-right}{\appto\jlreq@do{\jlreq@trimmarks@setbanner{bottom@right}{####2}}}
-            {right-bottom}{\appto\jlreq@do{\jlreq@trimmarks@setbanner{bottom@right}{####2}}}
-            {top-center}{\appto\jlreq@do{\jlreq@trimmarks@setbanner@{top@center}{####2}}}
-            {center-top}{\appto\jlreq@do{\jlreq@trimmarks@setbanner@{top@center}{####2}}}
-            {bottom-center}{\appto\jlreq@do{\jlreq@trimmarks@setbanner@{bottom@center}{####2}}}
-            {center-bottom}{\appto\jlreq@do{\jlreq@trimmarks@setbanner@{bottom@center}{####2}}}
-            {center-right}{\appto\jlreq@do{\jlreq@trimmarks@setbanner@{center@right}{####2}}}
-            {right-center}{\appto\jlreq@do{\jlreq@trimmarks@setbanner@{center@right}{####2}}}
-            {center-left}{\appto\jlreq@do{\jlreq@trimmarks@setbanner@{center@left}{####2}}}
-            {left-center}{\appto\jlreq@do{\jlreq@trimmarks@setbanner@{center@left}{####2}}}
+            {top-left}{\jlreq@tempatrue\appto\jlreq@do{\jlreq@trimmarks@setbanner{top@left}{top@left}{####2}}}
+            {left-top}{\jlreq@tempatrue\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}}}
           }%
           \ifjlreq@tempa
             \appto\jlreq@do{\expandafter\@bannertoken\expandafter{\jlreq@trimmarks@banner@odd@yoko@top@left}}%
@@ -437,18 +492,29 @@
     \fi
   \fi
 }
+\def\jlreq@trimmarks@bleed{3mm}
+% left=gutter?
+\def\ifjlreq@trimmarks@leftisgutter{%
+  \ifjlreq@trimmarks@tate{%
+    \ifnum 0\ifodd\c@page 1\fi\if@twoside\else 1\fi>0 \expandafter\@secondoftwo\else\expandafter\@firstoftwo\fi
+  }{%
+    \ifnum 0\ifodd\c@page 1\fi\if@twoside\else 1\fi>0 \expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi
+  }%
+}
+\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\relax
+    \kern-\dimexpr 10mm + \jlreq@trimmarks@bleed@top\relax
     \boxmaxdepth\maxdimen
-    \moveleft\jlreq@trimmarks@bleed\vbox to\@@paperheight{%
+    \moveleft\jlreq@trimmarks@bleed@left\vbox to\@@paperheight{%
       \color@begingroup\jlreq@trimmarks@color
       \hbox to\@@paperwidth{%
-        \hskip\jlreq@trimmarks@bleed\relax
+        \hskip\jlreq@trimmarks@bleed@left\relax
         \setbox\jlreq@tempboxa=\hbox to\z@{% \@TL
           \yoko\hss
-          \vrule width\dimexpr 10mm + \jlreq@trimmarks@bleed\relax height\@tombowwidth depth\z@
+          \vrule width\dimexpr 10mm + \jlreq@trimmarks@bleed@left\relax height\@tombowwidth depth\z@
           \vrule height10mm width\@tombowwidth depth\z@
           \iftombowdate
             \setbox\jlreq@tempboxa=\hbox to\z@{\hskip5mm\@bannerfont\jlreq@trimmarks@bannerfont
@@ -459,7 +525,7 @@
           \fi
           \jlreq@trimmarks@outputbanner{inyoko@top@left}{%
             \setbox\jlreq@tempboxa=\hbox to 0pt{\@bannerfont\jlreq@trimmarks@bannerfont##1\hss}%
-            \jlreq@tempdima=\dimexpr\ht\jlreq@tempboxa + \jlreq@trimmarks@bleed\relax
+            \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
           }%
@@ -477,7 +543,7 @@
           }%
           \jlreq@trimmarks@outputbanner{in@top@center}{%
             \setbox\jlreq@tempboxa=\hbox{\@bannerfont\jlreq@trimmarks@bannerfont##1}%
-            \jlreq@tempdima=\dimexpr\ht\jlreq@tempboxa + \jlreq@trimmarks@bleed\relax
+            \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
@@ -502,21 +568,21 @@
           }%
           \jlreq@trimmarks@outputbanner{inyoko@top@right}{%
             \setbox\jlreq@tempboxa=\hbox to 0pt{\yoko\hss\@bannerfont\jlreq@trimmarks@bannerfont##1}%
-            \jlreq@tempdima=\dimexpr\jlreq@trimmarks@bleed + \ht\jlreq@tempboxa\relax
+            \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 + 4pt\relax\@bannerfont\jlreq@trimmarks@bannerfont##1\hss}%
+            \setbox\jlreq@tempboxa=\hbox to 0pt{\hskip\dimexpr\jlreq@trimmarks@bleed@right + 4pt\relax\@bannerfont\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\relax height\@tombowwidth depth\z@\hss
+          \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
+        \hskip\jlreq@trimmarks@bleed@right
       }%
       \kern-10mm
       \hbox to\@@paperwidth{%
@@ -526,9 +592,9 @@
           \jlreq@trimmarks@outputbanner{corner@top@left}{%
             \setbox\jlreq@tempboxa=\hbox to 0pt{\hss\@bannerfont\jlreq@trimmarks@bannerfont##1\hskip 4pt}%
             \dp\jlreq@tempboxa=0pt \ht\jlreq@tempboxa=0pt
-            \raise\dimexpr \jlreq@trimmarks@bleed + 4pt\relax\box\jlreq@tempboxa
+            \raise\dimexpr \jlreq@trimmarks@bleed@top + 4pt\relax\box\jlreq@tempboxa
           }%
-          \vrule height\dimexpr 10mm + \jlreq@trimmarks@bleed\relax width\@tombowwidth depth\z@
+          \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\@bannerfont\jlreq@trimmarks@bannerfont##1\hss}%
             \ifx l\jlreq@trimmarks@engine
@@ -541,7 +607,7 @@
           }%
           \jlreq@trimmarks@outputbanner{intate@top@left}{%
             \setbox\jlreq@tempboxa=\hbox to 0pt{\tate\adjustbaseline\@bannerfont\jlreq@trimmarks@bannerfont##1\hss}%
-            \jlreq@tempdima=\dimexpr\jlreq@trimmarks@bleed \ifx l\jlreq@trimmarks@engine + \ht\jlreq@tempboxa\fi\relax
+            \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
           }%
@@ -558,14 +624,14 @@
           \jlreq@trimmarks@outputbanner{intate@top@right}{%
             \setbox\jlreq@tempboxa=\hbox to 0pt{\tate\adjustbaseline\@bannerfont\jlreq@trimmarks@bannerfont##1\hss}%
             \ifx l\jlreq@trimmarks@engine
-              \jlreq@tempdima=\dimexpr\jlreq@trimmarks@bleed + \ht\jlreq@tempboxa\relax
+              \jlreq@tempdima=\dimexpr\jlreq@trimmarks@bleed@top + \ht\jlreq@tempboxa\relax
             \else
-              \jlreq@tempdima=\dimexpr\jlreq@trimmarks@bleed + \wd\jlreq@tempboxa\relax
+              \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\relax width\@tombowwidth depth\z@
+          \vrule height\dimexpr 10mm + \jlreq@trimmarks@bleed@top\relax width\@tombowwidth depth\z@
           \vrule width10mm height\@tombowwidth depth\z@
           \hss
         }%
@@ -599,10 +665,10 @@
           \jlreq@trimmarks@outputbanner{in@center@left}{%
             \setbox\jlreq@tempboxa=\hbox{\tate\adjustbaseline\@bannerfont\jlreq@trimmarks@bannerfont##1}%
             \ifx l\jlreq@trimmarks@engine
-              \jlreq@tempdima=\dimexpr\jlreq@trimmarks@bleed + \ht\jlreq@tempboxa\relax
+              \jlreq@tempdima=\dimexpr\jlreq@trimmarks@bleed@left + \ht\jlreq@tempboxa\relax
               \jlreq@tempdimb=.5\wd\jlreq@tempboxa
              \else
-              \jlreq@tempdima=\dimexpr\jlreq@trimmarks@bleed\relax
+              \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
@@ -615,10 +681,10 @@
           \jlreq@trimmarks@outputbanner{in@center@right}{%
             \setbox\jlreq@tempboxa=\hbox{\tate\adjustbaseline\@bannerfont\jlreq@trimmarks@bannerfont##1}%
             \ifx l\jlreq@trimmarks@engine
-              \jlreq@tempdima=\dimexpr\jlreq@trimmarks@bleed  + \ht\jlreq@tempboxa\relax
+              \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  + \wd\jlreq@tempboxa\relax
+              \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
@@ -645,7 +711,7 @@
         \hbox to\z@{% \@Bl
           \yoko\hss
           \vrule width10mm depth\@tombowwidth height\z@
-          \vrule depth\dimexpr 10mm + \jlreq@trimmarks@bleed\relax width\@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\@bannerfont\jlreq@trimmarks@bannerfont##1}%
             \ifx l\jlreq@trimmarks@engine
@@ -658,7 +724,7 @@
           }%
           \jlreq@trimmarks@outputbanner{intate@bottom@left}{%
             \setbox\jlreq@tempboxa=\hbox to 0pt{\tate\adjustbaseline\hss\@bannerfont\jlreq@trimmarks@bannerfont##1}%
-            \jlreq@tempdima=\dimexpr\jlreq@trimmarks@bleed \ifx l\jlreq@trimmarks@engine + \ht\jlreq@tempboxa\fi\relax
+            \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
           }%
@@ -675,17 +741,17 @@
           \jlreq@trimmarks@outputbanner{intate@bottom@right}{%
             \setbox\jlreq@tempboxa=\hbox to 0pt{\tate\adjustbaseline\hss\@bannerfont\jlreq@trimmarks@bannerfont##1}%
             \ifx l\jlreq@trimmarks@engine
-              \jlreq@tempdima=\dimexpr\jlreq@trimmarks@bleed + \ht\jlreq@tempboxa\relax
+              \jlreq@tempdima=\dimexpr\jlreq@trimmarks@bleed@right + \ht\jlreq@tempboxa\relax
             \else
-              \jlreq@tempdima=\dimexpr\jlreq@trimmarks@bleed + \wd\jlreq@tempboxa\relax
+              \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\relax width\@tombowwidth height\z@
+          \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\@bannerfont\jlreq@trimmarks@bannerfont##1\hss}%
-            \jlreq@tempdima=\dimexpr\ht\jlreq@tempboxa  + \jlreq@trimmarks@bleed + 4pt\relax
+            \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
           }%
@@ -694,12 +760,12 @@
       }%
       \kern-10mm
       \hbox to\@@paperwidth{%
-        \hskip\jlreq@trimmarks@bleed\relax
+        \hskip\jlreq@trimmarks@bleed@left\relax
         \setbox\jlreq@tempboxa=\hbox to\z@{% \@BL
           \yoko\hss
-          \vrule width\dimexpr 10mm + \jlreq@trimmarks@bleed\relax depth\@tombowwidth height\z@
+          \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\@bannerfont\jlreq@trimmarks@bannerfont##1\hskip\dimexpr\jlreq@trimmarks@bleed + 4pt\relax}%
+            \setbox\jlreq@tempboxa=\hbox to 0pt{\hss\@bannerfont\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
@@ -713,7 +779,7 @@
           }%
           \jlreq@trimmarks@outputbanner{inyoko@bottom@left}{%
             \setbox\jlreq@tempboxa=\hbox to 0pt{\yoko\@bannerfont\jlreq@trimmarks@bannerfont##1\hss}%
-            \jlreq@tempdima=\dimexpr\jlreq@trimmarks@bleed + \dp\jlreq@tempboxa\relax
+            \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
           }%
@@ -732,7 +798,7 @@
           }%
           \jlreq@trimmarks@outputbanner{in@bottom@center}{%
             \setbox\jlreq@tempboxa=\hbox{\@bannerfont\jlreq@trimmarks@bannerfont##1}%
-            \jlreq@tempdima=\dimexpr\dp\jlreq@tempboxa + \jlreq@trimmarks@bleed\relax
+            \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
@@ -759,24 +825,24 @@
           }%
           \jlreq@trimmarks@outputbanner{inyoko@bottom@right}{%
             \setbox\jlreq@tempboxa=\hbox to 0pt{\yoko\hss\@bannerfont\jlreq@trimmarks@bannerfont##1}%
-            \jlreq@tempdima=\dimexpr\dp\jlreq@tempboxa + \jlreq@trimmarks@bleed\relax
+            \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\relax depth\@tombowwidth height\z@\hss
+          \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
+        \hskip\jlreq@trimmarks@bleed@right
       }%
     \color@endgroup}\vss
   }%
 }
 \def\@outputtombow{%
   % 6mm = \@tombowbleed: from plcore
-  \@@paperwidth=\dimexpr\@@paperwidth - 6mm + 2\dimexpr\jlreq@trimmarks@bleed\relax\relax
-  \@@paperheight=\dimexpr\@@paperheight - 6mm + 2\dimexpr\jlreq@trimmarks@bleed\relax\relax
+  \@@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
 }
 
@@ -796,39 +862,92 @@
       \jlreq@trimmarks@pttobp{(\jlreq@trimmarks@paperheight + \paperheight)/2}%
     ]
   }
-  \edef\jlreq@trimmarks@bleedboxsize{%
+  \jlreq@tempcnta=\c@page
+  \def\@tempa{%
     [%
-      \jlreq@trimmarks@pttobp{(\jlreq@trimmarks@paperwidth - \paperwidth)/2 - \jlreq@trimmarks@bleed}
-      \jlreq@trimmarks@pttobp{(\jlreq@trimmarks@paperheight - \paperheight)/2 - \jlreq@trimmarks@bleed}
-      \jlreq@trimmarks@pttobp{(\jlreq@trimmarks@paperwidth + \paperwidth)/2 + \jlreq@trimmarks@bleed}
-      \jlreq@trimmarks@pttobp{(\jlreq@trimmarks@paperheight + \paperheight)/2 + \jlreq@trimmarks@bleed}%
+      \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}%
     ]
   }
-  \edef\jlreq@trimmarks@pdfattribute{%
+  \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
+    /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}
-  \jlreq@trimmarks@afterpkg@addtodeletecs{\jlreq@trimmarks@pdfattribute}
+  \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}
 
-  \ifx l\jlreq@trimmarks@driver
-    \edef\@tempa{\noexpand\pdfvariable pageattr{\jlreq@trimmarks@pdfattribute}}
-    \@tempa
-  \fi
-  \ifx f\jlreq@trimmarks@driver
-    \edef\@outputtombow{\noexpand\special{pdf: put @thispage <<\jlreq@trimmarks@pdfattribute>>}\expandonce{\@outputtombow}}
-  \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 /PAGE pdfmark
-    end}}%
-    \@tempa
-  \fi
+  \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
-- 
cgit v1.2.3

