定制 biblatex 条目类型或修改现有的?

定制 biblatex 条目类型或修改现有的?

我想知道是否可以添加 biblatex 条目类型(因为我不想使用不同的 biblatex 样式)到“法律”之类的内容。

说到法律,不幸的是,我所在大学的规则不太严格(所以我不知道是否以及在哪里添加“出版商”、“位置”等字段 - 如果您有一个好主意,请告诉我!) - 但是对于法律文本有一些要求:

法律书目条目应以标题开头,而不是作者/编辑/机构/组织等。

我一直努力坚持这一点:例子但是,它不起作用(我尝试了确切的示例,它可以工作,但是,当我更改类、参考书目方面的配置并尝试编译时,它已经坏了。我也完全不明白,为什么会发生这种情况,只是试图根据我的需要进行调整,但显然也没有用)

这是我当前不起作用的 MWE,它甚至不包含任何 bib 格式,因为我之前的许多步骤已经失败了。

\RequirePackage{filecontents}
\begin{filecontents*}{\jobname.bib}
@legislation{help,
 legaltitle = {Kaisei minp\={o} j\={o}bun},
 law = {Saik\={o}-saiban-sho},
 date = {1947},
 location = {T\={o}ky\={o}},
 maintitle = {testmaintitle},
 legaltitleaddon = {{\"U}berarbeiteter Gesetzestext des Zivilgesetzbuchs},
 doi = {10.11501/1275567},
 urldate = {2019-08-01},
 legalbook = {5},
 legalchapter = {3},
 legalarticle = {2}
}
\end{filecontents*}
\begin{filecontents}{legislation.dbx}
\DeclareDatamodelEntrytypes{legislation}
\DeclareDatamodelFields[type=field,datatype=literal]{
  court,
  legalcode,
  law,
  legaltitle,
  legaltitleaddon
}
\DeclareDatamodelFields[type=field, datatype=verbatim]{
  legalbookno,
  legalchapterno,
  legalarticleno
  }
\DeclareDatamodelEntryfields[legislation]{
  court,
  legalcode,
  legaltitle,
  legaltitleaddon,
  law,
  date,
  urldate,
  legalbookno,
  legalchapterno,
  legalarticleno,
  maintitle,
  maintitleaddon,
  url,
  doi,
  location
}
\end{filecontents}
\documentclass[a4paper]{scrartcl}
\usepackage[main=ngerman, english]{babel}
\usepackage[babel, german=quotes]{csquotes}
\usepackage[ngerman]{isodate}
\usepackage[ngerman]{datetime}
\usepackage[datamodel=legislation,backend=biber]{biblatex}
\usepackage{hyperref}
\addbibresource{\jobname.bib}

\DeclareLanguageMapping{ngerman}{legislation}

\DeclareFieldFormat[legislation]{legaltitle}{#1\isdot}
\DeclareFieldFormat{titleaddon}{\mkbibbrackets{#1}}
\DeclareFieldAlias{legaltitleaddon}{titleaddon}

\newbibmacro*{bookchaparticle}{%
  \bibstring{legalbook}%
 \printfield{legalbookno}
 \setunit{\addcomma\space}
   \bibstring{legalchapter}%
 \printfield{legalchapterno}
 \setunit{\addcomma\space}
   \bibstring{legalarticle}%
 \printfield{legalarticleno}

\DeclareBibliographyDriver{legislation}{%
  \usebibmacro{bibindex}%
  \usebibmacro{bookchaparticle}%
  \newunit\newblock
  \usebibmacro{finentry}}

\begin{document}
\nocite{*}
\cite{help}

\printbibliography
\end{document}

谢谢你!

之前的输出(由于我的代码有错误,目前没有输出):电流输出 所需输出:所需输出

这就是我试图用来作为最接近的例子这个,然而这也不起作用。

\RequirePackage{filecontents}
\begin{filecontents*}{\jobname.bib}
@stackexchange{se:l3help,
  sitetopic = {tex},
  title   = {What can \textit{I} do to help the \LaTeX3 Project},
  askdate = {2012-02-26},
  askid   = {45838},
  askp    = {Brent Longorough},
  askpid  = {344},
  ansp    = {Frank Mittelbach},
  anspid  = {10109},
  ansdate = {2012-03-01},
  ansid   = {46427},
}
\end{filecontents*}
\begin{filecontents}{stackexchange.dbx}
\DeclareDatamodelEntrytypes{stackexchange}
\DeclareDatamodelFields[type=field,datatype=literal]{
  sitekey,
  sitetopic,
}
\DeclareDatamodelFields[type=list,datatype=name]{
  askp,
  ansp,
}
\DeclareDatamodelFields[type=field, datatype=date, skipout]{
  askdate,
  ansdate,
  askeditdate,
  anseditdate}
\DeclareDatamodelFields[type=field, datatype=verbatim]{
  askid,
  askpid,
  anspid,
  ansid,
}
\DeclareDatamodelEntryfields[stackexchange]{
  sitekey,
  sitetopic,
  askid,
  askp,
  askpid,
  ansp,
  anspid,
  ansid,
  askyear,
  askmonth,
  askday,
  ansyear,
  ansmonth,
  ansday,
  askedityear,
  askeditmonth,
  askeditday,
  ansedityear,
  anseditmonth,
  anseditday,
  title}
\end{filecontents}
\documentclass[
  12pt,
  a4paper,
  headings=standardclasses,
  listof=totoc,
  numbers=noenddot
]{scrartcl}

\usepackage{showframe}
\usepackage[left=2.50cm, right=2.50cm, top=2.50cm, bottom=2.00cm, footskip=1cm]{geometry}
\usepackage[onehalfspacing]{setspace}
\usepackage[main=ngerman, english]{babel}
\usepackage[babel, german=quotes]{csquotes}
\usepackage[ngerman]{isodate}
\usepackage[ngerman]{datetime}
\usepackage[
  backend=biber,
  style=ext-authoryear,
  sorting=nyvt,
  datamodel=journaltitleaddon,
  maxnames=25,
  innamebeforetitle=true,
  usetranslator=true,
  alldates=terse,
  labeldate=year,
  dashed=false,
  isbn=false
]{biblatex}
\usepackage{hyperref}
\addbibresource{\jobname.bib}

\begin{filecontents*}{english-stack.lbx}
  \ProvidesFile{english-stack.lbx}[2014/05/07 english with additions for stackexchange]
  \InheritBibliographyExtras{english}
  \NewBibliographyString{asked,answered,edited}
  \DeclareBibliographyStrings{%
    inherit   = {english},
    asked     = {{asked}{asked}},
    answered  = {{answered}{answered}},
    edited    = {{edited}{edited}},
  }
\end{filecontents*}
\DeclareLanguageMapping{ngerman}{ngerman}

\DeclareFieldFormat[stackexchange]{title}{\mkbibquote{#1\isdot}}
\DeclareFieldFormat{askpid}{%
  \mkbibparens{\ifhyperref
    {\href{http://tex.stackexchange.com/users/#1}{\nolinkurl{#1}}}
    {\nolinkurl{#1}}}}

\DeclareFieldFormat{anspid}{%
  \mkbibparens{\ifhyperref
    {\href{http://tex.stackexchange.com/users/#1}{\nolinkurl{#1}}}
    {\nolinkurl{#1}}}}

\DeclareFieldFormat{askid}{%
  \mkbibparens{\ifhyperref
    {\href{http://tex.stackexchange.com/q/#1}{\nolinkurl{#1}}}
    {\nolinkurl{#1}}}}

\DeclareFieldFormat{ansid}{%
  \mkbibparens{\ifhyperref
    {\href{http://tex.stackexchange.com/a/#1}{\nolinkurl{#1}}}
    {\nolinkurl{#1}}}}

\newbibmacro*{stackexchangequestion}{%
  \printfield{title}%
  \setunit{\addspace}%
  \printfield{askid}%
}

\newbibmacro*{stackexchangeask}{%
  \bibstring{asked}%
  \setunit{\addspace}%
  \printaskdate%
  \iffieldundef{askedityear}%
    {}
    {\printtext[parens]{%
       \bibstring{edited}%
       \setunit{\addspace}%
       \printaskeditdate}}%
  \setunit{\addspace}%
  \bibstring{byauthor}%
  \setunit{\addspace}%
  \printnames{askp}%
  \setunit{\addspace}%
  \printfield{askpid}%
}

\newbibmacro*{stackexchangeans}{%
  \bibstring{answered}%
  \setunit{\addspace}%
  \printansdate%
  \iffieldundef{ansedityear}
    {}
    {\printtext[parens]{%
       \bibstring{edited}%
       \setunit{\addspace}%
       \printanseditdate}}%
  \setunit{\addspace}%
  \bibstring{byauthor}%
  \setunit{\addspace}%
  \printnames{ansp}%
  \setunit{\addspace}%
  \printfield{anspid}%
}

\newbibmacro*{stackexchangesite}{%
  \printfield{sitetopic}}

\DeclareBibliographyDriver{stackexchange}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{stackexchangequestion}%
  \newunit\newblock
  \usebibmacro{stackexchangeask}%
  \newunit\newblock
  \usebibmacro{stackexchangeans}%
  \newunit\newblock
  \usebibmacro{stackexchangesite}%
  \newunit\newblock
  \usebibmacro{finentry}}

\begin{document}
\nocite{*}
\cite{se:l3help}

\printbibliography
\end{document}

答案1

MWE 中有一个语法错误,导致事情很快就变得很糟糕。该块

\newbibmacro*{bookchaparticle}{%
  \bibstring{legalbook}%
 \printfield{legalbookno}
 \setunit{\addcomma\space}
   \bibstring{legalchapter}%
 \printfield{legalchapterno}
 \setunit{\addcomma\space}
   \bibstring{legalarticle}%
 \printfield{legalarticleno}

缺少右花括号。只需}在末尾添加缺失部分即可。错误基本就是这样!

如果}添加了,示例将会编译,但输出将不会像预期的那样。这是由于两个原因。

  1. MWE 使用参考书目字符串,但没有声明或翻译它们(您在问题的早期版本中这样做了,我只是.lbx从那里复制了相关文件)。

  2. 字段名称似乎有点混淆:有时显示legalbookno(在.dbx和 驱动程序中),有时显示legalbook(在.bib文件中)。对于legalarticle(no)和 也一样legalchapter(no)。我认为添加no并将所有名称标准化为legalbooklegalchapter、没什么意义legalarticle

最后一个小小的美学细节:我更喜欢使用\bibstring字段格式而不是直接使用 bibmacros,所以这就是我在这里所做的。

\RequirePackage{filecontents}
\begin{filecontents*}{\jobname.bib}
@legislation{help,
 legaltitle      = {Kaisei minpō jōbun},
 law             = {Saikō-saiban-sho},
 date            = {1947},
 location        = {Tōkyō},
 maintitle       = {testmaintitle},
 legaltitleaddon = {Überarbeiteter Gesetzestext des Zivilgesetzbuchs},
 doi             = {10.11501/1275567},
 urldate         = {2019-08-01},
 legalbook       = {5},
 legalchapter    = {3},
 legalarticle    = {2},
}
\end{filecontents*}
\begin{filecontents}{legislation.dbx}
\DeclareDatamodelEntrytypes{legislation}
\DeclareDatamodelFields[type=field,datatype=literal]{
  court,
  legalcode,
  law,
  legaltitle,
  legaltitleaddon,
  legalbook,
  legalchapter,
  legalarticle,
}
\DeclareDatamodelEntryfields[legislation]{
  court,
  legalcode,
  legaltitle,
  legaltitleaddon,
  law,
  date,
  urldate,
  legalbook,
  legalchapter,
  legalarticle,
  maintitle,
  maintitleaddon,
  url,
  doi,
  location,
}
\end{filecontents}
\begin{filecontents*}{legislation-ngerman.lbx}
\ProvidesFile{legislation-ngerman.lbx}[2019 Legislation according to IOA]
\InheritBibliographyExtras{ngerman}

\DeclareBibliographyStrings{%
  inherit       = {ngerman},
  legalbook     = {{legalbook}{legalbook}},
  legalchapter  = {{legalchapter}{legalchapter}},
  legalarticle  = {{legalarticle}{legalarticle}},
}
\end{filecontents*}
\documentclass[a4paper]{scrartcl}
\usepackage[main=ngerman, english]{babel}
\usepackage[babel, german=quotes]{csquotes}
\usepackage[ngerman]{isodate}
\usepackage[ngerman]{datetime}
\usepackage[datamodel=legislation,backend=biber]{biblatex}
\usepackage{hyperref}
\addbibresource{\jobname.bib}

\NewBibliographyString{legalbook,legalchapter,legalarticle}
\DeclareLanguageMapping{ngerman}{legislation-ngerman}

\DeclareFieldFormat[legislation]{legaltitle}{#1\isdot}
\DeclareFieldFormat{titleaddon}{\mkbibbrackets{#1}}
\DeclareFieldAlias{legaltitleaddon}{titleaddon}

\DeclareFieldFormat{legalbook}{\bibstring{legalbook}~#1}
\DeclareFieldFormat{legalchapter}{\bibstring{legalchapter}~#1}
\DeclareFieldFormat{legalarticle}{\bibstring{legalarticle}~#1}

\newbibmacro*{bookchaparticle}{%
  \printfield{legalbook}%
  \setunit{\addcomma\space}%
  \printfield{legalchapter}%
  \setunit{\addcomma\space}%
  \printfield{legalarticle}}

\DeclareBibliographyDriver{legislation}{%
  \usebibmacro{bibindex}%
  \usebibmacro{bookchaparticle}%
  \newunit\newblock
  \usebibmacro{finentry}}

\begin{document}
\nocite{*}
\cite{help}

\printbibliography
\end{document}

法律第5册,法律第3章,法律第2条。


biblatex只允许您加载单个.dbx文件,这对于您的用例来说并不是真正的障碍,因为无论如何您都是编写所有.dbx文件的人,因此合并它们没什么大不了的。但如果需要,可以使用以下解决方法加载多个文件:使用 biblatex 进行数据模型分发https://ctan.org/pkg/biblatex-multiple-dm

我会尽量缩短字段名称,并尝试重新使用现有字段。所以我可能会将其重命名legalbookbooketc。我认为没有必要将legalarticleand 声明为verbatim(其中类似于\begin{verbatim}...\end{verbatim}特殊字符的字符没有其特殊含义;这对于类似 URL 的字段很有用),所以我将它们变成了“普通” 。我也不太明白and与etcliteral的含义。lawlegaltitletitlemaintitle

相关内容