在 biblatex 中使用 \path 代替 \verb

在 biblatex 中使用 \path 代替 \verb

注意,\path可以根据需要对任意文本进行换行强制在 \url 中换行,我想使用\path而不是\verbbiblatex 内部的“逐字”字段。

这意味着覆盖\verb\endverb,例如参见.bbl下面 MWE 生成的文件中的这些行。

  \verb{file}
  \verb /Users/joe/Weholdthesetruthstobeself-evidentthatallmenarecreatedequalthattheyareendowedbytheirCreatorwithcertainunalienableRightsthatamongtheseareLifeLibertyandthepursuitofHappiness/dec.txt
  \endverb

我对这在句法上如何起作用感到困惑。

此处的图像显示了“路径”上所需的换行;带有大量下划线的文件名的(良好)行为;以及没有下划线的文件名的(不太好的)行为。

在此处输入图片描述

上述内容的源代码:

% arara: pdflatex
% arara: biber
% arara: pdflatex
% arara: pdflatex
\documentclass{article}

\usepackage[style=reading,
            entryhead=true,
            entrykey=false,
            natbib,
            hyperref=false,
            url=false,
            doi=false,
            %style=apa,
            sorting=nyt,
            isbn=false,
            %backref=true,
            firstinits=true,
            minnames=13,
            maxnames=35,
            minbibnames=10,
            maxbibnames=100,
            parentracker=true,
            defernumbers=true,
            backend=biber]{biblatex}

\usepackage[hyphenbreaks]{breakurl}
\PassOptionsToPackage{hyphens}{url}

\begin{filecontents}{\jobname.bib}
@inproceedings{XXXXXX,
  author = {PQR},
  booktitle = {BBC},
  keywords = {LLM},
  title = {ARP},
  year = {2010a},
  file = {/Users/joe/We_hold_these_truths_to_be_self-evident_that_all_men_are_created_equal_that_they_are_endowed_by_their_Creator_with_certain_unalienable_Rights_that_among_these_are_Life_Liberty_and_the_pursuit_of_Happiness/dec.txt},
}

@inproceedings{YYYYYYYY,
  author = {PQR},
  booktitle = {BBC},
  keywords = {LLM},
  title = {ARP},
  year = {2010b},
  file = {/Users/joe/Weholdthesetruthstobeself-evidentthatallmenarecreatedequalthattheyareendowedbytheirCreatorwithcertainunalienableRightsthatamongtheseareLifeLibertyandthepursuitofHappiness/dec.txt},
}
\end{filecontents}

\expandafter\def\expandafter\UrlBreaks\expandafter{\UrlBreaks%  save the current one
  \do\a\do\b\do\c\do\d\do\e\do\f\do\g\do\h\do\i\do\j%
  \do\k\do\l\do\m\do\n\do\o\do\p\do\q\do\r\do\s\do\t%
  \do\u\do\v\do\w\do\x\do\y\do\z\do\A\do\B\do\C\do\D%
  \do\E\do\F\do\G\do\H\do\I\do\J\do\K\do\L\do\M\do\N%
  \do\O\do\P\do\Q\do\R\do\S\do\T\do\U\do\V\do\W\do\X%
  \do\Y\do\Z}

\addbibresource{\jobname.bib}

\begin{document}

Path: \path{/Users/joe/Weholdthesetruthstobeself-evidentthatallmenarecreatedequalthattheyareendowedbytheirCreatorwithcertainunalienableRightsthatamongtheseareLifeLibertyandthepursuitofHappiness/dec.txt}

\nocite{*}

\printbibliography

\end{document}

答案1

首先,文件中的输出.bbl仅供 内部使用biblatex,其对 命令的使用\verb并不意味着这是稍后在参考书目中实际用于打印字段的命令。因此,将 修补为.bblhave\path而不是\verb只会破坏biblatex,而不会破坏参考书目中的文件路径。

输出的关键是 的字段格式file。在您的设置(使用reading样式)中,定义是

\DeclareFieldFormat{file}{\bibstring{file}\addcolon\space \url{#1}}

因此biblatex使用\url来自url包的命令(它加载该命令)。

但这并不是全部。对 的设置biblatex有自己的修改url,以便对参考书目中的 URL 中断进行更细粒度的控制。特别是,\UrlBreaks对于 打印的所有 URL 重新定义biblatex。因此,您对 的重新定义\UrlBreaks将被覆盖。

通过将和设置为非零值,您可以获得与使用biblatex内置功能重新定义类似的结果。另请参阅biburlucpenaltybiburllcpenaltybiblatex 书目中的长 URL 的换行符?。为了确保万无一失,您可能还需要研究设置biburlnumpenalty

\documentclass{article}

\usepackage[style=reading, backend=biber]{biblatex}

\setcounter{biburlucpenalty}{9000}
\setcounter{biburllcpenalty}{9000}

%\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@inproceedings{XXXXXX,
  author = {PQR},
  booktitle = {BBC},
  keywords = {LLM},
  title = {ARP},
  year = {2010},
  file = {/Users/joe/We_hold_these_truths_to_be_self-evident_that_all_men_are_created_equal_that_they_are_endowed_by_their_Creator_with_certain_unalienable_Rights_that_among_these_are_Life_Liberty_and_the_pursuit_of_Happiness/dec.txt},
}

@inproceedings{YYYYYYYY,
  author = {PQR},
  booktitle = {BBC},
  keywords = {LLM},
  title = {ARP},
  year = {2010},
  file = {/Users/joe/Weholdthesetruthstobeself-evidentthatallmenarecreatedequalthattheyareendowedbytheirCreatorwithcertainunalienableRightsthatamongtheseareLifeLibertyandthepursuitofHappiness/dec.txt},
}
\end{filecontents}

\addbibresource{\jobname.bib}

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

文件路径在行末断开。


如果您不想使用biblatex的内置功能,而想将url的设置的自定义重新定义带入biblatex,那么需要做一些额外的工作。

我发现最便宜的解决方案是

\newcommand*{\mkjcurlbreaks}{%
  \expandafter\def\expandafter\UrlBreaks\expandafter{\UrlBreaks%  save the current one
    \do\a\do\b\do\c\do\d\do\e\do\f\do\g\do\h\do\i\do\j%
    \do\k\do\l\do\m\do\n\do\o\do\p\do\q\do\r\do\s\do\t%
    \do\u\do\v\do\w\do\x\do\y\do\z\do\A\do\B\do\C\do\D%
    \do\E\do\F\do\G\do\H\do\I\do\J\do\K\do\L\do\M\do\N%
    \do\O\do\P\do\Q\do\R\do\S\do\T\do\U\do\V\do\W\do\X%
    \do\Y\do\Z}}

\mkjcurlbreaks

\DeclareFieldFormat{file}{\bibstring{file}\addcolon\space\mkjcurlbreaks\url{#1}}

另一种方法可以修改biblatex的定义\biburlsetup直接地。

相关内容