참고문헌 항목의 저자 수 계산

참고문헌 항목의 저자 수 계산

특정 bib 항목의 작성자 수를 알려주는 명령을 갖고 싶습니다. 지금까지 내가 성공적으로 시도한 것은 키-값 저장소(prop)를 생성하고 bbl 가져오기 메커니즘을 연결하고 작성자 카운터에 있어야 하는 작성자 수를 저장하는 것이었습니다.

\documentclass{article}

\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
    @book{key,
        author = {John Doe and Mike Smith},
        year = {2001},
        title = {Title},
        publisher = {Publisher},
    }
    @book{key2,
        author = {John Doe},
        year = {2002},
        title = {Title2},
        publisher = {Publisher2},
    }
\end{filecontents}

\usepackage{biblatex}
\addbibresource{\jobname.bib}

\usepackage{expl3}
\ExplSyntaxOn
\prop_new:N \g_my_author_count
\cs_new_protected:Npn \storecount#1#2{%
    \prop_gput:Nnn \g_my_author_count{#1}{#2}%
}
\cs_new:Npn \getcount#1{%
    \prop_item:Nn \g_my_author_count{#1}%
}
\ExplSyntaxOff

\newcounter{authorcount}
\setcounter{authorcount}{0}

\AtDataInput{%
    \storecount{\strfield{entrykey}}{\value{author}}%
    % debug stuff begin
        \storecount{fakekey}{123}%
        \addtocounter{authorcount}{\value{author}}%
        \global\edef\entrykey{\strfield{entrykey}}%
    % debug stuff end
}

% make sure it's defined
\makeatletter
\@ifundefined{entrykey}{\edef\entrykey{\empty}}{}
\makeatother

\begin{document}
    % debug stuff begin
        % expect 3
        \arabic{authorcount} % got 3 => hook & counter work

        % expect key or key2
        \entrykey % got key => \strfield{entrykey} works

        % expect [?] - 123
        [?] - \getcount{fakekey}    % got [?] - 123
                                    % => storage works
    % debug stuff end

    % expect [2] - 2
    \cite{key} - \getcount{key} % got [2] - 

    % expect [1] - 1
    \cite{key2} - \getcount{key2} % got [1] -   

    \printbibliography

\end{document}

여기에 이미지 설명을 입력하세요

내가 무엇을 놓치고 있나요?

답변1

author항목이 처리될 때 정보가 카운터에 존재하므로 \cite...-like 명령을 사용하여 번호를 직접 검색할 수 있습니다. 우회 경유 \AtDataInput가 필요하지 않습니다.

biblatex의 명령은 강력하기 때문에 \cite확장 가능한 방식으로 작성자 수를 반환하지 않습니다. 필요한 경우 실제로 진행 \AtDataInput하거나 \cite유사한 명령을 사용하여 관련 카운터를 도우미 매크로에 저장하는 것이 더 쉬울 수 있습니다. 무엇이 더 합리적인지는 사용 사례에 따라 다릅니다.

\documentclass{article}

\usepackage{biblatex}
\addbibresource{biblatex-examples.bib}

\DeclareCiteCommand{\citeauthorcount}
  {\boolfalse{citetracker}%
   \boolfalse{pagetracker}%
   \usebibmacro{prenote}}
  {\printtext{The entry}%
   \setunit{\addspace}%
   \printfield{entrykey}%
   \setunit{\addspace}%
   \printtext{has \arabic{author} author(s)}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\begin{document}
\citeauthorcount{sigfridsson,worman}
\printbibliography
\end{document}

sigfridsson 항목에는 작성자가 2명 있고, worman 항목에는 작성자가 1명 있습니다.


내가 올바르게 이해했다면 솔루션의 주요 문제 expl3는 확장과 누락된 \the. MWE는 n-type 인수를 사용하므로 카운터 값을 저장하지 않고 내부 표현을 저장합니다. \strfield{entrykey}버전 n은 저장만 \strfield{entrykey}하지만 x버전은 이것을 확장하여 및 를 sigfridsson씁니다 worman. 다음 구현이 작동합니다.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{biblatex}

\usepackage{expl3}
\usepackage{xparse}

\ExplSyntaxOn

\prop_new:N \g_vh_author_count

\cs_new_protected:Npn \vh_store_author_count:nn #1#2
{
  \prop_gput:Nnn \g_vh_author_count {#1} {#2}
}
\cs_generate_variant:Nn \vh_store_author_count:nn {xx}

\cs_new:Npn \vh_get_author_count:n #1
{
  \prop_item:Nn \g_vh_author_count {#1}
}

\NewExpandableDocumentCommand \getauthorcount {m} {
  \vh_get_author_count:n { #1 }
}

\AtDataInput{%
  \vh_store_author_count:xx {\strfield{entrykey}}{\the\value{author}}%
}
\ExplSyntaxOff

\addbibresource{biblatex-examples.bib}

\begin{document}
  \cite{sigfridsson} - \getauthorcount{sigfridsson}

  \cite{worman} - \getauthorcount{worman}

  \edef\foo{\getauthorcount{worman}} \meaning\foo

  \edef\foo{\getauthorcount{sigfridsson}} \meaning\foo

  \printbibliography
\end{document}

[1] - 2

[2] - 1

매크로:->1

매크로:->2

관련 정보