访问胶水注册表的各个部分

访问胶水注册表的各个部分

这可能是一个愚蠢的问题,但我似乎无法在任何地方找到答案:假设我有这个简单的纯 TeX 代码:

\newskip\myskip
\myskip = 10pt plus 4pt minus 2pt

现在,我如何访问(读取)那些拉伸和收缩部分4pt以及那些2pt值?

David 回答后:这就是我想要的:

%%%! tex
\newskip\spaceskipFixed

% nonsensical values just for testing
\spaceskipFixed = 10pt plus 4pt minus 2pt
\spaceskip = \spaceskipFixed

% wrong, glue becomes dimen, stretchability and shrinkability gone
\def\modifyspaces #1 {%
    \spaceskip = #1\spaceskipFixed
}

\def\text{Aha oho haha hoho!}
\newbox\gauge \setbox\gauge = \hbox{\modifyspaces .5 \text}
\def\showline #1#2{
    \line{\hbox to\wd\gauge{#1\hfill}\hskip 2em {\spaceskip = 0pt\tt\% #2}\hfill}
}

\line{\text\hskip 2em{\spaceskip = 0pt\tt \% unmodified, wild spaces}\hfill}
\vbox to 0pt{\noindent\kern \wd\gauge\hbox{\vrule width .1pt height 0pt depth 15mm}\par\vskip -15mm}
\showline{\modifyspaces .5 \text}{simple text with modified spaces, width \the\wd\gauge}
\showline{\hbox to 92pt {\modifyspaces .5 \text}}{hbox to 92pt, no shrinkability => overfull}

% fixed
\def\modifyspaces #1 {%
    \spaceskip = #1\spaceskipFixed plus #1\gluestretch\spaceskipFixed minus #1\glueshrink\spaceskipFixed
}
\showline{\hbox to 92pt {\modifyspaces .5 \text}}{hbox to 92pt, shrinkability preserved, all shiny}
\bye

在此处输入图片描述

答案1

如果你启用了 etex 扩展,你可以这样做

\newskip\myskip
\myskip = 10pt plus 4pt minus 2pt

\edef\z{\the\gluestretch\myskip}
\show\z
\edef\z{\the\glueshrink\myskip}
\show\z
\bye

产生

> \z=macro:
->4.0pt.
l.5 \show\z

? 
> \z=macro:
->2.0pt.
l.7 \show\z

? 

答案2

你必须注意无限胶水:

\documentclass{article}

\makeatletter
\newcommand{\extractnatural}[1]{%
  \the\dimexpr#1\relax
}
\newcommand{\extractstretch}[1]{%
  \strip@pt\dimexpr\gluestretch#1\relax
  \ifcase\gluestretchorder#1pt\or fil\or fill\or filll\fi
}
\newcommand{\extractshrink}[1]{%
  \strip@pt\dimexpr\glueshrink#1\relax
  \ifcase\glueshrinkorder#1pt\or fil\or fill\or filll\fi
}
\makeatother

\newlength{\test}

\begin{document}

\setlength{\test}{10pt plus 4pt minus 2pt}
\texttt{\the\test}: (\extractnatural{\test}) (\extractstretch{\test}) (\extractshrink{\test})

\setlength{\test}{10pt plus 4fil minus 2pt}
\texttt{\the\test}: (\extractnatural{\test}) (\extractstretch{\test}) (\extractshrink{\test})

\setlength{\test}{10pt plus 4filll minus 2fill}
\texttt{\the\test}: (\extractnatural{\test}) (\extractstretch{\test}) (\extractshrink{\test})

\edef\macro{(\extractnatural{\test}) (\extractstretch{\test}) (\extractshrink{\test})}
\texttt{\meaning\macro}

\end{document}

在此处输入图片描述

相关内容