BibLaTeX:用作者年份样式的破折号替换多个作者

BibLaTeX:用作者年份样式的破折号替换多个作者

我正在尝试在 BibLaTeX 中复制参考书目样式。在原始样式中,重复的作者姓名应该用破折号替换,如下所示:

Sherlock Holmes (2016), ...

————/Watson, John (2017a), ...

————/———— (2017b), ...

然而,当前的输出看起来更像这样:

Sherlock Holmes (2016), ...

Sherlock Holmes/Watson, John (2017a), ...

——— (2017b), ...

编辑:正如评论中提到的,我能够暂时解决我的问题,这要感谢 moewe 针对另一个问题发布的解决方案。但是,如果条目之间有多个作者,我目前的调整(见下文)无法正确地“破折号化”作者姓名。是什么导致了这种情况,如何修复?再次提前感谢!

梅威瑟:

\documentclass[a4paper,12pt]{scrartcl}

\RequirePackage[english,ngerman]{babel}
\RequirePackage[T1]{fontenc} 
\RequirePackage[utf8]{inputenc} 
\RequirePackage{microtype} 
\RequirePackage[autostyle=true,german=guillemets]{csquotes} 

  \usepackage{filecontents}
  \usepackage[
    natbib=true,
    backend=biber,
    style=authoryear-comp,
    dashed=true,
    maxbibnames=99,
    maxcitenames=2,
    sorting=nyt,
    sortlocale=auto,
    isbn=false, 
    doi=false
  ]{biblatex}

\DeclareNameAlias{author}{last-first}  
\DeclareNameAlias{sortname}{last-first}
\DeclareFieldFormat{editortype}{\mkbibparens{#1}}
\renewcommand*{\newunitpunct}{\addcomma\space}
\renewcommand*{\compcitedelim}{\addsemicolon\space}
\DefineBibliographyStrings{ngerman}{andothers={et\addabbrvspace al\adddot}}      % et al. statt u.a. 
\DefineBibliographyStrings{ngerman}{%
  editor           = {Hg.},
  editors          = {Hg.},
}
\setlength{\bibitemsep}{1em} 
\setlength{\bibhang}{2em} 

\renewbibmacro{in:}{%
  \ifentrytype{article}{}{\printtext{\bibstring{in}\intitlepunct}
    \ifnameundef{bookauthor}
    {\ifnameundef{editor}
       {\printnames{translator}%
        \setunit{\addcomma\space}%
        \usebibmacro{translator+othersstrg}%
        \clearname{translator}}
       {\printnames{editor}%
        \setunit{\space}%
        {\usebibmacro{editor+othersstrg}}
        \clearname{editor}}}
    {\ifnamesequal{author}{bookauthor}
       {}
       {\printnames{bookauthor}%
        \clearname{bookauthor}}}%
  \newunit\newblock}
  }

\renewbibmacro*{volume+number+eid}{%
  \setunit*{\addcomma\space}
  \printfield[bold]{volume}%
  \setunit*{\addcomma\space}%
  \printfield{number}%
  \setunit{\addcomma\space}%
  \printfield{eid}}

\renewcommand*{\bibnamedash}{\textemdash\textemdash\textemdash}
\newcommand*{\multidashdelim}{\multinamedelim}
\newcommand*{\finaldashdelim}{\finalnamedelim}

\makeatletter
\newtoggle{bbx:goahead}
\newcounter{bbx:currnames}
\newcounter{bbx:lastnames}

\InitializeBibliographyStyle{\usebibmacro{dash:cleanup}{0}}

\newbibmacro*{bbx:printlist}[1]{%
  \setcounter{bbx:currnames}{0}% 
  \toggletrue{bbx:goahead}%
  \printnames[dashed:first-last]{#1}%
  \usebibmacro{dash:cleanup}{\value{bbx:currnames}+1}%
  \setcounter{bbx:lastnames}{\value{bbx:currnames}}}

\newbibmacro*{dash:delim}{%
\ifnumgreater{\value{listcount}}{\value{liststart}}
    {\ifboolexpr{
       test {\ifnumless{\value{listcount}}{\value{liststop}}}
       or
       test \ifmorenames
     }
       {\multidashdelim}
       {\finaldashdelim}}
    {}}

\DeclareNameFormat{dashed:first-last}{%
   \addtocounter{bbx:currnames}{1}%
   \iffieldequalcs{hash}{bbx@lastname@\the\value{listcount}}  
     {\usebibmacro{dash:delim}\bibnamedash}
     {\global\togglefalse{bbx:goahead}%
      \iffirstinits
        {\usebibmacro{name:family-given}
           {\namepartfamily}%
           {\namepartgiveni}%
           {\namepartprefix}%
           {\namepartsuffix}%
}
        {\usebibmacro{name:family-given}
           {\namepartfamily}%
           {\namepartgiven}%
           {\namepartprefix}%
           {\namepartsuffix}%
}
}%
  \csxdef{bbx@lastname@\the\value{listcount}}{\thefield{hash}}}

  \newbibmacro{dash:cleanup}[1]{%
  \ifnumgreater{\value{bbx:lastnames}}{#1}
    {\global\csundef{bbx@lastname@\the\value{bbx:lastnames}}%
     \addtocounter{bbx:lastnames}{-1}%
     \usebibmacro{dash:cleanup}{0}}
    {}}

\renewbibmacro*{author}{%
  \ifboolexpr{ test {\ifuseauthor}
               and not test {\ifnameundef{author}} }
{\usebibmacro{bbx:printlist}{author}%
\addspace\mkbibparens{\printfield{year}}}  
{\usebibmacro{dash:cleanup}{0}}}

\renewbibmacro*{bbx:editor}[1]{%
  \ifboolexpr{ test {\ifuseeditor}
               and not test {\ifnameundef{editor}} }
    {\usebibmacro{bbx:printlist}{editor}%
     \addspace%
     \usebibmacro{#1}%
     \clearname{editor}
     (\printfield{year})}
{\usebibmacro{dash:cleanup}{0}}}

\renewbibmacro*{bbx:translator}[1]{%
  \ifboolexpr{ test {\ifusetranslator}
               and not test {\ifnameundef{translator}} }
    {\usebibmacro{bbx:printlist}{translator}%
     \addspace%
     \usebibmacro{#1}%
     \clearname{translator}}
{\usebibmacro{dash:cleanup}{0}}} 
\makeatother

\renewcommand*{\nameyeardelim}{\addspace}
\renewcommand*{\compcitedelim}{\addcomma\addspace}
\AtBeginBibliography{%
  \renewcommand{\multinamedelim}{\addslash}%
  \renewcommand{\finalnamedelim}{\multinamedelim}}


\begin{filecontents}{sample.bib}
@article{schmitt_spatial_2013,
  title = {Spatial {{Interdependencies}} and {{Welfare State Generosity}} in {{Western Democracies}}, 1960–2000},
  volume = {23},
  langid = {english},
  number = {2},
  journaltitle = {Journal of European Social Policy},
  author = {Schmitt, Carina and Obinger, Herbert},
  date = {2013-05-01},
  pages = {119--133},
}

@article{schmitt_explaining_2011,
  title = {Explaining {{Convergence}} of {{OECD Welfare States}}: {{A Conditional Approach}}},
  volume = {21},
  langid = {english},
  number = {2},
  journaltitle = {Journal of European Social Policy},
  author = {Schmitt, Carina and Starke, Peter},
  date = {2011-05-01},
  pages = {120--135},
}

@article{schmitt_global_2015,
  title = {The {{Global Emergence}} of {{Social Protection}}: {{Explaining Social Security Legislation}} 1820–2013},
  volume = {43},
  langid = {english},
  number = {4},
  journaltitle = {Politics \& Society},
  author = {Schmitt, Carina and Lierse, Hanna and Obinger, Herbert and Seelkopf, Laura},
  date = {2015-12-01},
  pages = {503--524},
}

@article{rothgang_social_2010,
  title = {Social {{Insurance}} for {{Long}}-Term {{Care}}: {{An Evaluation}} of the {{German Model}}},
  volume = {44},
  timestamp = {2017-02-09T20:38:03Z},
  langid = {english},
  number = {4},
  journaltitle = {Social Policy \& Administration},
  author = {Rothgang, Heinz},
  date = {2010-08-01},
  pages = {436--460},
}

@article{rothgang_solidaritat_2011,
  title = {Solidarität in der Pflegeversicherung: Das Verhältnis von Sozialer Pflegeversicherung und Privater Pflegepflichtversicherung},
  volume = {60},
  langid = {german},
  issue = {4–5},
  journaltitle = {Sozialer Fortschritt},
  author = {Rothgang, Heinz},
  date = {2011-04},
  pages = {81--87},
}

@article{pickard_modelling_2007,
  title = {Modelling an Entitlement to Long-Term Care Services for Older People in                 {{Europe}}: Projections for Long-Term Care Expenditure to 2050},
  volume = {17},
  langid = {english},
  number = {1},
  journaltitle = {Journal of European Social Policy},
  author = {Pickard, Linda and Comas-Herrera, Adelina and Costa-Font, Joan and Gori, Cristiano and di Maio, Alessandra and Patxot, Concepció and Pozzi, Alessandro and Rothgang, Heinz and Wittenberg, Raphael},
  date = {2007-02-01},
  pages = {33--48},
  options = {useprefix=true},
}

\end{filecontents}

  \addbibresource{sample.bib}

\begin{document}

Happy Valentine's Day. 

\nocite{*}

\printbibliography

\end{document}

答案1

我以前的回答中的代码Biblatex/Biber 将每个作者的作者姓名替换为破折号包含一个错误,导致清理程序总是删除所有名称,正确的代码是

\newbibmacro{dash:cleanup}[1]{%
  \ifnumgreater{\value{bbx:lastnames}}{#1}
    {\global\csundef{bbx@lastname@\the\value{bbx:lastnames}}%
     \addtocounter{bbx:lastnames}{-1}%
     \usebibmacro{dash:cleanup}{#1}}
    {}}

请注意;#1那里\usebibmacro{dash:cleanup}{#1}有一个错误的代码0

我对您的代码做了一些其他修改。最重要的是author,对editortranslator宏进行了修改。您可以在下面的 MWE 中查看它们

\documentclass[a4paper,12pt]{scrartcl}

\RequirePackage[english,ngerman]{babel}
\RequirePackage[T1]{fontenc} 
\RequirePackage[utf8]{inputenc} 
\RequirePackage{microtype} 
\RequirePackage[autostyle=true,german=guillemets]{csquotes} 

  \usepackage{filecontents}
  \usepackage[
    natbib=true,
    backend=biber,
    style=authoryear-comp,
    dashed=true,
    maxbibnames=99,
    maxcitenames=2,
    sorting=nyt,
    sortlocale=auto,
    isbn=false, 
    doi=false
  ]{biblatex}

\DeclareNameAlias{author}{last-first}  
\DeclareNameAlias{sortname}{last-first}
\DeclareFieldFormat{editortype}{\mkbibparens{#1}}
\renewcommand*{\newunitpunct}{\addcomma\space}
\renewcommand*{\compcitedelim}{\addsemicolon\space}
\DefineBibliographyStrings{ngerman}{andothers={et\addabbrvspace al\adddot}}      % et al. statt u.a. 
\DefineBibliographyStrings{ngerman}{%
  editor           = {Hg.},
  editors          = {Hg.},
}
\setlength{\bibitemsep}{1em} 
\setlength{\bibhang}{2em} 

\renewbibmacro{in:}{%
  \ifentrytype{article}{}{\printtext{\bibstring{in}\intitlepunct}
    \ifnameundef{bookauthor}
    {\ifnameundef{editor}
       {\printnames{translator}%
        \setunit{\addcomma\space}%
        \usebibmacro{translator+othersstrg}%
        \clearname{translator}}
       {\printnames{editor}%
        \setunit{\space}%
        {\usebibmacro{editor+othersstrg}}
        \clearname{editor}}}
    {\ifnamesequal{author}{bookauthor}
       {}
       {\printnames{bookauthor}%
        \clearname{bookauthor}}}%
  \newunit\newblock}
  }

\renewbibmacro*{volume+number+eid}{%
  \setunit*{\addcomma\space}
  \printfield[bold]{volume}%
  \setunit*{\addcomma\space}%
  \printfield{number}%
  \setunit{\addcomma\space}%
  \printfield{eid}}

\renewcommand*{\bibnamedash}{\textemdash\textemdash\textemdash}
\newcommand*{\multidashdelim}{\multinamedelim}
\newcommand*{\finaldashdelim}{\finalnamedelim}

\makeatletter
\newtoggle{bbx:goahead}
\newcounter{bbx:currnames}
\newcounter{bbx:lastnames}

\InitializeBibliographyStyle{\usebibmacro{dash:cleanup}{0}}

\newbibmacro*{bbx:printlist}[1]{%
  \setcounter{bbx:currnames}{0}% 
  \toggletrue{bbx:goahead}%
  \printnames[dashed:given-family]{#1}%
  \usebibmacro{dash:cleanup}{\value{bbx:currnames}+1}%
  \setcounter{bbx:lastnames}{\value{bbx:currnames}}}

\newbibmacro*{dash:delim}{%
  \ifnumgreater{\value{listcount}}{\value{liststart}}
    {\ifboolexpr{
       test {\ifnumless{\value{listcount}}{\value{liststop}}}
       or
       test \ifmorenames
     }
       {\multidashdelim}
       {\finaldashdelim}}
    {}}

\DeclareNameFormat{dashed:given-family}{%
  \addtocounter{bbx:currnames}{1}%
   \ifboolexpr{togl {bbx:goahead} and not test \iffirstonpage
               and test {\iffieldequalcs{hash}{bbx@lastname@\the\value{listcount}}}}
    {\usebibmacro{dash:delim}\bibnamedash}
    {\global\togglefalse{bbx:goahead}%
     \ifgiveninits
       {\usebibmacro{name:family-given}
          {\namepartfamily}%
          {\namepartgiveni}%
          {\namepartprefix}%
          {\namepartsuffix}}
       {\usebibmacro{name:family-given}
          {\namepartfamily}%
          {\namepartgiven}%
          {\namepartprefix}%
          {\namepartsuffix}}}%
  \csxdef{bbx@lastname@\the\value{listcount}}{\thefield{hash}}}

\newbibmacro{dash:cleanup}[1]{%
  \ifnumgreater{\value{bbx:lastnames}}{#1}
    {\global\csundef{bbx@lastname@\the\value{bbx:lastnames}}%
     \addtocounter{bbx:lastnames}{-1}%
     \usebibmacro{dash:cleanup}{#1}}
    {}}

\renewbibmacro*{author}{%
  \ifboolexpr{
    test \ifuseauthor
    and
    not test {\ifnameundef{author}}
  }
    {\usebibmacro{bbx:printlist}{author}%
     \iffieldundef{authortype}
       {}
       {\usebibmacro{authorstrg}}%
     \setunit{\printdelim{nameyeardelim}}}%
    {\usebibmacro{dash:cleanup}{0}%
     \usebibmacro{labeltitle}%
     \setunit*{\printdelim{nonameyeardelim}}}%
  \usebibmacro{date+extrayear}}

\renewbibmacro*{bbx:editor}[1]{%
  \ifboolexpr{
    test \ifuseeditor
    and
    not test {\ifnameundef{editor}}
  }
    {\usebibmacro{bbx:printlist}{editor}%
     \setunit{\addspace}%
     \usebibmacro{#1}%
     \clearname{editor}%
     \setunit{\printdelim{nameyeardelim}}}%
    {\usebibmacro{dash:cleanup}{0}%
     \usebibmacro{labeltitle}%
     \setunit*{\printdelim{nonameyeardelim}}}%
  \usebibmacro{date+extrayear}}


\renewbibmacro*{bbx:translator}[1]{%
  \ifboolexpr{
    test \ifusetranslator
    and
    not test {\ifnameundef{translator}}
  }
    {\usebibmacro{bbx:printlist}{translator}%
     \setunit{\addspace}%
     \usebibmacro{#1}%
     \clearname{translator}%
     \setunit{\printdelim{nameyeardelim}}}%
    {\usebibmacro{dash:cleanup}{0}%
     \usebibmacro{labeltitle}%
     \setunit*{\printdelim{nonameyeardelim}}}%
  \usebibmacro{date+extrayear}}
\makeatother

\renewcommand*{\nameyeardelim}{\addspace}
\renewcommand*{\compcitedelim}{\addcomma\addspace}
\AtBeginBibliography{%
  \renewcommand{\multinamedelim}{\addslash}%
  \renewcommand{\finalnamedelim}{\multinamedelim}}


\begin{filecontents}{sample.bib}
@article{schmitt_spatial_2013,
  title = {Spatial {{Interdependencies}} and {{Welfare State Generosity}} in {{Western Democracies}}, 1960–2000},
  volume = {23},
  langid = {english},
  number = {2},
  journaltitle = {Journal of European Social Policy},
  author = {Schmitt, Carina and Obinger, Herbert},
  date = {2013-05-01},
  pages = {119--133},
}

@article{schmitt_explaining_2011,
  title = {Explaining {{Convergence}} of {{OECD Welfare States}}: {{A Conditional Approach}}},
  volume = {21},
  langid = {english},
  number = {2},
  journaltitle = {Journal of European Social Policy},
  author = {Schmitt, Carina and Starke, Peter},
  date = {2011-05-01},
  pages = {120--135},
}

@article{schmitt_global_2015,
  title = {The {{Global Emergence}} of {{Social Protection}}: {{Explaining Social Security Legislation}} 1820–2013},
  volume = {43},
  langid = {english},
  number = {4},
  journaltitle = {Politics \& Society},
  author = {Schmitt, Carina and Lierse, Hanna and Obinger, Herbert and Seelkopf, Laura},
  date = {2015-12-01},
  pages = {503--524},
}

@article{rothgang_social_2010,
  title = {Social {{Insurance}} for {{Long}}-Term {{Care}}: {{An Evaluation}} of the {{German Model}}},
  volume = {44},
  timestamp = {2017-02-09T20:38:03Z},
  langid = {english},
  number = {4},
  journaltitle = {Social Policy \& Administration},
  author = {Rothgang, Heinz},
  date = {2010-08-01},
  pages = {436--460},
}

@article{rothgang_solidaritat_2011,
  title = {Solidarität in der Pflegeversicherung: Das Verhältnis von Sozialer Pflegeversicherung und Privater Pflegepflichtversicherung},
  volume = {60},
  langid = {german},
  issue = {4–5},
  journaltitle = {Sozialer Fortschritt},
  author = {Rothgang, Heinz},
  date = {2011-04},
  pages = {81--87},
}

@article{pickard_modelling_2007,
  title = {Modelling an Entitlement to Long-Term Care Services for Older People in                 {{Europe}}: Projections for Long-Term Care Expenditure to 2050},
  volume = {17},
  langid = {english},
  number = {1},
  journaltitle = {Journal of European Social Policy},
  author = {Pickard, Linda and Comas-Herrera, Adelina and Costa-Font, Joan and Gori, Cristiano and di Maio, Alessandra and Patxot, Concepció and Pozzi, Alessandro and Rothgang, Heinz and Wittenberg, Raphael},
  date = {2007-02-01},
  pages = {33--48},
  options = {useprefix=true},
}

\end{filecontents}

\addbibresource{sample.bib}

\begin{document}
Happy Valentine's Day. 

\nocite{*}
\printbibliography
\end{document}

相关内容