当我尝试在 URL 中使用空格时,它会显示 %20 而不是空格。我在网上寻找答案,发现使用
\PassOptionsToPackage{obeyspaces}{url}%
应该可以解决问题。确实如此,但至少对我来说不在参考书目中。
以下是 MWE:
\documentclass{article}
\PassOptionsToPackage{obeyspaces}{url}%
\usepackage[backend=biber,sorting=nyt,style=alphabetic]{biblatex}
\usepackage{hyperref}
\bibliography{test}
\begin{document}
\cite{mean_well_rcp-1600_2018}
\url{C:/Test Folder/file}
\printbibliography
\end{document}
@misc{mean_well_rcp-1600_2018,
langid = {Englisch},
title = {RCP-1600 series},
url = {C:/Test Filder/file},
shorttitle = {RCP-1600},
date = {2018-01-15},
author = {MEAN\textasciitilde{}WELL}
}
有什么建议我做错了吗?
答案1
您可以重新定义 url bibmacro 以使用 urlraw 而不是 url:
\documentclass{article}
\PassOptionsToPackage{obeyspaces}{url}%
\usepackage[backend=biber,sorting=nyt,style=alphabetic]{biblatex}
\usepackage{hyperref}
\bibliography{test}
\renewbibmacro*{url}{\printfield{urlraw}}
\begin{document}
\cite{mean_well_rcp-1600_2018}
\url{C:/Test Folder/file}
\printbibliography
\end{document}
答案2
C:/Test Folder/file
对于参考书目来说,这是一个相当不寻常的 URL,但当然这可能只是举个例子。如果不是,那么您可能需要查看该file
字段,它不被任何标准样式使用,但它在语义上是合理的决定。
Biber 将 URL 转义为百分比编码。如果您不想这样,您可以urlraw
改为显示该字段,请参阅如何禁用 URL 中的百分比编码?。
\documentclass{article}
\usepackage[backend=biber,sorting=nyt,style=alphabetic]{biblatex}
\usepackage{hyperref}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@misc{mean_well_rcp-1600_2018,
langid = {english},
title = {RCP-1600 series},
url = {C:/Test Filder/file},
shorttitle = {RCP-1600},
date = {2018-01-15},
author = {MEAN\textasciitilde{}WELL}
}
\end{filecontents}
\DeclareFieldFormat{url}{\mkbibacro{URL}\addcolon\space\url{\thefield{urlraw}}}
\addbibresource{\jobname.bib}
\begin{document}
\cite{mean_well_rcp-1600_2018}
\url{C:/Test Folder/file}
\raggedright
\printbibliography
\end{document}
你可以更安全一点,链接到编码版本,同时显示未编码版本
\DeclareFieldFormat{url}{%
\mkbibacro{URL}\addcolon\space
\ifhyperref
{\href{#1}{\nolinkurl{\thefield{urlraw}}}}
{\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter
\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter
\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter
\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter
\expandafter\expandafter\expandafter
\nolinkurl
\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter
\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter
\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter
\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter
\expandafter\expandafter\expandafter
{\thefield{urlraw}}}}
请注意,该langid
字段应包含已知的语言名称babel
或polyglossia
。Englisch
在该上下文中不是有效的语言名称,您可能需要english
。
答案3
文件路径不能是有效的 URL。因此,在您的 bib 条目中,不要使用该url
字段来存储文件路径!
第一个解决方案(使用eprint
和eprinttype
字段)
\documentclass{article}
\usepackage{filecontents}
\begin{filecontents*}{\jobname.bib}
@misc{mean_well_rcp-1600_2018,
langid = {Englisch},
title = {RCP-1600 series},
eprint = {C:/Test Folder/file},
eprinttype= {raw},
shorttitle = {RCP-1600},
date = {2018-01-15},
author = {MEAN\textasciitilde{}WELL}
}
\end{filecontents*}
\usepackage[backend=biber,sorting=nyt,style=alphabetic]{biblatex}
\usepackage{hyperref}
\DeclareFieldFormat{eprint:raw}{%
Path\addcolon\space\texttt{#1}%
}
\addbibresource{\jobname.bib}
\begin{document}
\cite{mean_well_rcp-1600_2018}
\printbibliography
\end{document}
第二种解决方案(使用file
字段)
(形式这个答案)
\documentclass{article}
\usepackage{filecontents}
\begin{filecontents*}{\jobname.bib}
@misc{mean_well_rcp-1600_2018,
langid = {Englisch},
title = {RCP-1600 series},
file = {C:/Test Folder/file},
shorttitle = {RCP-1600},
date = {2018-01-15},
author = {MEAN\textasciitilde{}WELL}
}
\end{filecontents*}
\pagestyle{empty}
\usepackage[backend=biber,sorting=nyt,style=alphabetic]{biblatex}
\usepackage{hyperref}
\DeclareFieldFormat{file}{%
\bibstring{file}\addcolon\space\texttt{#1}%
}
\renewbibmacro{finentry}{%
\finentry\addspace
\printfield{file}%
}
\addbibresource{\jobname.bib}
\begin{document}
\cite{mean_well_rcp-1600_2018}
\printbibliography
\end{document}