如何讓 \cite 列印 @ONLINE 的 URL?

如何讓 \cite 列印 @ONLINE 的 URL?

我使用自訂環境{readon}在章節末尾提供一些額外的文章和網站供閱讀。我如何更改\cite才能列印@ONLINE此列表中條目的 URL?

在此輸入影像描述

\documentclass{scrbook}

\usepackage[style=authortitle]{biblatex}
\addbibresource{\jobname.bib}

\usepackage{lipsum}

\begin{filecontents}{\jobname.bib}
   @Online{penalties,
     author  = {David Carlisle},
     title   = {What are penalties and which ones are defined?},
     date    = {2012-04-09},
     url     = {https://tex.stackexchange.com/a/51264/4918},
     urldate = {2017-06-28},
   }
   @Book{texbytopic,
     author  = {Eijkhout, Victor},
     title   = {\TeX{} by Topic},
     address = {Berlin},
     year    = {2014},
   }
\end{filecontents}

\newenvironment{readon}{%
   \par\bigskip\noindent
   \footnotesize
   \textbf{Further reading \dots}
   \begin{itemize}
}{
   \end{itemize}
}

\begin{document}

\lipsum[1-3]

\begin{readon}
   \item \cite[155\psqq]{texbytopic}
   \item \cite{penalties} [[add URL here]]
\end{readon}

\printbibliography

\end{document}

答案1

@online您可以修改 cite 巨集來列印條目的 URL

\renewbibmacro*{cite}{%
  \iffieldundef{shorthand}
    {\ifnameundef{labelname}
       {}
       {\printnames{labelname}%
        \setunit{\printdelim{nametitledelim}}}%
     \usebibmacro{cite:title}}%
    {\usebibmacro{cite:shorthand}}%
  \usebibmacro{cite:url}}

\newbibmacro{cite:url}{%
  \ifentrytype{online}
    {\setunit{\addspace}%
     \printfield{url}}
    {}}

由於這會修改citebibmacro,因此解決方案特定於authoryear樣式,但一般想法可以應用於所有樣式。

答案2

\usepackage[style=authortitle]{biblatex}
\addbibresource{\jobname.bib}
\DeclareFieldFormat{citeurl}{\ifentrytype{online}{[\url{#1}]}{}}

進而

\begin{readon}
    \item \cite[155\psqq]{texbytopic} \citeurl{texbytopic}
    \item \cite{penalties} \citeurl{penalties}
\end{readon}

在此輸入影像描述

相關內容