The solution that works perfect for me both for bibtex
and biblatex
is the combination of sloppypar
that @fuenfundachtzig mentioned with the \usepackage[hyphens]{url}
that proposed by @Suresh.
The next code is used to be able to use both ways (bibtex
and biblatex
) to compile your file and works for me in cases of natbib
s agsm
style and biber
s authoryear
. Actually you don't have to use both ways and the method will work (I think) anyway if you just keep the code of each case (bibtex
or biblatex
) [except of the trick of @moewe with the url that solved the problem I had in my post here that will be possibly need to be adjusted according to the bibtex
style we will use].
\documentclass{article}
\usepackage{filecontents}
% \UseBibLaTex is a variable that if is less than 1 the document
% will have to compiled with `bibTeX`... else with biber
\def\UseBibLaTeX{1}
% ``url'' package is used in order to make LaTeX to break the urls
% in places like the bibliography combined with the next (upcoming)
% command
%\usepackage{breakurl}
\usepackage[hyphens]{url}
\Urlmuskip=0mu plus 1mu minus 5mu
\ifnum\UseBibLaTeX>0
\usepackage[backend=biber,style=authoryear]{biblatex}
\addbibresource{myBib.bib}
\else
\usepackage{natbib}
\def\harvardurl#1{{\bfseries URL:}\space\url{#1}}
\fi
\begin{filecontents*}{myBib.bib}
@Article{cite1,
title={One Article with a url that has to break both in bibtex and biblatex},
author={Someone NotMe and Someother Me},
year={2018},
month={10},
url={http://A-long-URL-that-has-to-break-through-lines-and-biber-has-to-ignore-the-url-command},
doi={http://dx.doi.org/10.1038/nphys1170}
}
@Article{cite2,
title={One Article with another url that has to break both in bibtex and biblatex},
author={Someone NotMe and Myself Me},
year={2017},
month={10},
url={http://AlongUrlThatHasToBreak.ThroughlinesAndBoth.BiberAndBiblatex.HasToAcceptTheCitation.com},
doi={http://dx.doi.org/10.1038/nphys1170}
}
\end{filecontents*}
\title{Double Functionality about Bibliography}
\author{Konstantinos Leledakis}
\date{October 2018}
\begin{document}
\maketitle
\nocite{*}
\ifnum\UseBibLaTeX>0
\begin{sloppypar}
\printbibliography
\end{sloppypar}
\else
\bibliographystyle{agsm}
\begin{sloppypar}
\bibliography{myBib}
\end{sloppypar}
\fi
\end{document}
Output with bibtex:
Output with biblatex (biber):