更改几何包日志输出的单位

更改几何包日志输出的单位

几何包会将其计算的尺寸摘要(以点为单位)输出到日志文件。在处理以厘米(或任何其他单位,我猜)为单位的客户规范时,以这些单位输出会很方便。

在我开始编辑执行此操作的宏的私人副本\Gm@logcontent以使用 printlen 包之前,是否有人这样做过?您是否愿意分享您的代码?

答案1

使用这种方法可以达到以下效果:

\documentclass[a4paper]{article}

\usepackage{geometry}

\usepackage{xintexpr}

\makeatletter
% the [2] is for one hundredth of a millimeter which seems precise enough
\def\Gm@showdim#1{* \string#1=\xinttheiexpr [2]#1*635/118407168\relax mm^^J}
\makeatother
\begin{document}
See the log
\end{document}

日志内容如下:

*geometry* driver: auto-detecting
*geometry* detected driver: pdftex
*geometry* verbose mode - [ preamble ] result:
* driver: pdftex
* paper: a4paper
* layout: <same size as paper>
* layoutoffset:(h,v)=(0.0pt,0.0pt)
* modes: 
* h-part:(L,W,R)=(89.62709pt, 418.25368pt, 89.6271pt)
* v-part:(T,H,B)=(101.40665pt, 591.5302pt, 152.11pt)
* \paperwidth=210.00mm
* \paperheight=297.00mm
* \textwidth=147.00mm
* \textheight=207.90mm
* \oddsidemargin=6.10mm
* \evensidemargin=6.10mm
* \topmargin=-2.76mm
* \headheight=4.22mm
* \headsep=8.79mm
* \topskip=3.51mm
* \footskip=10.54mm
* \marginparwidth=20.03mm
* \marginparsep=3.87mm
* \columnsep=3.51mm
* \skip\footins=9.0pt plus 4.0pt minus 2.0pt
* \hoffset=0mm
* \voffset=0mm
* \mag=0.01mm
* \@twocolumnfalse
* \@twosidefalse
* \@mparswitchfalse
* \@reversemarginfalse
* (1in=72.27pt=25.4mm, 1cm=28.453pt)

由于方式不同,某些尺寸仍以 pt 表示\Gm@logcontent。例如,它包含

  * h-part:(L,W,R)=(\Gm@lmargin, \Gm@width, \Gm@rmargin)^^J%
  * v-part:(T,H,B)=(\Gm@tmargin, \Gm@height, \Gm@bmargin)^^J%

您需要按照上述思路对其中两处进行修改。

答案2

不包含\printlength在包装内printlen,因为它不可扩展。

\documentclass{article}
\usepackage[verbose]{geometry}
\usepackage{xparse}

\ExplSyntaxOn
\NewDocumentCommand{\setunit}{m}
 {
  \tl_gset:Nn \g_geometry_unit_tl { #1 }
 }
\DeclareExpandableDocumentCommand{\printlength}{m}
 {
  \dim_to_decimal_in_unit:nn { #1 } { 1\g_geometry_unit_tl } \g_geometry_unit_tl
 }
\setunit{pt} % initialize
\ExplSyntaxOff


\makeatletter
\def\Gm@logcontent#1{%
  *geometry* verbose mode - [ #1 ] result:^^J%
  \ifGm@pass * pass: disregarded the geometry package!^^J%
  \else
  * driver: \if\Gm@driver<none>\else\Gm@driver\fi^^J%
  * paper: \ifx\Gm@paper\@undefined<default>\else\Gm@paper\fi^^J%
  * layout: \ifGm@layout<custom>\else<same size as paper>\fi^^J%
  \ifGm@layout
  * layout(width,height): (\printlength\Gm@layoutwidth,\printlength\Gm@layoutheight)^^J%
  \fi
  * layoutoffset:(h,v)=(\printlength\Gm@layouthoffset,\printlength\Gm@layoutvoffset)^^J%
  \@ifundefined{Gm@lines}{}{* lines: \Gm@lines^^J}%
  \@ifundefined{Gm@hmarginratio}{}{* hratio: \Gm@hmarginratio^^J}%
  \@ifundefined{Gm@vmarginratio}{}{* vratio: \Gm@vmarginratio^^J}%
  \ifdim\Gm@bindingoffset=\z@\else
  * bindingoffset: \printlength\Gm@bindingoffset^^J\fi
  * modes: %
   \Gm@showbool{landscape}%
   \Gm@showbool{includehead}%
   \Gm@showbool{includefoot}%
   \Gm@showbool{includemp}%
   \if@twoside twoside\space\fi%
   \if@mparswitch\else\if@twoside asymmetric\space\fi\fi%
   \Gm@showbool{heightrounded}%
   \ifx\Gm@truedimen\@empty\else truedimen\space\fi%
   \Gm@showbool{showframe}%
   \Gm@showbool{showcrop}%
  ^^J%
  * h-part:(L,W,R)=(\printlength\Gm@lmargin, \printlength\Gm@width, \printlength\Gm@rmargin)^^J%
  * v-part:(T,H,B)=(\printlength\Gm@tmargin, \printlength\Gm@height, \printlength\Gm@bmargin)^^J%
  \fi
  \Gm@showdim{\paperwidth}%
  \Gm@showdim{\paperheight}%
  \Gm@showdim{\textwidth}%
  \Gm@showdim{\textheight}%
  \Gm@showdim{\oddsidemargin}%
  \Gm@showdim{\evensidemargin}%
  \Gm@showdim{\topmargin}%
  \Gm@showdim{\headheight}%
  \Gm@showdim{\headsep}%
  \Gm@showdim{\topskip}%
  \Gm@showdim{\footskip}%
  \Gm@showdim{\marginparwidth}%
  \Gm@showdim{\marginparsep}%
  \Gm@showdim{\columnsep}%
  * \string\skip\string\footins=\the\skip\footins^^J%
  \Gm@showdim{\hoffset}%
  \Gm@showdim{\voffset}%
  * \string\mag=\the\mag^^J%
  * \string\@twocolumn\if@twocolumn true\else false\fi^^J%
  * \string\@twoside\if@twoside true\else false\fi^^J%
  * \string\@mparswitch\if@mparswitch true\else false\fi^^J%
  * \string\@reversemargin\if@reversemargin true\else false\fi^^J%
  * (1in=72.27pt=25.4mm, 1cm=28.453pt)^^J}%
\def\Gm@showdim#1{* \string#1=\printlength#1^^J}
\makeatother

\setunit{cm}% use centimeters for logging the dimensions

\begin{document}

\end{document}

这是日志文件中的输出

*geometry* driver: auto-detecting
*geometry* detected driver: pdftex
*geometry* verbose mode - [ preamble ] result:
* driver: pdftex
* paper: <default>
* layout: <same size as paper>
* layoutoffset:(h,v)=(0cm,0cm)
* modes: 
* h-part:(L,W,R)=(3.23854cm, 15.11295cm, 3.23854cm)
* v-part:(T,H,B)=(3.35283cm, 19.55792cm, 5.02925cm)
* \paperwidth=21.59001cm
* \paperheight=27.94002cm
* \textwidth=15.11295cm
* \textheight=19.55792cm
* \oddsidemargin=0.69853cm
* \evensidemargin=0.69853cm
* \topmargin=-0.48756cm
* \headheight=0.42175cm
* \headsep=0.87865cm
* \topskip=0.35146cm
* \footskip=1.05438cm
* \marginparwidth=2.28448cm
* \marginparsep=0.38661cm
* \columnsep=0.35146cm
* \skip\footins=9.0pt plus 4.0pt minus 2.0pt
* \hoffset=0cm
* \voffset=0cm
* \mag=1000
* \@twocolumnfalse
* \@twosidefalse
* \@mparswitchfalse
* \@reversemarginfalse
* (1in=72.27pt=25.4mm, 1cm=28.453pt)

相关内容