3

How to break url links that include long alphanumerical strings?

Here an example:

\documentclass[12pt,a4paper,twoside]{article}

\begin{filecontents}[overwrite]{ref.bib}
@misc{Reuters_2023,
  author = "Reuters",
  title  = "Example of long URL",
  year   = 2023,
  url    = "https://www.facebook.com/Reuters/posts/pfbid0Gw8qyhJSCCBeAzfVRXcV9aMBsy5pzmeTfbx2WeTmGySdpSYPBxtqJqkkuhDX9Fb9l",
}
\end{filecontents}


\usepackage{apacite}
\bibliographystyle{apacite}
\usepackage[hyphens,spaces,obeyspaces]{url}

\begin{document}
\cite{Reuters_2023}
\bibliography{ref}
\end{document} 

enter image description here

7
  • 4
    One classical alternative is \usepackage{xurl}.
    – gusbrs
    Commented Mar 1, 2023 at 13:57
  • 2
    As gusbrs say use xurl instead, this changes \url, which (hopefully) is used by the style you use, to allow linebreaks more or less everywhere. With all the long URLs we use nowadays it is better to use xurl.
    – daleif
    Commented Mar 1, 2023 at 14:50
  • 1
    @gusbrs would you provide an answer?
    – daleif
    Commented Mar 1, 2023 at 16:49
  • 2
    @daleif Mhm, except that I can't make it work. Apparently apacite does use \url, but has its own url breakpoints settings. So, anyone who can make it work, please feel free to answer.
    – gusbrs
    Commented Mar 1, 2023 at 18:10
  • 2
    @gusbrs you're right, I don't think one can use xurl with apacite in its current form. (But since apacite looks for loaded url at begin document, one could delay xurl: \AtBeginDocument{\usepackage{xurl}} loaded after apacite, that does seem to work)
    – daleif
    Commented Mar 2, 2023 at 8:12

1 Answer 1

4

The apacite package detects url being loaded and then changes it. Thus any changes made by xurl might be gone. However, if we instead loads xurl via

\usepackage{apacite}
\AtBeginDocument{\usepackage{xurl}}

instead of loading url, xurl is actually loaded after apacite's check for url and its changes are never applied.

It is a bit hackish... Also note that apacite does not seem to have been updated in almost 10years, so no wonder it has no support for xurl.

1
  • 1
    I am very grateful, thanks a lot to you and to @gusbrs!!! :-)
    – Ommo
    Commented Mar 2, 2023 at 13:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .