3

I use a custom environment {readon} to give some additional article and websites for the read at the end of sections. How can I change \cite so that it prints also the URL for @ONLINE entries in this list?

enter image description here

\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}
Tobi
  • 56,353
  • 2
    Only in readon? Or also in other instances when you use \cite? – moewe Jun 28 '17 at 15:56
  • I’d say only in readon but math the moment there are no occurrences of \cite outside of the environment. However in that case I could just add the redefinition of cite in the definition of {readon} to keep it local … – Tobi Jun 28 '17 at 17:13

2 Answers2

3

With

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

and then

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

enter image description here

  • Hm … that would require to add an extra macro for every entry. Of course I could wrap this an a new macro and \let this to be \cite. But what would be the way to change \cite itself? – Tobi Jun 28 '17 at 16:56
  • sure, a simple \myCite{#1} should work –  Jun 28 '17 at 17:30
  • Except for the optional arguments ;-) but I prefer the solution by moewe anyway … – Tobi Jun 28 '17 at 17:36
  • With an optional argument! –  Jun 28 '17 at 17:41
  • Sure it is possible (ans not that complicated) but one has to take care of two optional arguments of \cite. I just wanted to mention it for sake of completeness if another user comes here later :-) – Tobi Jun 28 '17 at 17:50
  • It is not important if you need one or two optional arguments. –  Jun 28 '17 at 17:53
  • Sorry … how do you mean that? – Tobi Jun 28 '17 at 19:38
3

You can modify the cite macro to print the URL for @online entries

\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}}
    {}}

Since this modifies the cite bibmacro, the solution is specific to the authoryear style, but the general idea can be applied for all styles.

moewe
  • 175,683
  • Thanks! It works fine although I had to change to \ptintfield[siteurl]{url} to make it use my \DeclareFieldFormat{citeurl}{[\url{#1}} setting. – Tobi Jun 28 '17 at 17:11