使用 XeLaTeX 时,Trimbox 不会显示整页浮动

使用 XeLaTeX 时,Trimbox 不会显示整页浮动

我的标签如下(感谢David Carlisle我如何才能动态地(使用宏)设置 PDF TrimBox 并使其独立于编译器?David Purton 使用 PDFLaTeX 设置 BleedBox

%\pdfcompresslevel0
\documentclass{article}
\usepackage{graphicx}
\usepackage{xparse}

\ExplSyntaxOn\makeatletter %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% bleed value (keyval class option in real document)
\dim_new:N \g_@@_bleed_dim 
\dim_set:Nn \g_@@_bleed_dim { 3mm }

%% set page size (and other stuff in the real document)
\usepackage { geometry }
   \geometry { papersize = { 185mm , 245mm } }

%% set crop size
\usepackage [ center ] { crop }
   \CROP@size {
      \dim_eval:n { \paperwidth + 2 \g_@@_bleed_dim }
   } {
      \dim_eval:n { \paperheight + 2 \g_@@_bleed_dim }
   }

%% new variant
\cs_generate_variant:Nn \dim_to_decimal_in_bp:n { V }

% values for the rim box
\tl_new:N \g_@@_trim_box_quadruple_tl
\tl_set:Nx \g_@@_trim_box_quadruple_tl {
   \dim_to_decimal_in_bp:V \g_@@_bleed_dim \space 
   \dim_to_decimal_in_bp:V \g_@@_bleed_dim \space
   \dim_to_decimal_in_bp:n { \paperwidth + \g_@@_bleed_dim } \space
   \dim_to_decimal_in_bp:n { \paperheight + \g_@@_bleed_dim }
}

%% special for use with XeTeX
\tl_new:N \g_@@_trim_special_tl
\tl_set:Nx \g_@@_trim_special_tl {
   pdf: ~ put ~ @thispage ~
   << ~ /TrimBox \space [ \g_@@_trim_box_quadruple_tl ] ~ >>
}

%% page attribute for use with LuaTeX and PDFTeX
\tl_new:N \g_@@_trim_pageattr_tl
\tl_set:Nx \g_@@_trim_pageattr_tl {
   /TrimBox \space [ \g_@@_trim_box_quadruple_tl ]
}




%% command to set the specials for xetex
\cs_new:Npn \@@_special:n #1 {
   \AtBeginShipout { \immediate \special { #1 } }
   \immediate \special { #1 }
}

%% command to set the page attributes for pdftex/luatex
\cs_new:Npn \@@_pdfpageattr:n #1 {
   \pdfpageattr { #1 }
}

%% make a variants to make sure we get the expaned content
\cs_generate_variant:Nn \@@_special:n { V }
\cs_generate_variant:Nn \@@_pdfpageattr:n { V }

%% [A] THIS DOES NOT WORK!
%% set the trim box according to engine
\bool_if:nTF { \sys_if_engine_luatex_p: || \sys_if_engine_pdftex_p: } {
   \@@_pdfpageattr:V \g_@@_trim_pageattr_tl
} {
   \sys_if_engine_xetex:TF {
      \usepackage{atbegshi}
      \@@_special:V \g_@@_trim_special_tl
   } { ERROR: UNKOWN MACHINE! }
}

%% just a macro to show some debug info
\NewDocumentCommand { \debuginfo } { } {
   \par\noindent
   Machine: ~ \texttt{ \c_sys_engine_str }

   \par\bigskip\noindent
   special: \\
   \mbox { \texttt { \g_@@_trim_special_tl } }

   \par\medskip\noindent
   pageattribute: \\
   \mbox { \texttt { \g_@@_trim_pageattr_tl } }
}

\ExplSyntaxOff\makeatother %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% [B] THIS WORKS!
%% for pdftex and luatex
%\pdfpageattr { /TrimBox [8.50392 8.50392 532.91336 702.99211] }
%% for xetex
%\usepackage{atbegshi}
%\AtBeginShipout { \special { pdf: put @thispage << /TrimBox [8.50392 8.50392 532.91336 702.99211] >> } }
%\special { pdf: put @thispage << /TrimBox [8.50392 8.50392 532.91336 702.99211] >> }

\begin{document}
\section*{Test Document}
\debuginfo \clearpage Just another page \ldots

\newpage

\begin{figure}[p!]
\includegraphics{example-image-a}
\end{figure}

\end{document}

我使用XeLaTeX上面的方法可以正常工作并TrimBox在所有页面中都使用,但是当出现整页浮动时它就TrimBox消失了,请建议如何实现...但是使用时所有页面都可以正常工作PDFLaTeX...

答案1

抱歉,我不知道它为什么会消失,我也没时间看。如果你想在所有页面上使用相同的裁切框,你可以使用pdf: ~ put ~ @pages ~。或者你可以尝试新的 pdfmanagement:

\DocumentMetadata{}
\documentclass{article}

\usepackage{graphicx}
\ExplSyntaxOn
\pdfmanagement_add:nnn{Page}{Trimbox}{[8.50392~8.50392~532.91336~702.99211]}
% or
%\pdfmanagement_add:nnn{Pages}{Trimbox}{[8.50392~8.50392~532.91336~702.99211]}
\ExplSyntaxOff
\begin{document}


\section*{Test Document}
\clearpage Just another page \ldots

\newpage

\begin{figure}[p!]
\includegraphics{example-image-a}
\end{figure}

\end{document}

这适用于所有引擎。

答案2

这基本上与 Ulrike 的回答相同,只是我使用你的代码作为基础(并修复了 Ulrike 的回答中的 Trimbox→TrimBox 拼写错误)。

我建议您使用新pdfmanagement代码,它目前有效,并且从长远来看肯定会更加可靠。

经过我的测试,这三种引擎均有效:

\DocumentMetadata{uncompress}
\documentclass{article}
\usepackage{graphicx}

\ExplSyntaxOn\makeatletter %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% bleed value (keyval class option in real document)
\dim_new:N \g_@@_bleed_dim 
\dim_set:Nn \g_@@_bleed_dim { 3mm }

%% set page size (and other stuff in the real document)
\usepackage { geometry }
\geometry { papersize = { 185mm , 245mm } }

%% set crop size
\usepackage [ center ] { crop }
\CROP@size
  {
    \dim_eval:n { \paperwidth + 2 \g_@@_bleed_dim }
  }
  {
    \dim_eval:n { \paperheight + 2 \g_@@_bleed_dim }
  }

%% new variant
\cs_generate_variant:Nn \dim_to_decimal_in_bp:n { V }

% values for the TrimBox
\tl_new:N \g_@@_trim_box_quadruple_tl
\tl_set:Nx \g_@@_trim_box_quadruple_tl
  {
    \dim_to_decimal_in_bp:V \g_@@_bleed_dim \space
    \dim_to_decimal_in_bp:V \g_@@_bleed_dim \space
    \dim_to_decimal_in_bp:n { \paperwidth + \g_@@_bleed_dim } \space
    \dim_to_decimal_in_bp:n { \paperheight + \g_@@_bleed_dim }
  }

% set the TrimBox
\pdfmanagement_add:nnx
  { Page }
  { TrimBox }
  { [ \g_@@_trim_box_quadruple_tl ] }

\ExplSyntaxOff\makeatother %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}
\section*{Test Document}

\clearpage

Just another page \ldots

\clearpage

\begin{figure}[p!]
\includegraphics{example-image-a}
\end{figure}

\end{document}

相关内容