在Latex中管理带符号的数字宏参数

时间:2016-05-24 13:09:32

标签: macros latex numeric curly-braces

我已经使用不需要的效果签名了数字:

x+-5
x--5

(我事先不知道常量\ const是正还是负)。 我创建了这些宏来解决这个问题:

\def\plus#1{\ifthenelse{#1<0}{#1}{+#1}}
\def\cutMinus-#1{#1} % to remove the minus in front of a negative number
\def\minus#1{\ifthenelse{#1<0}{+\cutMinus#1}{-#1}}

然后用

x\plus{\const}

我正确地得到了表达式:

x-5

目标:我希望我可以使用\ plus和\ minus作为标准+ ans的替代品 - 如下所示(如果可能的话,没有花括号使得输入时间更长并且更不清晰):

x\plus\const
x\minus\const

以下是我的测试:\ plus,\ cutMinus和\ minus根据参数的给定方式有不同的行为。

\def\const{-123456}\\
%
*1**x\plus{-12345} ****\\
%*2**x\plus -12345 ****\\ % compilation error : ! Missing number, treated as zero.
%*3**x\plus-12345 ****\\ % compilation error : ! Missing number, treated as zero.
*4**x\plus{\const} ****\\
*5**x\plus\const ****\\
%*6**\plus-\const ***\\ % compilation error : ! Missing number, treated as zero.
%
%*11**\cutMinus{-12345} ***\\ % compilation error :  ! Use of \cutMinus doesn't match its definition. ! Too many }'s.
*12**\cutMinus -12345 ***\\
*13**\cutMinus-12345 ***\\
%*14**\cutMinus{\const} ***\\ % compilation error :  ! Use of \cutMinus doesn't match its definition. ! Too many }'s.
%*15**\cutMinus\const ***\\ % compilation error :  ! Use of \cutMinus doesn't match its definition.
*16**\cutMinus-\const ***\\
%
*21**x\minus{-12345} ****\\
%*22**x\minus -12345 ****\\ % compilation error : ! Missing number, treated as zero.
%*23**x\minus-12345 ****\\ % compilation error : ! Missing number, treated as zero.
%*24**x\minus{\const} ****\\ % compilation error :  ! Use of \cutMinus doesn't match its definition.
%*25**x\minus\const ****\\ % compilation error :  ! Use of \cutMinus doesn't match its definition.
%*26**\minus-\const ***\\ % compilation error : ! Missing number, treated as zero.
%

我不明白所有这些错误。似乎\ const和-12345不等同。数字内部编码的问题? 如何修改我的宏以使其具有功能? 更确切地说 : * \ minus不能使用宏\ const * \ cutMinus,我用来摆脱负数前面的减号的方式,对于宏\ const不起作用。可能还有另一种摆脱“ - ”标志的方法吗? *我希望我可以像这样使用\ minus:x \ minus \ const给出:x + 12345(使用\ const等于-13245)

0 个答案:

没有答案