String 乳胶中的字符串替换

String 乳胶中的字符串替换,string,latex,replace,String,Latex,Replace,我想知道如何用乳胶替换绳子的部分。具体来说,我得到了一个测量值(如3pt、10mm等),我想删除该测量值的单位(如3pt-->3、10mm-->10等)。 我希望使用命令执行此操作的原因是在以下代码段中: \newsavebox{\mybox} \sbox{\mybox}{Hello World!} \newlength{\myboxw} \newlength{\myboxh} \settowidth{\myboxw}{\usebox{\mybox}} \settoheight{\myboxh}

我想知道如何用乳胶替换绳子的部分。具体来说,我得到了一个测量值(如3pt、10mm等),我想删除该测量值的单位(如3pt-->3、10mm-->10等)。 我希望使用命令执行此操作的原因是在以下代码段中:

\newsavebox{\mybox}
\sbox{\mybox}{Hello World!}
\newlength{\myboxw}
\newlength{\myboxh}
\settowidth{\myboxw}{\usebox{\mybox}}
\settoheight{\myboxh}{\usebox{\mybox}}
\begin{picture}(\myboxw,\myboxh)
\end{picture}
基本上我创建了一个名为mybox的存储框。我把“你好,世界”这个词插入我的信箱。我创建了一个新的长度/宽度,称为myboxw/h。然后我得到mybox的宽度/高度,并将其存储在myboxw/h中。然后我设置了一个图片环境,其尺寸对应于myboxw/h。问题是myboxw返回的是形式为“132.56pt”的内容,而图片环境的输入必须是无量纲的:“\begin{picture}{132.56,132.56}”

因此,我需要一个命令,它将从字符串中删除度量单位。
谢谢

使用以下技巧:

{
\catcode`p=12 \catcode`t=12
\gdef\removedim#1pt{#1}
}
然后写:

\edef\myboxwnopt{\expandafter\removedim\the\myboxw}
\edef\myboxhnopt{\expandafter\removedim\the\myboxh}
\begin{picture}(\myboxwnopt,\myboxhnopt)
\end{picture}  

考虑一下
xstring
包。

LaTeX内核--已经提供了
\strip@pt
,可用于去除对长度的任何引用。此外,不需要为长方体的宽度和/或高度创建长度
\wd
返回宽度,而
\ht
返回高度:

\documentclass{article}

\makeatletter
\let\stripdim\strip@pt % User interface for \strip@pt
\makeatother

\begin{document}

\newsavebox{\mybox}
\savebox{\mybox}{Hello World!}

\begin{picture}(\stripdim\wd\mybox,\stripdim\ht\mybox)
  \put(0,0){Hello world}
\end{picture}

\end{document}
考虑使用与乳胶相关的问题。