I'm using BibTeX (requirement of the journal I'm submitting to), and I'm referencing mostly journal articles, but also one blog post. I would like to hid the urls in the references list, but only for the journal articles. The url should still display for the blog post. Is this possible without removing the URLs from the .bib
file?
1 Answer
Here is an hack if there is only one blog, and key for the blog is known.
This solution also assumes:
1) that the url
bibtex
field is rendered by \url{<field>}
.
2) natbib
or other bibliography managers modifying (and adding arguments) to \bibitem` are not used (though, in some cases this is easy to fix).
\documentclass{article}
\usepackage{xpatch}
\usepackage{etoolbox}
\usepackage{filecontents}
\usepackage{url}
\begin{filecontents}{\jobname.bbl}
\begin{thebibliography}{1}
\bibitem{abc}
Author.
\newblock Title.
\newblock {\em Journal}, 2013. \url{http://article.example.com}
\bibitem{cde}
blogAuthot.
\newblock blogtitle. \url{blog.examnple.com}
\end{thebibliography}
\end{filecontents}
\let\oldurl\url
\providetoggle{blog}
\renewcommand{\url}[1]{\iftoggle{blog}{\oldurl{#1}}{}}
\xapptocmd{\@bibitem}{
\ifstrequal{#1}{cde}
{\toggletrue{blog}}
{\togglefalse{blog}}}
{}
{}
\begin{document}
This is a reference to an article \cite{abc}, this a reference to a blog \cite{cde}.
%\bibliographystyle{<style creating bbl with \url>}
\bibliography{\jobname}
\end{document}
The idea is to have a toggle for the blog, and based on this \url
is define to essentially gobble its content. The toggle is set to true based on the content of the bibtex key
for the blog (cde
in the example above). It is possible to extend to above to a list of values.
-
I'd prefer
\renewcommand{\url}{\iftoggle{blog}{\oldurl}{\@gobble}
(requires the usual\makeatletter
and\makeatother
) so the argument to\url
is not untimely read and tokenized.– egregSep 18, 2013 at 9:31
.bst
file)? The usual way to handle things is to select printing of fields in the.bst
file, but that's not possible if you have to use one and can't edit it.