
Ao citar exemplos linguísticos de autores dentro de uma citação, gosto de usar uma etiqueta especial especificando o nome do autor. (Eu o coloco entre colchetes, mas não aparecerá aqui porque é irrelevante.)
Ao se referir a vários exemplos e subexemplosdo mesmo autorQuero poder pular esse rótulo especial não numérico e manter apenas o número.
\StrCut from xstring
funciona muito bem para remover o espaço inquebrável que fica entre o nome do autor e o número.
No entanto, quando não há delimitador, a solução usual com cleveref
, \crefstripprefix, não funciona conforme o esperado, consulte MWE.
Além disso, removendo para o delimitador level2/level3 com \StrCut para obterAutor 1a.i--iiifunciona, mas gera um erro crítico se hyperref
for carregado.
Deixe-me salientar que não preciso especificamente de intervalos, que já estão funcionando usando uma abordagem alternativa de "ajustes", conforme mostrado no mwe.
Eu só quero poder pular o Nome do Autor ao me referir ao exemplo, isso permitiria a flexibilidade necessária para múltiplas referências que não são intervalos, como "Autor 1a.ii, 2b.i".
Todos os créditos pela codificação podem ser encontrados aqui: Referência cruzada: mais subníveis e predefinições
\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}
Responder1
Graças ao exemplo de @Ulrike Fischeraquisobre como usar o pacote brilhante zref
, apresento uma rápida ilustração de como resolver o problema levantado por mim no post original.
Tudo fica muito mais fácil depois disso, como você verá.
(É claro que \zlabel terá que substituir \label em todos os lugares de qualquer pacote linguístico que inclua o último, para que não tenhamos que adicioná-lo manualmente, mas isso é trivial.)
\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}
Editar:
Para extrair apenas a variável Nome do Autor, que corresponde ao Argumento 3 do comando \bpaformat
, basta adicionar dentro da definição deste último o seguinte comando:
\gdef\theauthor{#3}
O comando \gdef
é uma forma muito eficaz de extrair qualquer argumento de qualquer comando. Apenas certifique-se de utilizá-la dentro da definição, para que a variável possa ser acessível, por meio do código de referência de argumento #n(ondené a classificação do argumento, contando da esquerda para a direita).