
인용문 안에 저자의 언어적 예를 인용할 때 나는 저자의 이름을 명시하는 특별한 라벨을 사용하는 것을 좋아합니다. (대괄호로 묶었지만 관련성이 없으므로 여기에 표시되지 않습니다.)
여러 예시와 하위 예시를 참고할 때같은 작가의숫자가 아닌 특별한 라벨을 건너뛰고 숫자만 유지하고 싶습니다.
\StrCut from xstring
은 작성자 이름과 번호 사이에 있는 깨지지 않는 공간을 잘 제거합니다.
그러나 구분 기호가 없으면 cleveref
\crefstripprefix를 사용하는 일반적인 솔루션이 의도한 대로 작동하지 않습니다. MWE를 참조하세요.
게다가 \StrCut을 사용하여 level2/level3 구분 기호를 제거하면저자 1a.i--iiihyperref
작동하지만 로드 되면 심각한 오류가 발생합니다 .
mwe에 표시된 대로 대체 "조정" 접근 방식을 사용하여 이미 작동하고 있는 범위가 특별히 필요하지 않다는 점을 지적하겠습니다.
예제를 참조할 때 작성자 이름을 건너뛸 수 있기를 원합니다. 그러면 "Author 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왼쪽에서 오른쪽으로 계산되는 인수 순위입니다.