无法使用 biblatex 替换非 ASCII 字符

无法使用 biblatex 替换非 ASCII 字符

这是对我的问题的跟进翻译参考书目条目字段中的内容(biblatex),这暴露了当尝试替换文件中的内容时出现问题,.bib因为该内容包含非 ASCII 字符,例如æøå

编译以下 MWE 可以正常工作。在本例中,字符串def被替换为abc

\documentclass{article}
\usepackage[style = authoryear-comp]{biblatex}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@BOOK{lennon1968,
    AUTHOR = "John Lennon",
    TITLE = "def",
    YEAR = "1968"}
\end{filecontents}
\DeclareSourcemap{
  \maps[datatype = bibtex]{
    \map{
       \step[fieldsource = title,
          match = {def}, 
          replace = {abc}]
    }
  }
}
\addbibresource{\jobname.bib}
\begin{document}
\nocite{*}
\printbibliography
\end{document}

在此处输入图片描述

但是当字符串包含非 ASCII 字符(如)时æøå,不会产生任何输出LaTeX

\documentclass{article}
\usepackage[style = authoryear-comp]{biblatex}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@BOOK{lennon1968,
    AUTHOR = "John Lennon",
    TITLE = "æøå",
    YEAR = "1968"}
\end{filecontents}
\DeclareSourcemap{
  \maps[datatype = bibtex]{
    \map{
       \step[fieldsource = title,
          match = {æøå}, 
          replace = {abc}]
    }
  }
}
\addbibresource{\jobname.bib}
\begin{document}
\nocite{*}
\printbibliography
\end{document}

控制台产生此输出(biblatextest64.tex即文档的名称):

Failure to make 'biblatextest64.pdf'
Collected error summary (may duplicate other messages):
  biber biblatextest64: Command for 'biber biblatextest64' gave return code 256
Latexmk: Use the -f option to force complete processing,
 unless error was exceeding maximum runs of latex/pdflatex.
Latexmk: Errors, so I did not complete making targets
C:\texlive2013\bin\win32\runscript.tlu:650: command failed with exit code 12:
perl.exe c:/texlive2013/texmf-dist/scripts/latexmk/latexmk.pl -pdf biblatextest64.tex

使用 进行编译时生成了一个 pdf XeLaTeX,但是没有进行替换:

\documentclass{article}
\usepackage[style = authoryear-comp]{biblatex}
\usepackage{fontspec}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@BOOK{lennon1968,
    AUTHOR = "John Lennon",
    TITLE = "æøå",
    YEAR = "1968"}
\end{filecontents}
\DeclareSourcemap{
  \maps[datatype = bibtex]{
    \map{
       \step[fieldsource = title,
          match = {æøå}, 
          replace = {abc}]
    }
  }
}
\addbibresource{\jobname.bib}
\begin{document}
\nocite{*}
\printbibliography
\end{document}

在此处输入图片描述

答案1

看来赋予的值match是通过 TeX 的扩展机制传递的,这是一个大问题,但也有帮助,因为我们可以(也可以有选择地)使用\detokenize

\documentclass{article}
\usepackage[style = authoryear-comp]{biblatex}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@BOOK{lennon1968,
    AUTHOR = "John Lennon",
    TITLE = "æøå",
    YEAR = "1968"}
\end{filecontents}

\DeclareSourcemap{
  \maps[datatype = bibtex]{
    \map{
       \step[fieldsource = title,
          match = {\detokenize{æøå}},
          replace = {abc}]
    }
  }
}
\addbibresource{\jobname.bib}
\begin{document}
\nocite{*}
\printbibliography
\end{document}

文件中是这样写的.bcf

  <!-- SOURCEMAP -->
  <bcf:sourcemap>
    <bcf:maps datatype="bibtex" level="user">
      <bcf:map>
        <bcf:map_step map_field_source="title" map_match="æøå" map_replace="abc"/>
      </bcf:map>
    </bcf:maps>

如果没有\detokenize,结果是

  <!-- SOURCEMAP -->
  <bcf:sourcemap>
    <bcf:maps datatype="bibtex" level="user">
      <bcf:map>
        <bcf:map_step map_field_source="title" map_match="\T1\ae \T1\o <E5>" map_replace="abc"/>
      </bcf:map>
    </bcf:maps>

看起来一切\detokenize正常。但是,替换并没有发生,这似乎是 Biber 的一个问题。

也就是说,我尝试了以下 Perl 脚本(改编自https://stackoverflow.com/a/1572156

use warnings;
use strict;
use utf8;
binmode STDOUT, "utf8";
my $string = "æøå";

$string =~ s/æøå/abc/gi; 

print "$string\n";

终端上的结果是

abc

相关内容