How to carry long text of \href to the next line while ocgcolorlinks is present?
\usepackage{hyperref} \usepackage[ocgcolorlinks]{ocgx2}[2017/03/30]
Package ocgx2
, as of version 0.24, re-implements the ocgcolorlinks
option of hyperref
, based on B. Lerner's code with some refinements:
Besides OCG colour links that wrap around line breaks, also wrapping at page breaks and nested hyperlinks are supported (only pdfLaTeX/LuaLaTeX, as XeTeX does not support nested links at all), and the issue with empty link text has been resolved.
Example code (open on ShareLaTeX):
\documentclass[a6paper]{scrartcl}
\usepackage{hyperref}
\usepackage[ocgcolorlinks]{ocgx2}[2017/03/30]
\usepackage{mwe,graphicx}
\begin{document}\raggedright\huge
Empty links $\Rightarrow$\href{https://tex.stackexchange.com}{\qquad}$\Leftarrow$ don't flood the page with link colour.\\[2ex]
Visit \href{https://ctan.org/tex-archive/macros/latex/contrib/ocgx2}{ocgx2 ocgx2 ocgx2 ocgx2 ocgx2 ocgx2 ocgx2 ocgx2 ocgx2 ocgx2 ocgx2 ocgx2 ocgx2 ocgx2 ocgx2 ocgx2 ocgx2 ocgx2 \hypersetup{urlcolor=red}\href{https://ctan.org}{on CTAN CTAN CTAN CTAN CTAN CTAN CTAN CTAN CTAN CTAN CTAN CTAN CTAN CTAN CTAN CTAN} ocgx2 ocgx2 ocgx2 ocgx2 ocgx2}!\\[2ex]
{
\normalsize Graphical content, if mixed with text inside the link text, must be protected by enclosing in \verb+\ocglinkprotect{...}+:\\[1ex]
}
Visit \href{https://ctan.org/tex-archive/macros/latex/contrib/mwe}{this fancy \ocglinkprotect{\includegraphics[width=1cm]{example-image}} on CTAN!}
\end{document}
Option ocgcolorlinks
does not support links that can be broken across lines. From hyperref
's README:
- Main disadvantage: Links cannot be broken across lines. PDF reference 1.7: 4.10.2 "Making Graphical Content Optional": Graphics state operations, such as setting the color, ..., are still applied. Therefore the link text is put in a box and set twice, with and without color.