![带有 xkeyval、fp 和 newcommand 的库](https://linux22.com/image/477509/%E5%B8%A6%E6%9C%89%20xkeyval%E3%80%81fp%20%E5%92%8C%20newcommand%20%E7%9A%84%E5%BA%93.png)
在网上搜索过,但没找到任何解决方案。我在定义库结构(xkeyval
)时遇到了一些问题,其中使用了 FPeval 计算,然后将此信息/计算传递给文档中的 FPeval。我基本上想创建一个大型的键/值库,并用它们进行一系列计算:
\documentclass{article}
\usepackage{fp}% http://ctan.org/pkg/fp
\usepackage{xkeyval}% http://ctan.org/pkg/xkeyval
\usepackage{siunitx} %Adding SI-prefixes
\sisetup{
exponent-to-prefix = true,
round-mode = figures,
round-precision = 3,
scientific-notation = engineering
}%
%
%
\newcommand \Family[1]{\setkeys{RESFamily}{#1}}%
\makeatletter
%
\define@key{RESFamily}{Name}{ \newcommand \RESFamilyName{#1} }%
\define@key{RESFamily}{Value}{ \newcommand \RESFamilyValue{#1} }%
%
\makeatother
%
\AtBeginDocument{
%##################################################################################################
\Family{%
Name = Some text here,%
Value = ,%Value is added in the LIBRARY components
}%
%
\newcommand \defRES[3]{%START of \defRES
\expandafter\newcommand\csname #1Name\endcsname{\csname RES#2Name\endcsname}%
\expandafter\newcommand\csname #1Value\endcsname{#3}% 1
%With this now i am having problems
\expandafter\newcommand\csname #1Max\endcsname{% START of MAX FPeval
\ensuremath{\FPeval{\RtmpMax}{round( \csname #1Value\endcsname * (1+20/100) :4 )}}\RtmpMax%
}%END of MAX FPeval
%
\ignorespaces}%END of \defRES
%
%LIBRARY
\defRES{Rone}{Family}{10}%
%
}%
%
\begin{document}
test = \RoneName\\
test = \RoneValue\\
\FPeval{\resultTwo}{round( 2*2 :2)}
test2 = 2 * 2 =\resultTwo\\
\FPeval{\resultThree}{round( \RoneValue * \RoneValue :2)}
test3 = \RoneValue * \RoneValue = \resultThree\\
test3a = \RoneValue * \RoneValue = \num{\resultThree}\\
%until now everything OK
test3a = \num[parse-numbers=false]{\RoneMax}\\% this offcourse works
%now NOK
test3a = \num{\RoneMax}
\FPeval{\resultFour}{round( \RoneMax * \RoneMax :2)}
test3 = \resultFour \\
test3a = \num{\resultFour}
\end{document}
如果对此还有任何疑问,请直接提问。如能得到任何帮助,我们将不胜感激。
答案1
我想我已经找到了一个可能的解决方案。我已将\defRES
宏重新排列为如下形式:
\newcommand \defRES[3]{%START of \defRES
\expandafter\newcommand\csname #1Name\endcsname{\csname RES#2Name\endcsname}%
\expandafter\newcommand\csname #1Value\endcsname{#3}% 1 %
\FPeval{#1Max}{round( \csname #1Value\endcsname * (1+20/100) :4 )}%
\ignorespaces}%END of \defRES
现在我可以从 打印出一个数字(不带参数) \num
,并且它也可以用于进一步的计算。\SI
[parse-numbers=false]
\FPeval