我遇到的问题是,我的交叉引用和相应的计算似乎无法在\tabbing
环境中正常工作。计算本身似乎可以工作,但交叉引用可能被封装在 '\tabbing` 环境中。
顺便说一句:Minipage 环境显示出相同的行为,所以我认为这是一个系统问题。
平均能量损失
\documentclass{article}
\usepackage[parfill]{parskip}
\usepackage{zref}
\usepackage{siunitx}
\newcommand{\myHSpace}{25mm}
\makeatletter
\newcommand\mylabel[2]{%
\def\@currentlabel{#2}\phantomsection\label{mylabel:#1}{#2}}
\newcommand\myref[1]{%
\ref{mylabel:#1}}
\makeatother
\makeatletter
\ExplSyntaxOn
\cs_new_protected_nopar:Npn \DefineExemptionOrderBudget #1#2{%
\@bsphack
\exp_args:Nnf
\zref@newprop{ExemptionOrder#1}{\fp_to_decimal:n{(#2)}}
\@esphack
}%
\cs_new_protected_nopar:Npn \WithdrawFromExemptionOrderBudget #1#2 {%
\@bsphack
\exp_args:Nnf
\zref@setcurrent{ExemptionOrder#1}{%
\fp_to_decimal:n{(\zref@getcurrent{ExemptionOrder#1})-(#2)}
}
\@esphack
}%
\cs_new_protected_nopar:Npn \GetCurrentExemptionOrderBudget #1 {%
\fp_to_decimal:n {(\zref@getcurrent{ExemptionOrder#1})}
}
\cs_new_protected_nopar:Npn \SetRemainingExemptionOrderBudgetToLabel #1#2 {%
\zref@labelbyprops{#2}{ExemptionOrder#1}
}
\cs_new_protected_nopar:Npn \ReferToOverallExemptionOrderBudgetLeft #1#2#3 {%
\zref@ifrefundefined{#2}
{\use_ii:nn}
{\zref@ifrefcontainsprop{#2}{ExemptionOrder#1}{\use_i:nn}{\use_ii:nn}}
{ \PrintMoney{\zref@extractdefault{#2}{ExemptionOrder#1}{0}}{#3}}
{\zref@refused{#2}\textsf{??}}
}
\cs_new_protected_nopar:Npn \PrintMoney #1#2 {%
\exp_args:Nne
\use:n {\SI [{ add-decimal-zero,
add-integer-zero,
detect-mode=true,
round-mode=places,
round-half=up,
group-digits=true,
group-minimum-digits=2,
group-separator=\,,
output-decimal-marker={,},
round-precision={#2}}]}
{\fp_to_decimal:n{round(((#1)+0),#2,NaN)}}{€}
}
\DefineExemptionOrderBudget{ExemptionBudget}{1000}
\cs_new_protected_nopar:Npn \WithdrawFromExemptionOrderBudgetForAccount #1 {%
\WithdrawFromExemptionOrderBudget{ExemptionBudget}{#1}
Piece~price:\nobreakspace
\PrintMoney{#1}{2}\nobreakspace/~
Money~left~currently~\PrintMoney{\GetCurrentExemptionOrderBudget{ExemptionBudget}}{2}\nobreakspace/~
Money~left~overall~\ReferToOverallExemptionOrderBudgetLeft{ExemptionBudget}{overall}{2})
}
\cs_new_protected_nopar:Npn\RecordFinalExemptionOrderBudgetToLabel {%
\SetRemainingExemptionOrderBudgetToLabel{ExemptionBudget}{overall}
}
\ExplSyntaxOff
\makeatother
\begin{document}
Complete Budget: \PrintMoney{\GetCurrentExemptionOrderBudget{ExemptionBudget}}{2}\\
\WithdrawFromExemptionOrderBudgetForAccount{20}\\
\begin{tabbing}
\hspace{\myHSpace}\=\kill
Tabbing:\>\WithdrawFromExemptionOrderBudgetForAccount{20}\\
\end{tabbing}
\WithdrawFromExemptionOrderBudgetForAccount{20}\\
\RecordFinalExemptionOrderBudgetToLabel
\end{document}
如您所见,该金额在制表环境中暂时扣除,但不计入“整体”计算。
答案1
链接中引用的代码A 是我写的。
在编写它时,我忽略了使用 zref-package 时,引入新属性的赋值(\zref@newprop
)是全局完成的(不限于当前范围),而设置属性值的赋值(\zref@setcurrent
)始终限于当前范围,该范围也可以是某些环境形成的局部范围。在下面的代码中,我添加了\zref@setcurrent
全局完成赋值的变体。
\documentclass{article}
\usepackage[parfill]{parskip}
\usepackage{zref}
\usepackage{siunitx}
\newcommand{\myHSpace}{25mm}
\makeatletter
\newcommand\mylabel[2]{%
\def\@currentlabel{#2}\phantomsection\label{mylabel:#1}{#2}}
\newcommand\myref[1]{%
\ref{mylabel:#1}}
\makeatother
\makeatletter
% !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
% A variant of \zref@setcurrent which sets properties globally
\ZREF@Robust\def\zref@setcurrentglobal#1#2{%
\zref@propexists{#1}{%
\expandafter\gdef\csname Z@C@#1\endcsname{#2}%
}%
}%
% !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
\ExplSyntaxOn
\cs_new_protected_nopar:Npn \DefineExemptionOrderBudget #1#2{%
\@bsphack
\exp_args:Nnf
\zref@newprop{ExemptionOrder#1}{\fp_to_decimal:n{(#2)}}
\@esphack
}%
\cs_new_protected_nopar:Npn \WithdrawFromExemptionOrderBudget #1#2 {%
\@bsphack
\exp_args:Nnf
\zref@setcurrentglobal{ExemptionOrder#1}{% <----\zref@setcurrentglobal instead of \zref@setcurrent
\fp_to_decimal:n{(\zref@getcurrent{ExemptionOrder#1})-(#2)}
}
\@esphack
}%
\cs_new_protected_nopar:Npn \GetCurrentExemptionOrderBudget #1 {%
\fp_to_decimal:n {(\zref@getcurrent{ExemptionOrder#1})}
}
\cs_new_protected_nopar:Npn \SetRemainingExemptionOrderBudgetToLabel #1#2 {%
\zref@labelbyprops{#2}{ExemptionOrder#1}
}
\cs_new_protected_nopar:Npn \ReferToOverallExemptionOrderBudgetLeft #1#2#3 {%
\zref@ifrefundefined{#2}
{\use_ii:nn}
{\zref@ifrefcontainsprop{#2}{ExemptionOrder#1}{\use_i:nn}{\use_ii:nn}}
{\PrintMoney{\zref@extractdefault{#2}{ExemptionOrder#1}{0}}{#3}}
{\zref@refused{#2}\textsf{??}}
}
\cs_new_protected_nopar:Npn \PrintMoney #1#2 {%
\exp_args:Nne
\use:n {\SI [{ add-decimal-zero,
add-integer-zero,
detect-mode=true,
round-mode=places,
round-half=up,
group-digits=true,
group-minimum-digits=2,
group-separator=\,,
output-decimal-marker={,},
round-precision={#2}}]}
{\fp_to_decimal:n{round(((#1)+0),#2,NaN)}}{€}
}
\DefineExemptionOrderBudget{ExemptionBudget}{1000}
\cs_new_protected_nopar:Npn \WithdrawFromExemptionOrderBudgetForAccount #1 {%
\WithdrawFromExemptionOrderBudget{ExemptionBudget}{#1}
Piece~price:\nobreakspace
\PrintMoney{#1}{2}\nobreakspace/~
Money~left~currently~\PrintMoney{\GetCurrentExemptionOrderBudget{ExemptionBudget}}{2}\nobreakspace/~
Money~left~overall~\ReferToOverallExemptionOrderBudgetLeft{ExemptionBudget}{overall}{2})
}
\cs_new_protected_nopar:Npn\RecordFinalExemptionOrderBudgetToLabel {%
\SetRemainingExemptionOrderBudgetToLabel{ExemptionBudget}{overall}
}
\ExplSyntaxOff
\makeatother
\begin{document}
Complete Budget: \PrintMoney{\GetCurrentExemptionOrderBudget{ExemptionBudget}}{2}\\
\WithdrawFromExemptionOrderBudgetForAccount{30}\\
\begin{tabbing}
\hspace{\myHSpace}\=\kill
Tabbing:\>\WithdrawFromExemptionOrderBudgetForAccount{50}\\
\end{tabbing}
\WithdrawFromExemptionOrderBudgetForAccount{20}\\
\RecordFinalExemptionOrderBudgetToLabel
\end{document}