[Tex/LaTex] How to wrap a URL or Reference

hyperref

In a LuaLaTeX book document with Koma Script I have two problems with Hyperref (which may are one):

sampel.bib

@online{Writ:Title,
author = {Writ, R.},
title = {Title},
date = {2005},
url = {http://www.blabliblabla.com/filefolder/folder_folder/folder/R._Schreib_AVery_-_LongTitle_That_Shoud_Have_A_Break.pdf},
urldate = {2017-08-15}}

linkwrap.tex

\documentclass[a4paper,oneside,twocolumn]{scrbook}
\usepackage[ngerman]{babel}
\usepackage{blindtext}

\usepackage[backend=biber,style=apa]{biblatex}
\DeclareLanguageMapping{german}{german-apa}
\addbibresource{sampelbib.bib}

\usepackage[dvipsnames,svgnames,x11names,hyperref]{xcolor}
\PassOptionsToPackage{hyphens,obeyspaces,spaces}{url}
\usepackage[
    breaklinks=true,    
    allbordercolors=Maroon,
    ocgcolorlinks=true,
    colorlinks=true,
    anchorcolor=Maroon, 
    citecolor=Maroon,
    filecolor=Maroon,
    linkcolor=Maroon,
    menucolor=Maroon,
    runcolor=Maroon,
    urlcolor=Maroon,
    linktoc=all
]{hyperref}
\makeatletter
    \g@addto@macro{\UrlBreaks}{\do\/\do\-\do\_}
\makeatother

\begin{document}
\chapter{A Chapter}
Some sample text from \textcite{Writ:Title} with a link to the Chapter \ref{Too Long Reference}. \nameref{Too Long Reference} \blindtext[1]

\chapter{Another Chapter With A Too Long Text For A Nice Reference}
\label{Too Long Reference} 

\onecolumn
\printbibliography

\end{document}

When creating a PDF I get this:
enter image description here

What do I have to change to get wrapped the url and chapter link?

Best Answer

ocgcolorlinks option of the hyperref package prevents links from wrapping around line and page breaks. Instead, try the ocgx2 package with an improved ocgcolorlinks implementation.

It seems though, that the apa style has some bug related to underscores in urls. Replacing it with authoryear gives the following result:

enter image description here

\documentclass[a4paper,oneside,twocolumn]{scrbook}
\usepackage[ngerman]{babel}
\usepackage{blindtext}

%\usepackage[backend=biber,style=apa]{biblatex}
\usepackage[backend=biber,style=authoryear]{biblatex}
%\DeclareLanguageMapping{german}{german-apa}
\addbibresource{sampelbib.bib}

\usepackage[dvipsnames,svgnames,x11names,hyperref]{xcolor}
\PassOptionsToPackage{hyphens,obeyspaces,spaces}{url}
\usepackage[
    breaklinks=true,    
    allbordercolors=blue,
%    ocgcolorlinks=true,
    colorlinks=true,
    anchorcolor=blue, 
    citecolor=blue,
    filecolor=blue,
    linkcolor=blue,
    menucolor=blue,
    runcolor=blue,
    urlcolor=blue,
    linktoc=all
]{hyperref}
\makeatletter
    \g@addto@macro{\UrlBreaks}{\do\/\do\-\do\_}
\makeatother

\usepackage[ocgcolorlinks]{ocgx2}

\begin{document}
\chapter{A Chapter}
Some sample text from \textcite{Writ:Title} with a link to the Chapter \ref{Too Long Reference}. \nameref{Too Long Reference} \blindtext[1]

\chapter{Another Chapter With A Too Long Text For A Nice Reference}
\label{Too Long Reference} 

\onecolumn
\printbibliography

\end{document}
Related Question