我想使用zref
\clevestrip{ref1}{ref2} 范围定义一个巧妙的交叉引用命令,如果 ref1 和 ref2 的 ExNo 相等,则返回“剥离”字符串 (1ab),否则仅打印 ref1ref2。
但肯定是扩展性出了问题,因为它不起作用。谁能告诉我为什么……
已编辑 @Ulrike 告诉我使用 \zref@extract 因为 \zref 不可扩展,而且它的效果非常好。
MAWE(即将开始工作……)
\documentclass{report}
\usepackage{zref-user}
\usepackage{philex}
\setlength{\parskip}{1em}
\makeatletter
\zref@newprop{exno}{\arabic{ExNo}}
\zref@newprop{theexno}{\theExNo}
\zref@newprop{subexno}{\alph{SubExNo}}
\zref@newprop{thesubexno}{\theSubExNo}
\zref@newprop{subsubexno}{\roman{SubSubExNo}}
\zref@newprop{refskip}{\ifnum\theExDepth=3\roman{SubSubExNo}\else\alph{SubExNo}\fi}
\zref@addprops{main}{exno,subexno,subsubexno,theexno,thesubexno,refskip}
\makeatother
\newcommand{\refstrip}[2]{(\zref{#1}--\zref[refskip]{#2})}
\begin{document}
\phildashes{}{.}
\subformat{a}{}{.}
\lb{main1}{Example One.\zlabel{main1}
\lba{sub11}{Subexample One-One.\zlabel{sub11}
\lba{subsub111}{Subsubexample One-One-One.\zlabel{subsub111}}
\lbb{subsub112}{Subsubexample One-One-Two.}
\lbz{subsub113}{Subsubexample One-One-Three.\zlabel{subsub113}}}
\lbz{sub12}{Subexample One-Two.\zlabel{sub12}
\lba{subsub121}{Subsubexample One-Two-One.}
\lbz{subsub122}{Subsubexample One-Two-Two.}}}
\lb{main2}{Example Two. \zlabel{main2}
\lba{sub21}{Subexample Two-One.}
\lbz{sub22}{Subexample Two-Two.}} \zlabel{sub22}
\refstrip{sub11}{sub12}
\refstrip{subsub111}{subsub113}
\makeatletter
\newcommand{\clevestrip}[2]{%
\ifnum\zref@extract{#1}{theexno}=\zref@extract{#2}{theexno}\refstrip{#1}{#2}\else\zref{#1}\zref{#2}\fi} % Using the expandable version (thanks to Ulrike Fischer)
\makeatother
\clevestrip{sub11}{sub12} % ERROR
\end{document}
答案1
随着时间的推移,我学到的一件事就是始终遵循@UlrikeFischer 的建议。由于她建议你看看zref-clever
另一个问题(这让我很开心 :-),我认为你应该这样做。事实上,zref-clever
的endrange
选项似乎特别适合解决你试图解决的问题。
该endrange
选项可以接收多个预定义值,例如stripprefix
、 或pagecomp
,在这种情况下,它会调用处理函数来构建范围的结束部分。但它也可以接收属性zref
( 的优点zref
),在这种情况下,您可以按照自己想要的方式构建范围的结束部分。而且,如果使用属性,则zref
无需以任何方式处理引用,因此您无需猜测它将采用的形式,也无需添加“标记”以便能够在正确的点将其拆分。
(我一点也不知道philex
,linguex
我希望我没有屠杀他们......)
\documentclass{report}
\usepackage{philex}
\usepackage{zref-clever}
\zcsetup{
countertype={
ExNo=example, % I'm assuming this is what "ExNo" means
SubExNo=example,
SubSubExNo=example,
},
counterresetby={
SubExNo=ExNo,
SubSubExNo=SubExNo,
},
}
\ExplSyntaxOn
\makeatletter
\zref@newprop{refskip}
{
\int_compare:nNnTF { \value{ExDepth} } = { 3 }
{ \roman{SubSubExNo} }
{ \alph{SubExNo} }
}
\zref@addprop{main}{refskip}
\makeatother
\ExplSyntaxOff
\zcRefTypeSetup{example}{
endrange=refskip,
rangesep={--},
rangetopair=false,
}
\usepackage{hyperref}
\setlength{\parskip}{1em}
\begin{document}
\phildashes{}{.}
\subformat{a}{}{.}
\lb{main1}{Example One.\zlabel{main1}
\lba{sub11}{Subexample One-One.\zlabel{sub11}
\lba{subsub111}{Subsubexample One-One-One.\zlabel{subsub111}}
\lbb{subsub112}{Subsubexample One-One-Two.\zlabel{subsub112}}
\lbz{subsub113}{Subsubexample One-One-Three.\zlabel{subsub113}}}
\lbz{sub12}{Subexample One-Two.\zlabel{sub12}
\lba{subsub121}{Subsubexample One-Two-One.}
\lbz{subsub122}{Subsubexample One-Two-Two.}}}
\lb{main2}{Example Two. \zlabel{main2}
\lba{sub21}{Subexample Two-One.}
\lbz{sub22}{Subexample Two-Two.\zlabel{sub22}}}
\zcref[range]{sub11,sub12}
\zcref[range]{subsub111,subsub113}
\zcref{subsub111,subsub112,subsub113}
\zcref[range]{sub11,sub22}
\end{document}