選項卡環境內的交叉引用和浮點計算

選項卡環境內的交叉引用和浮點計算

基於此/A

我遇到的問題是我的交叉引用和相應的計算似乎無法在\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}

在此輸入影像描述

相關內容