
當在引文中引用作者的語言範例時,我喜歡使用特殊標籤來指定作者的姓名。 (我將其括在方括號中,但它不會出現在這裡,因為不相關。)
當引用多個範例和子範例時同一作者我希望能夠跳過這個特殊的非數字標籤,只保留數字。
\StrCut fromxstring
可以很好地移除作者姓名和編號之間的不可破壞的空格。
但是,當沒有分隔符號時,通常使用cleveref
\crefstripprefix 的解決方案將無法如預期般運作,請參閱 MWE。
此外,用 \StrCut 剝離到 level2/level3 分隔符號以獲得作者 1a.i--iiihyperref
有效,但如果載入則會產生嚴重錯誤。
讓我指出,我並不特別需要範圍,這些範圍已經使用 mwe 中所示的替代「調整」方法進行工作。
我只是希望在引用示例時能夠跳過作者姓名,這將為非範圍的多個參考文獻提供所需的靈活性,例如“作者 1a.ii,2b.i”。
編碼的所有學分可以在這裡找到: 交叉引用:更多子層級和預設
\documentclass{article}
\usepackage{philex} % Linguex wrapper. Awesome despite the "non-academic" coding.
\usepackage{xstring} % Provides the \StrCut command.
\usepackage{refcount} % Provides the \getrefbykeydefault command.
\usepackage{cleveref} % For ranges.
\setlength{\parskip}{1em}
\crefname{bpa}{}{} % Main Counter
\crefname{SubExNo}{}{} % Sublevel.
\crefname{SubSubExNo}{}{}
\newcommand{\dotstrip}[2]{\StrCut{#1}{.}{\onea}{\oneb}%
\StrCut{#2}{.}{\twoa}{\twob}%
\IfStrEq{\onea}{\twoa}{\twob}{#2}}
\newcommand{\spacestrip}[2]{\StrCut{#1}{~}{\onea}{\oneb}%
\StrCut{#2}{~}{\twoa}{\twob}%
\IfStrEq{\onea}{\twoa}{\twob}{#2}}
\crefrangelabelformat{bpa}{(#3#1#4--#5\spacestrip{#1}{#2}#6)} % Stripping to the non-brakable space, so that Author is not repeated.
\crefrangelabelformat{SubExNo}{(#3#1#4--#5\crefstripprefix{#1}{#2}#6)} % Usually outputs 1a--b but does not work here.
\crefrangelabelformat{SubSubExNo}{(#3#1#4--#5\dotstrip{#1}{#2}#6)} % Used with roman numbering, which confuses crefstripprefix. But you need a separator (a dot in this variant).
\begin{document}
% Philex Formatting
\phildashes{}{.} % Adds a dot between levels 2 and 3 in references.
\subformat{a}{}{.} % Level 2 is of the form “a.”
\subsubformat{i}{(}{)} % Level 3 is of the form “(i)”
\bpaformat{1}{Author~}{}
\lbpa{main1}{Example One.
\lba{sub11}{Subexample One-One.
\lba{subsub111}{Subsubexample One-One-One.}
\lbb{subsub112}{Subsubexample One-One-Two.}
\lbz{subsub113}{Subsubexample One-One-Three}}
\lbz{sub12}{Subexample One-Two.
\lba{subsub121}{Subsubexample One-Two-One.}
\lbz{subsub122}{Subsubexample One-Two-Two.}}}
\lbpa{main2}{Example Two.}
When quoting different examples, I do not want \textit{Author} to be repeated.
Works very nicely with xstring's StrCut for the 1st level...
\crefrange{main1}{main2}
... but the 3rd does not work if hypperref is loaded :
\textbackslash crefrange\{subsub111\}\{subsub113\} yields a critical error.
\vspace{6pt}
... and more importantly, level 2 does not work at all because \textbackslash crefstripprefix fails:
\textbackslash crefrange\{sub11\}\{sub12\} should output “Author 1a--b” but instead I get the following error :
“Improper alphabetic constant.”
\vspace{12pt}
Of course an alternative approach is to refer to “parts” so we can “cheat” and build the refs manually:
Philex already has \textbackslash rfx/rnx command to skip the main level.
Then we may define a new command to skip the first sublevel :
\makeatletter
\@ifdefinable\gobbletodot{\long\def\gobbletodot#1.{}}% refcount package
\newcommand\delbefdot[1]{%
\ifcat$\detokenize\expandafter{\gobbletodot#1.}$%
\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi
{#1}{\expandafter\delbefdot\expandafter{\gobbletodot#1}}%
}%
\@ifdefinable\rfxx{%
\DeclareRobustCommand\rfxx[1]{%
\IfRefUndefinedBabel{#1}{\refused{#1}\nfss@text{\reset@font\bfseries??}}%
{%
\@ifundefined{hyperref}{\@firstofone}{\hyperref[{#1}]}%
{%
(\expandafter\expandafter\expandafter\delbefdot
\expandafter\expandafter\expandafter{\getrefbykeydefault{#1}{}{??}})%
}%
}%
}%
}%
\@ifdefinable\rnxx{%
\DeclareRobustCommand\rnxx[1]{%
\IfRefUndefinedBabel{#1}{\refused{#1}\nfss@text{\reset@font\bfseries??}}%
{%
\@ifundefined{hyperref}{\@firstofone}{\hyperref[{#1}]}%
{%
\expandafter\expandafter\expandafter\delbefdot
\expandafter\expandafter\expandafter{\getrefbykeydefault{#1}{}{??}}%
}%
}%
}%
}%
\makeatother
\newcommand{\rfstrip}[2]{(\rn{#1}--\rnx{#2})}
\newcommand{\rfdoublestrip}[2]{(\rn{#1}--\rnxx{#2})}
\rfstrip{sub11}{sub12}
\rfdoublestrip{subsub111}{subsub113}
\vspace{6pt}
But we lose systematicity and besides, “Author 1a.i, 2b.” is also something I would like.
\end{document}
答案1
感謝@Ulrike Fischer 的舉例這裡關於如何使用輝煌包zref
,我提出了一個如何解決我自己在原帖中提出的問題的快速說明。
之後一切都會變得容易得多,正如您將看到的。
(當然, \zlabel 必須在任何包含後者的語言包中替換 \label ,這樣我們就不必手動添加它,但這很簡單。)
\documentclass{report}
\usepackage{zref-user}
\usepackage{philex}
\setlength{\parskip}{1em}
\makeatletter
\zref@newprop{exno}{\arabic{ExNo}}
\zref@newprop{subexno}{\alph{SubExNo}}
\zref@newprop{subsubexno}{\roman{SubSubExNo}}
\zref@newprop{authorstrip}{\bota{bpa}\alph{SubExNo}{\ifnum\theExDepth=3\roman{SubSubExNo}\fi}} % Here is the key line.
\zref@newprop{refstrip}{\ifnum\theExDepth=3\roman{SubSubExNo}\else\alph{SubExNo}\fi}
\zref@addprops{main}{exno,subexno,subsubexno,authorstrip,refstrip}
\makeatother
\newcommand{\authorstrip}[2]{(\zref{#1},\,\zref[authorstrip]{#2})}
\newcommand{\rfxx}[1]{(\zref[subsubexno]{#1})}
\newcommand{\rfstrip}[2]{(\zref{#1}--\zref[refstrip]{#2})}
\begin{document}
\phildashes{}{.}
\subformat{a}{}{.}
\bpaformat{1}{Author~}{}
\lbpa{main1}{Example One.\zlabel{mainex}
\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.}}}
\lbpa{main2}{Example Two.
\lba{sub21}{Subexample Two-One.}
\lbz{sub22}{Subexample Two-Two.}} \zlabel{sub22}
\vspace{6pt}
Results :
\rfxx{subsub113}
\rfstrip{subsub111}{subsub113}
\rfstrip{sub11}{sub12}
\authorstrip{subsub111}{sub22}
\end{document}
編輯:
若要單獨提取作者姓名變數(對應於命令的參數 3)\bpaformat
,只需在後者的定義中新增以下命令:
\gdef\theauthor{#3}
該命令\gdef
是從任何命令中提取任何參數的非常有效的方法。只要確保在定義中使用它,以便可以透過參數引用程式碼來存取該變數#n(在哪裡n是參數排名,從左到右計數)。