以任意单位显示橡胶长度

以任意单位显示橡胶长度

基于这个问题,我知道如何显示以任意单位表示的常规长度。但是,我需要对橡胶长度执行相同操作(显示正数和负数),并且该printlen软件包不支持除 pt 之外的选项。是否有适用于橡胶长度的等效方法?

答案1

在此处输入图片描述

etex 具有用于提取组件的附加原语,以便您可以单独打印它们:

\documentclass{article}

\usepackage{printlen}


\begin{document}

\the\parskip


The \verb|\parskip| is \printlength{\dimexpr\parskip\relax} which is also
\uselengthunit{in}\printlength{\dimexpr\parskip\relax} and
\uselengthunit{mm}\printlength{\dimexpr\parskip\relax}.


The \verb|\gluestretch\parskip| is \printlength{\gluestretch\parskip} which is also
\uselengthunit{in}\printlength{\gluestretch\parskip} and
\uselengthunit{mm}\printlength{\gluestretch\parskip}.


The \verb|\glueshrink\parskip| is \printlength{\glueshrink\parskip} which is also
\uselengthunit{in}\printlength{\glueshrink\parskip} and
\uselengthunit{mm}\printlength{\glueshrink\parskip}.

\end{document}

答案2

expl3这是一个使用它来处理无限组件的版本。

\documentclass{article}
\usepackage{xparse}

\ExplSyntaxOn
\NewDocumentCommand{\printglue}{O{pt}m}
 { % #1 = unit, #2 = glue
  \rpspringuel_print_glue:nn { #1 } { #2 }
 }

\cs_new_protected:Npn \rpspringuel_print_glue:nn #1 #2
 {
  \skip_set:Nn \l_rpspringuel_input_skip { #2 }
  \dim_set:Nn \l_rpspringuel_natural_dim { \l_rpspringuel_input_skip }
  \dim_set:Nn \l_rpspringuel_stretch_dim
   { \rpspringuel_gluestretch:n { \l_rpspringuel_input_skip } }
  \dim_set:Nn \l_rpspringuel_shrink_dim
   { \rpspringuel_glueshrink:n { \l_rpspringuel_input_skip } }
  \int_set:Nn \l_rpspringuel_stretch_order_int
   { \rpspringuel_gluestretchorder:n { \l_rpspringuel_input_skip } }
  \int_set:Nn \l_rpspringuel_shrink_order_int
   { \rpspringuel_glueshrinkorder:n { \l_rpspringuel_input_skip } }
  % print the components
  \dim_to_decimal_in_unit:nn { \l_rpspringuel_natural_dim } { 1#1 }
  \,#1
  \c_space_tl
  plus
  \c_space_tl
  \int_case:nn { \l_rpspringuel_stretch_order_int }
   {
    { 0 } { \dim_to_decimal_in_unit:nn { \l_rpspringuel_stretch_dim } { 1#1 }\,#1 }
    { 1 } { \dim_to_decimal_in_unit:nn { \l_rpspringuel_stretch_dim } { 1pt }\,fil }
    { 2 } { \dim_to_decimal_in_unit:nn { \l_rpspringuel_stretch_dim } { 1pt }\,fill }
    { 3 } { \dim_to_decimal_in_unit:nn { \l_rpspringuel_stretch_dim } { 1pt }\,filll }
   }
  \c_space_tl
  minus
  \c_space_tl
  \int_case:nn { \l_rpspringuel_shrink_order_int }
   {
    { 0 } { \dim_to_decimal_in_unit:nn { \l_rpspringuel_shrink_dim } { 1#1 }\,#1 }
    { 1 } { \dim_to_decimal_in_unit:nn { \l_rpspringuel_shrink_dim } { 1pt }\,fil }
    { 2 } { \dim_to_decimal_in_unit:nn { \l_rpspringuel_shrink_dim } { 1pt }\,fill }
    { 3 } { \dim_to_decimal_in_unit:nn { \l_rpspringuel_shrink_dim } { 1pt }\,filll }
   }
 }

\skip_new:N \l_rpspringuel_input_skip
\dim_new:N \l_rpspringuel_natural_dim
\dim_new:N \l_rpspringuel_stretch_dim
\dim_new:N \l_rpspringuel_shrink_dim
\int_new:N \l_rpspringuel_stretch_order_int
\int_new:N \l_rpspringuel_shrink_order_int

\cs_new:Npn \rpspringuel_gluestretch:n #1
 {
  \etex_gluestretch:D \etex_glueexpr:D #1\scan_stop:
 }
\cs_new:Npn \rpspringuel_glueshrink:n #1
 {
  \etex_glueshrink:D \etex_glueexpr:D #1\scan_stop:
 }
\cs_new:Npn \rpspringuel_gluestretchorder:n #1
 {
  \etex_gluestretchorder:D \etex_glueexpr:D #1\scan_stop:
 }
\cs_new:Npn \rpspringuel_glueshrinkorder:n #1
 {
  \etex_glueshrinkorder:D \etex_glueexpr:D #1\scan_stop:
 }

\ExplSyntaxOff

\begin{document}

\printglue{\parskip}

\printglue{\fill}

\newlength\mylength

\setlength\mylength{10cm plus 1cm minus 1filll}

\printglue[cm]{\mylength}

\printglue[mm]{10cm plus 1cm minus 1filll}

\end{document}

\gluestretch请注意,、\gluestretchorder和没有公共接口,\glueshrink因此\glueshrinkorder我定义了一个。

四舍五入可能会产生意想不到的结果;使用fp模块可能会改善这种情况。

在此处输入图片描述

相关内容