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

Mico
  • 506,678
Ommo
  • 835
  • 4
    One classical alternative is \usepackage{xurl}. – gusbrs Mar 01 '23 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 Mar 01 '23 at 14:50
  • Thanks a lot to both! It works perfectly! If you write your comment(s) in the "Answer" section, I will accept the Answer! – Ommo Mar 01 '23 at 16:05
  • 1
    @gusbrs would you provide an answer? – daleif Mar 01 '23 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 Mar 01 '23 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 Mar 02 '23 at 08:12
  • @daleif It's stretching things a bit, but I guess it's what can be done, short of using a different style. But, go ahead, since you found a way to make it work. – gusbrs Mar 02 '23 at 12:17

1 Answers1

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.

daleif
  • 54,450