经过几个小时,我仍然无法生成一个简单的pagebreak
计数器是否成功测试等于 ConTeXt 中的常数。
\definenumber[eintraege][way=bytext,prefix=no]
\setnumber[eintraege][1]
\definenumber[horst][way=bytext,prefix=no]
\setnumber[horst][3]
\starttext
\dorecurse{20}{
Einträge: \getnumber[eintraege]\hfill Horst: \getnumber[horst]\\
%\doif{\getnumber[eintraege]}{\getnumber[horst]}{\pagebreak}
%\doif{\getnumber[eintraege]}{horst}{\pagebreak}
%\doif{eintraege}{horst}{\pagebreak}
%\doif{\getnumber[eintraege]}{3}{\pagebreak}
\doif{\getnumber[eintraege]}{\getnumber[eintraege]}{\pagebreak}
\incrementnumber[eintraege]
}
\stoptext
所有注释掉的版本都不会产生pagebreak
计数器等于其自身的简单情况。这里出了什么问题?
答案1
您必须使用命令\rawcountervalue
来访问计数器的数值,而不是打印计数器的格式化表示\convertedcounter
(或旧名称)。\getnumber
\definecounter[eintraege][way=bytext,prefix=no]
\setcounter[eintraege][1]
\definecounter[horst][way=bytext,prefix=no]
\setcounter[horst][3]
\starttext
\dorecurse{20}
{Einträge: \convertedcounter[eintraege]\hfill Horst: \convertedcounter[horst]\par
%\ifnum\rawcountervalue[eintraege]=\rawcountervalue[horst]\relax\page\fi
\doif{\rawcountervalue[eintraege]}{\rawcountervalue[horst]}{\page}%
\incrementcounter[eintraege]}
\stoptext
以下示例演示了\rawcountervalue
和\convertedcounter
命令之间的区别。使用\convertedcounter
命令时,ConTeXt 会在输出中应用计数器每个级别的转换,并且在启用它时还会显示数字的前缀。\rawcountervalue
另一边的命令仅显示请求的计数器级别的数值,您可以将它与 TeX 的数字命令一起使用,例如\ifnum
。
\defineconversionset[testcounter][n,a,r][n]
\definecounter
[testcounter]
[prefix=yes,
prefixsegments=section,
numberconversionset=testcounter,
prefixconnector=–]
\starttext
\section{Section 1}
\incrementcounter[testcounter]
\incrementcounter[testcounter][2]
\incrementcounter[testcounter][2]
\incrementcounter[testcounter][3]
\starttabulate[|l|l|l|]
\NC \bf Level \NC \bf Converted counter \NC \bf Raw counter \NC\NR
\NC 1 \NC \convertedcounter[testcounter][numbersegments=1:1] \NC \rawcountervalue [testcounter] \NC\NR
\NC 2 \NC \convertedcounter[testcounter][numbersegments=1:2] \NC \rawsubcountervalue[testcounter][2] \NC\NR
\NC 3 \NC \convertedcounter[testcounter][numbersegments=1:3] \NC \rawsubcountervalue[testcounter][3] \NC\NR
\stoptabulate
\section{Section 2}
\incrementcounter[testcounter]
\incrementcounter[testcounter][2]
\incrementcounter[testcounter][3]
\incrementcounter[testcounter][3]
\starttabulate[|l|l|l|]
\NC \bf Level \NC \bf Converted counter \NC \bf Raw counter \NC\NR
\NC 1 \NC \convertedcounter[testcounter][numbersegments=1:1] \NC \rawcountervalue [testcounter] \NC\NR
\NC 2 \NC \convertedcounter[testcounter][numbersegments=1:2] \NC \rawsubcountervalue[testcounter][2] \NC\NR
\NC 3 \NC \convertedcounter[testcounter][numbersegments=1:3] \NC \rawsubcountervalue[testcounter][3] \NC\NR
\stoptabulate
\stoptext