如何获取 biblatex-apa 的在线源代码修改版

如何获取 biblatex-apa 的在线源代码修改版

我使用 biblatex-apa 来引用和参考书目。不幸的是,我需要一种特殊的方法来处理参考书目中的在线资源。

我得到的是: 我得到了什么

我想要的是: 我想要的是

如果有人能指出我需要改变什么,我会很高兴。

我的 MWE(尝试一下):

\documentclass[ngerman, toc=listof, toc=bibliography, footnotes=multiple, numbers=noendperiod]{scrartcl}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}
\usepackage[
backend=biber,
autocite=inline, 
style=apa,
%citestyle=authortitle-icomp,
sortlocale=de_DE,
natbib=true,
isbn=false,
url=false, 
doi=false,
eprint=false,
dashed=false,
pagetracker, 
ibidtracker=constrict
]{biblatex}
\addbibresource{biblatex-examples.bib}
\DeclareNameAlias{sortname}{family-given}
\DeclareNameAlias{default}{given-family}
\renewcommand*{\newunitpunct}{\addcomma\space}
\renewcommand*{\subtitlepunct}{\addperiod\space}

\DeclareDelimFormat{multinamedelim}{\addslash\space}
\DeclareDelimAlias{finalnamedelim}{multinamedelim}

\renewbibmacro*{url+urldate}{%
    \ifthenelse{\iffieldundef{url}\OR\NOT\iffieldundef{doi}}
    {}
    {\iffieldundef{urlyear}
        {}
        {\bibstring{retrieved}%
            \setunit{\addspace}%
            \printtext{\bibstring{from}}%
            \setunit{\addspace}}%
        \iffieldundef{url}{}{\printfield{url}\renewcommand*{\finentrypunct}{\relax}}
        \setunit*{\addspace}%
        \printurldate
        \setunit{\urldatecomma}%
}}

\makeatletter
\newbool{cbx:loccit}

\DeclareBibliographyOption[boolean]{ibidpage}[true]{%
    \ifstrequal{#1}{true}
    {\ExecuteBibliographyOptions{loccittracker=constrict}}
    {\ExecuteBibliographyOptions{loccittracker=false}}}

\providecommand*{\mkibid}[1]{#1}

\newbibmacro*{cite:ibid}{%
    \printtext[bibhyperref]{\bibstring[\mkibid]{ibidem}}%
    \ifloccit
    {\global\booltrue{cbx:loccit}}
    {}}


\renewbibmacro*{cite}{%
    \global\boolfalse{cbx:loccit}%
    \ifthenelse{\ifciteibid\AND\NOT\iffirstonpage}
    {\usebibmacro{cite:ibid}}
    {\iffieldequals{fullhash}{\cbx@lasthash}
        % Multiple cites in one command
        {\setunit{\compcitedelim}%
            \usebibmacro{cite:plabelyear+extradate}}%
        % Single cite
        {\ifnameundef{labelname}
            % No author/editor
            {\usebibmacro{cite:noname}%
                \setunit{\printdelim{nameyeardelim}}%
                \usebibmacro{cite:plabelyear+extradate}%
                \savefield{fullhash}{\cbx@lasthash}}
            % Normal cite
            {\ifnameundef{shortauthor}
                {\printnames{labelname}}%
                {\cbx@apa@ifnamesaved
                    {\printnames{shortauthor}}
                    {\ifnameundef{groupauthor}
                        {\printnames[labelname]{author}}
                        {\printnames[labelname]{groupauthor}}%
                        \addspace\printnames[sabrackets]{shortauthor}}}%
                \setunit{\printdelim{nameyeardelim}}%
                \usebibmacro{cite:plabelyear+extradate}%
                \savefield{fullhash}{\cbx@lasthash}}}%
        \setunit{\multicitedelim}}}

\renewbibmacro*{textcite}{%
    \global\boolfalse{cbx:loccit}%
    \iffieldequals{fullhash}{\cbx@lasthash}
    % Compact cite - more than one thing for same author
    {\setunit{\compcitedelim}%
        \usebibmacro{cite:plabelyear+extradate}}
    % New cite
    {\ifbool{cbx:parens}
        {\bibcloseparen\global\boolfalse{cbx:parens}}
        {}%
        \setunit{\textcitedelim}%
        \ifnameundef{labelname}
        % No author/editor
        {\iffieldundef{shorthand}%
            % Cite using title
            {\usebibmacro{cite:noname}%
                \setunit{\global\booltrue{cbx:parens}\addspace\bibopenparen}%
                \usebibmacro{cite:plabelyear+extradate}}
            % Cite using shorthand
            {\usebibmacro{cite:shorthand}}}
        % Normal cite with author/editor
        % Normal full cite
        {\ifnameundef{shortauthor}%
            % Normal full cite
            {\printnames{labelname}}
            % Cite using short author
            {\cbx@apa@ifnamesaved
                {\printnames{shortauthor}}
                {\ifnameundef{groupauthor}
                    {\printnames[labelname]{author}}
                    {\printnames[labelname]{groupauthor}}}}%
            % Year
            \setunit{\global\booltrue{cbx:parens}\addspace\bibopenparen}%
            % Put the shortauthor inside the year brackets if necessary
            \ifnameundef{shortauthor}
            {}
            {\cbx@apa@ifnamesaved
                {}
                {\printnames{shortauthor}%
                    \setunit{\printdelim{nameyeardelim}}}}%
            % Print prenote (belongs to first cite)
            \ifnumequal{\value{citecount}}{1}
            {\usebibmacro{prenote}}
            {}%
            % Actual year printing
            \ifthenelse{\ifciteibid\AND\NOT\iffirstonpage}
            {\usebibmacro{cite:ibid}}
            {\usebibmacro{cite:plabelyear+extradate}}%
            % Save name hash for checks later
            \savefield{fullhash}{\cbx@lasthash}}%
        \stepcounter{textcitecount}}}

\letbibmacro{orig:postnote}{postnote}

\renewbibmacro*{postnote}{%
    \ifbool{cbx:loccit}
    {}
    {\usebibmacro{orig:postnote}}}
\makeatother
\ExecuteBibliographyOptions{ibidpage=true}

\DeclareSourcemap{
    \maps[datatype=bibtex]{
        \map{
            \step[fieldsource=urldate, match=\regexp{\A(\d{2}).(\d{2}).(\d{4})\Z}, replace={$3-$2-$1}]
        }
    }
}

\DeclareStyleSourcemap{
    \maps[datatype=bibtex, overwrite=true]{
        \map{
            \step[fieldsource=url, final]
            \step[typesource=misc, typetarget=online]
        }
    }
}
\begin{document}
    Lorem ipsum.\autocite{ctan}
    
    \printbibliography
\end{document}

答案1

您给出的示例引文不仅仅是@report一种@online资源。具体来说,它@report具有字段typenumber指示符,例如“工作论文 2014/9”。

请注意,这ctan并不特别适合作为此类条目类型的示例,因为它没有作者,并且实际上@online比 NIDI 论文更接近真实条目。

通过您的设置,您将获得

\documentclass[ngerman, toc=listof, toc=bibliography, footnotes=multiple, numbers=noendperiod]{scrartcl}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}
\usepackage[
backend=biber,
style=apa,
autocite=inline, 
natbib=true,
isbn=false,
doi=false,
eprint=false,
dashed=false,
pagetracker, 
ibidtracker=constrict
]{biblatex}

\DeclareNameAlias{sortname}{family-given}
\DeclareNameAlias{default}{given-family}
\renewcommand*{\newunitpunct}{\addcomma\space}
\renewcommand*{\subtitlepunct}{\addperiod\space}

\DeclareDelimFormat{multinamedelim}{\addslash\space}
\DeclareDelimAlias{finalnamedelim}{multinamedelim}

\renewbibmacro*{url+urldate}{%
    \ifthenelse{\iffieldundef{url}\OR\NOT\iffieldundef{doi}}
    {}
    {\iffieldundef{urlyear}
        {}
        {\bibstring{retrieved}%
            \setunit{\addspace}%
            \printtext{\bibstring{from}}%
            \setunit{\addspace}}%
        \iffieldundef{url}{}{\printfield{url}\renewcommand*{\finentrypunct}{\relax}}
        \setunit*{\addspace}%
        \printurldate
        \setunit{\urldatecomma}%
}}

\makeatletter
\newbool{cbx:loccit}

\DeclareBibliographyOption[boolean]{ibidpage}[true]{%
    \ifstrequal{#1}{true}
    {\ExecuteBibliographyOptions{loccittracker=constrict}}
    {\ExecuteBibliographyOptions{loccittracker=false}}}

\providecommand*{\mkibid}[1]{#1}

\newbibmacro*{cite:ibid}{%
  \printtext[bibhyperref]{\bibstring[\mkibid]{ibidem}}%
  \ifloccit
    {\global\booltrue{cbx:loccit}}
    {}}


\renewbibmacro*{cite}{%
    \global\boolfalse{cbx:loccit}%
    \ifthenelse{\ifciteibid\AND\NOT\iffirstonpage}
    {\usebibmacro{cite:ibid}}
    {\iffieldequals{fullhash}{\cbx@lasthash}
        % Multiple cites in one command
        {\setunit{\compcitedelim}%
            \usebibmacro{cite:plabelyear+extradate}}%
        % Single cite
        {\ifnameundef{labelname}
            % No author/editor
            {\usebibmacro{cite:noname}%
                \setunit{\printdelim{nameyeardelim}}%
                \usebibmacro{cite:plabelyear+extradate}%
                \savefield{fullhash}{\cbx@lasthash}}
            % Normal cite
            {\ifnameundef{shortauthor}
                {\printnames{labelname}}%
                {\cbx@apa@ifnamesaved
                    {\printnames{shortauthor}}
                    {\ifnameundef{groupauthor}
                        {\printnames[labelname]{author}}
                        {\printnames[labelname]{groupauthor}}%
                        \addspace\printnames[sabrackets]{shortauthor}}}%
                \setunit{\printdelim{nameyeardelim}}%
                \usebibmacro{cite:plabelyear+extradate}%
                \savefield{fullhash}{\cbx@lasthash}}}%
        \setunit{\multicitedelim}}}

\renewbibmacro*{textcite}{%
    \global\boolfalse{cbx:loccit}%
    \iffieldequals{fullhash}{\cbx@lasthash}
    % Compact cite - more than one thing for same author
    {\setunit{\compcitedelim}%
        \usebibmacro{cite:plabelyear+extradate}}
    % New cite
    {\ifbool{cbx:parens}
        {\bibcloseparen\global\boolfalse{cbx:parens}}
        {}%
        \setunit{\textcitedelim}%
        \ifnameundef{labelname}
        % No author/editor
        {\iffieldundef{shorthand}%
            % Cite using title
            {\usebibmacro{cite:noname}%
                \setunit{\global\booltrue{cbx:parens}\addspace\bibopenparen}%
                \usebibmacro{cite:plabelyear+extradate}}
            % Cite using shorthand
            {\usebibmacro{cite:shorthand}}}
        % Normal cite with author/editor
        % Normal full cite
        {\ifnameundef{shortauthor}%
            % Normal full cite
            {\printnames{labelname}}
            % Cite using short author
            {\cbx@apa@ifnamesaved
                {\printnames{shortauthor}}
                {\ifnameundef{groupauthor}
                    {\printnames[labelname]{author}}
                    {\printnames[labelname]{groupauthor}}}}%
            % Year
            \setunit{\global\booltrue{cbx:parens}\addspace\bibopenparen}%
            % Put the shortauthor inside the year brackets if necessary
            \ifnameundef{shortauthor}
            {}
            {\cbx@apa@ifnamesaved
                {}
                {\printnames{shortauthor}%
                    \setunit{\printdelim{nameyeardelim}}}}%
            % Print prenote (belongs to first cite)
            \ifnumequal{\value{citecount}}{1}
            {\usebibmacro{prenote}}
            {}%
            % Actual year printing
            \ifthenelse{\ifciteibid\AND\NOT\iffirstonpage}
            {\usebibmacro{cite:ibid}}
            {\usebibmacro{cite:plabelyear+extradate}}%
            % Save name hash for checks later
            \savefield{fullhash}{\cbx@lasthash}}%
        \stepcounter{textcitecount}}}

\letbibmacro{orig:postnote}{postnote}

\renewbibmacro*{postnote}{%
    \ifbool{cbx:loccit}
    {}
    {\usebibmacro{orig:postnote}}}
\makeatother
\ExecuteBibliographyOptions{ibidpage=true}

\DeclareSourcemap{
    \maps[datatype=bibtex]{
        \map{
            \step[fieldsource=urldate, match=\regexp{\A(\d{2}).(\d{2}).(\d{4})\Z}, replace={$3-$2-$1}]
        }
    }
}

\DeclareStyleSourcemap{
    \maps[datatype=bibtex, overwrite=true]{
        \map{
            \step[fieldsource=url, final]
            \step[typesource=misc, typetarget=online]
        }
    }
}

\begin{filecontents}{\jobname.bib}
@report{kristiansen,
  author       = {Marcus H. Kristiansen},
  title        = {Agency as an Empirical Concept},
  subtitle     = {An Assessment of Theory and Operationalization},
  date         = {2014},
  type         = {Working Paper},
  number       = {2014/9},
  location     = {Den Haag},
  publisher    = {NIDI},
  url          = {https://www.nidi.nl/shared/content/output/papers/nidi-wp-2014-09.pdf},
  urldate      = {2020-07-28},
}
\end{filecontents}
\addbibresource{\jobname.bib}
\addbibresource{biblatex-examples.bib}

\begin{document}
  Lorem ipsum. \autocite{kristiansen}
    
  \printbibliography
\end{document}

Kristiansen, MH, (2014),《代理作为实证概念》。理论与操作评估 (工作论文编号 2014/9),海牙,NIDI,可从 https://www.nidi.nl/shared/content/output/papers/nidi-wp-2014-09.pdf 查阅 2020 年 7 月 28 日

这与图片中所展示的不完全一样,但很接近。

不过,我注意到,您的图片包含位置,这在第 7 版 APA 格式中通常不会出现biblatex-apa。事实上,如果我切换到biblatex-apa6第 6 版 APA 格式,我得到的结果更接近您需要的内容。

\documentclass[ngerman, toc=listof, toc=bibliography, footnotes=multiple, numbers=noendperiod]{scrartcl}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}
\usepackage[backend=biber,
  style=apa6]{biblatex}

\begin{filecontents}{\jobname.bib}
@report{kristiansen,
  author       = {Marcus H. Kristiansen},
  title        = {Agency as an Empirical Concept},
  subtitle     = {An Assessment of Theory and Operationalization},
  date         = {2014},
  type         = {Working Paper},
  number       = {2014/9},
  location     = {Den Haag},
  publisher    = {NIDI},
  url          = {https://www.nidi.nl/shared/content/output/papers/nidi-wp-2014-09.pdf},
  urldate      = {2020-07-28},
}
\end{filecontents}
\addbibresource{\jobname.bib}

\begin{document}
  Lorem ipsum. \autocite{kristiansen}
    
  \printbibliography
\end{document}

Kristiansen, MH (2014)。代理作为经验概念:理论和操作评估(工作文件编号 2014/9)。海牙:NIDI。2020 年 7 月 28 日可查阅 https://www.nidi.nl/shared/content/output/papers/nidi-wp-2014-09.pdf

相关内容