BibLaTeX 自定义杂项引用,添加点

BibLaTeX 自定义杂项引用,添加点

我正在根据 ISO 690 规范编写一份包含多种参考书目类型的文档。

我有这个MWE:

\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage{fancyhdr}
\usepackage{graphicx}
\usepackage[headheight=2cm,]{geometry}
\usepackage[most]{tcolorbox}
\usepackage{lipsum}
\usepackage{pgfplots}
\usepackage{xcolor}
\usepackage{multirow}
\usepackage{tikz}
\usepackage[hyphens, spaces, obeyspaces]{url}
\usepackage{hyperref}

% ...

\usepackage[backend=biber,defernumbers=true,style=iso-authoryear,]{biblatex}
\addbibresource{Zdroje/Zdroje.bib}

% ...

\DeclareFieldFormat[misc]{urldate}{[cit. #1].}
\DeclareFieldFormat[misc]{url}{Dostupné z: #1}

% ...

\begin{document}

% ...

%\include{...}

Some text\footfullcite{example}.

% ...

\printbibliography[omitnumbers=true,type=misc,heading=subbibliography,title={Online zdroje}]

% ...

\end{document}

文件.bib如下所示:

@misc{example,
    title = {{exmp}, a.s. - {Detail} - {example}.cz},
    url = {https://www.exmp.cz/search/detail/cz-12345678/},
    urldate = {2021-12-27},
}

我使用以下方式插入参考书目:\footfullcite{key}

一切工作正常,只是杂项类型的参考书目条目未根据 iso-690 规范正确打印。

通过编译 MWE,我得到了以下信息:

在此处输入图片描述

我希望得到的是:

exmp, as - 详细信息 - example.cz[在线的]。 [引文] 2021-12-27]。取消关注:https://www.exmp.cz/search/detail/cz-12345678/

请注意后面的点[online]

我尝试\DeclareFieldFormat过:

  • howpublished
  • eprint
  • eprintclass
  • eprinttype

但是什么都没起作用,我没能在[online]部分后面添加点,你能帮帮我吗?


更新:

biblatex-iso690 项目中出现了问题。

不幸的是,我无法重新定义宏,但是对于任何感兴趣的人,我找到了一种快速而简单的解决方法来解决这个问题。

可以howpublished = {online}为 bibfile 中的条目定义,完成后,howpublished可以通过访问文字\DeclareFieldFormat并进行相应的更改:\DeclareFieldFormat[misc]{howpublished}{[#1].},但正如 moewe 所述,这可能不是最好的解决方案。

目前,在问题解决之前,我已经创建了一个简单的 python 脚本和 makefile 来使用howpublishedurldate字段之间的标点符号来编译我的项目。

请注意,我绝不是 Make 专家,所以可能有更好的方法来做到这一点。

生成文件:

TEXFILE := Strategický_audit # <= Change the texfile name here
BIBFILE := Zdroje/Zdroje.bib # <= Change the bib file location here
TEXENGINE=pdflatex
BIBLATEX=biber
BUILDFLAGS=-output-directory=out
FOLDER=out
BUILDTEX=$(TEXENGINE) $(BUILDFLAGS) $(TEXFILE)

.PHONY: all
.PHONY: prepareBib
.PHONE: clear
.PHONY: clean
.PHONE: prepareOut

build: prepareBib prepareOut
    $(BUILDTEX)
    $(BIBLATEX) $(FOLDER)/$(TEXFILE)
    $(BUILDTEX)
    $(BUILDTEX)
    cp out/$(TEXFILE).pdf .

prepareBib:
    python3 prepare_bib.py $(BIBFILE)

prepareOut:
    ./create_subdirectories.sh

clear: clean
    @rm -f $(TEXFILE).pdf; \

clean:
    @rm -rf $(FOLDER);

help:
    @echo "build:    Generate pdf file."; \
     echo "clear:    Delete all generated files."; \
     echo "clean:    Delete all temporary files."; \
     echo "help:     Print help for Makefile."

all: build clean

Python 脚本:

"""File to parse and prepare the bib file for the LaTeX compilation."""

from typing import Iterable, Any, Tuple
import copy
import sys

prefixes: list = ["@misc", "@online"]

def check_if_field_already_exists(it:Iterable[Any], field: str) -> bool:
    return any(field in string for string in it)

def check_if_online_entry(it:Iterable[Any]) -> bool:
    return it[0].startswith(tuple(prefixes))

def is_element_last_in_iterable(it:Iterable[Any]) -> Iterable[Tuple[bool, Any]]:
    iterable = iter(it)
    ret_var = next(iterable)
    for val in iterable:
        yield False, ret_var
        ret_var = val
    yield True, ret_var

def main(bib_file_location: str) -> None:

    list_of_entries = []
    temp_list = []

    try:
        with open(bib_file_location, "r") as f:
            lines = f.readlines()
    except FileNotFoundError:
        print("Provided file was not found.")
        exit(1)

    for line in lines:
        if line == "\n":
            continue
        temp_list.append(line)
        if line == "}\n" or line == "}":
            list_of_entries.append(copy.deepcopy(temp_list))
            temp_list.clear()

    with open(bib_file_location, "w") as f:
        for entry in list_of_entries:
            if not (is_online := check_if_online_entry(entry)):
                for is_last_element, var in is_element_last_in_iterable(entry):
                    if is_last_element:
                        f.write("{}\n".format(var))
                    else:
                        f.write(var)
            if is_online:
                if check_if_field_already_exists(entry, "howpublished"):
                    for is_last_element, var in is_element_last_in_iterable(entry):
                        if is_last_element:
                            f.write("{}\n".format(var))
                        else:
                            f.write(var)
                else:
                    for is_last_element, var in is_element_last_in_iterable(entry):
                        if is_last_element:
                            f.write("\thowpublished = {{online}},\n{}\n".format(var))
                        else:
                            f.write(var)

if __name__ == "__main__":
    if len(sys.argv) > 1:
        main(sys.argv[1])
    else:
        print("Please provide the bib file location.")
        exit(1)

Bash 脚本用于准备编译环境:

#!/bin/bash

create_subdirectories () {
    for OUTPUT in $(find . -type d)
    do
        if [[ $OUTPUT == *".texpadtmp"* ]] || [[ $OUTPUT == *"out"* ]] || [[ $OUTPUT == "." ]]; then
            :
        else
            mkdir -p out/"${OUTPUT#"./"}"
        fi
    done
}

copy_folder_structure () {
for OUTPUT in $(find . -type f -name "*.tex" -o -name "*.bib" -o -name "*.png")
    do
        if [[ $OUTPUT == "./out/"* ]]; then
            :
        else
            cp -R "${OUTPUT}" out/"${OUTPUT#"./"}"
        fi
    done
}

create_subdirectories
copy_folder_structure

请注意,仅当 bib 文件是特定格式时,Makefile 才会起作用(我使用的是 Zotero)。

答案1

感谢向 biblatex-iso690 项目发布了一个问题,我通过以下方式重新定义宏设法解决了该问题:

\providetoggle{bbx:url}

% The url seen date of @online entries is always printed
\renewbibmacro*{urldate}{%
  % if there is no publisher specified in the bib file, set unit to period
  \ifboolexpr{%
    test {\iflistundef{publisher}}%
    and test {\iflistundef{location}}%
  }{\setunit{\adddot\addspace}}%
  {\setunit{\addspace}}%
  \ifboolexpr{
    test {\iftoggle{bbx:url}}
    or test {\ifentrytype{online}}
  }
    {\printurldate}%
    {}%
}

请注意,该解决方案适用于在线输入类型。

相关内容