在 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並不意味著這是稍後在參考書目中實際用於打印字段的命令。因此,將 修補為.bblhas\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直接地。

相關內容