0

I have a named link within my document. I want to allow line breaks of the text at an arbitrary position, preferred at some common know position but if it won't work out than at any kind of position.

While for the \url command there are some packages out (e.g. xurl) I haven't found a solution when using \hyperlink.

\documentclass[a4paper,11pt,british]{article}
\usepackage[margin=2.5cm, showframe]{geometry}
\usepackage[tracking=true,factor=1100,stretch=10,shrink=10,final]{microtype} 
\usepackage{fontspec}
\directlua{luaotfload.add_fallback("fntFallback",{
    "DejaVu Sans:mode=harf",
    "NotoColorEmoji:mode=harf"})}
\setmainfont{Liberation Sans}
\usepackage{hyphenat}
\usepackage{xurl} 
\urlstyle{same}
\usepackage[pdfa, unicode, breaklinks]{hyperref}
\begin{document}
The labour participation rate in my own country is estimated to be 99.9\% in 2019 (%
\hyperlink{abc}{ILO/CSO/KRSO 2020})\newline
The labour participation rate in my own country is estimated to be 99.9\% in 2019 (%
\url{ILO/CSO/KRSO 2020})\newline

\hypertarget{abc}{sample anchor text}
\end{document}

enter image description here

I'm using lualatex 1.17.0 with hyperref 2023-02-07 v7.00v.

4
  • that is simply text, so everything that allows a line break works, e.g. {ILO/CSO/KR\hspace{0pt}SO 2020}. Jan 16 at 18:30
  • Well then I need to take care on my own. Isn't there an automatic solution similar to xurl?
    – LeO
    Jan 16 at 19:05
  • there are various packages around to split a string at some arbitrary place see e.g. tex.stackexchange.com/q/324042/2388 or tex.stackexchange.com/a/595035/2388. It depends a lot on what you actually want and which chars will be in your string (e.g. non-ascii will not work well with url-like commands.) Jan 17 at 9:40
  • @UlrikeFischer: Thank you for the various links you've sent. I finally found the tex.stackexchange.com/a/422570/48642 which fits best since I have as well arbitrary text included. I was not aware that this might have an influence. Thx very much again!
    – LeO
    Jan 18 at 12:08

1 Answer 1

1

You can use the same line breaking as \url for example

\hyperlink{abc}{\path{ILO/CSO/KRSO 2020}})

\path is like \url but doesn't make a link. By default it uses \texttt but as with \url you can specify the font to use, by default it's defined via

\DeclareUrlCommand\path{\urlstyle{tt}}

2
  • Ahhh... Thx... I'll try tomorrow - this sounds promising ☺️
    – LeO
    Jan 16 at 19:39
  • After trying many different approaches I have to admit I'm getting lost between different solutions. Using the path command solves somehow the problem but opens others. First of all the whitespace - but this could be handled with the option of obeyspaces. The other (main) problem is how to use special chars like #@%? By escaping them I can compile the TeX code but the the text has `\` included. Is there a way to resolve it?
    – LeO
    Jan 18 at 16:00

You must log in to answer this question.

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