TeX - LaTeX Asked on March 2, 2021
I am using latex-dvips-ps2pdf
steps with -Ppdf
option passed to dvips
. The following code snippet
documentclass{article}
usepackage[colorlinks]{hyperref}
usepackage{breakurl}
hypersetup{pdfborder={0 0 100}}
defemailA{url{[email protected]} }
defemailB{url{[email protected]} }
begin{document}
emailA or emailB or emailB or emailA or
emailA or emailB or emailB or emailA or
emailA or emailB or emailB or emailA or
emailA or emailB or emailB or emailA or
emailA or emailB or emailB or emailA or
emailA or emailB or emailB or emailA or
emailA or emailB or emailB or emailA or
end{document}
produces the output as follows.
Is there any trick to fix it?
Even with the help of the breakurl
package, your example will produce overfull boxes. This is because breakurl
will only break urls after one of the following symbols :/.?#&_,;!
and before any ocurrence of the symbol %
.
To overcome this you have two possibilities: to use sloppy
(which will make the spacing look really awful) or to manually insert some spaces in the appropriate places to help the package find a proper break-point for the urls.
In the following example I show a reduced version of your example with three variants: the first one shows the default output obtained with breakurl
; in the second one, I manually inserted some hspaces
, and in the third one I used sloppy
. It's up to you to decide which of the two last approaches looks less ugly and is more practical.
I used draft
to see the overfull boxes more clearly. The code must be compiled through latex.
documentclass[draft,10pt]{article}
usepackage[colorlinks]{hyperref}
usepackage{breakurl}
hypersetup{pdfborder={0 0 100}}
defemailA{url{[email protected]} }
defemailB{url{[email protected]} }
begin{document}
The example:
emailA or emailB or emailB or emailA or
emailA or emailB or emailB or emailA or
emailA or emailB or emailB
vspace{1cm}
The example with verb+hspace+s manually inserted:
hspace*{-4pt}emailA or emailB or emailB or emailAhspace{3pt} orhspace{4pt}
emailA or emailB or emailB or emailA or
emailA or emailBhspace{3pt} orhspace{3pt} emailB
vspace{1cm}
The example with verb+sloppy+:
begingroup
sloppy
emailA or emailB or emailB or emailA or
emailA or emailB or emailB or emailA or
emailA or emailB or emailBpar
endgroup
end{document}
Correct answer by Gonzalo Medina on March 2, 2021
Try this.
documentclass{article}
usepackage[breaklinks=true]{hyperref}
begin{document}
If you have any questions, please don't hesitate to contact me
at url{mailto:[email protected]}.
end{document}
With href
, you need to use nolinkurl
in the second argument.
href{mailto:[email protected]}{nolinkurl{[email protected]}}
Answered by Ian Thompson on March 2, 2021
Have a look at the breakurl
package -- page 1 of the documentation includes the answer to your question.
Answered by lockstep on March 2, 2021
I finally found a solution, that might be of interest to all the ones having problems with displaying long URLs in LaTeX:
I had a little chat with Vilar (the maintainer of the breakurl
-package) and he was able to extend the breaking possibilities of his package they way I suggested.
Therefore the new option anythingbreaks
in the newest version does the links look good as they keep in range of the textborder.
See for yourself:
Completely without:
Standard behavior:
Anythingbreaks:
Look also at my question here: Biblatex: URL-breaking not working in DVI-mode
Answered by MrD on March 2, 2021
Add
Lazy answer, but it's working for me, and I'm new in latex:
BEFORE:
url{http://www.mma.gov.br/port/conama/processos/C1CB3034/DECRETO_SAO_PAULO_59113_2013.pdf}
AFTER:
url{http://www.mma.gov.br/port/conama/processos/C1CB3034/DECRETO_SAO_PAULO_59113_2013.pdf}
Answered by Sergio on March 2, 2021
I found 2 solutions for breaking long URLs.
The first one unfortunately doesn't work with hyperref
.
usepackage[hyphens]{url}
This will break long URLs after hyphens, which is mostly ok. But since hyperref
uses url
somehow, there's a conflict activating the hyphens
-option
! LaTeX Error: Option clash for package url.
If somebody has an explanation (or solution) for me, I'd be glad.
The second solution works fine. I haven't researched it intensely, yet. But it should be a clean solution as only the characterlist for linebreaking is manipulated an neither measures nor mechanisms are influenced. (I'd appreciate it, if someone could verify this.)
usepackage{hyperref}
%or usepackage{url}
usepackage{etoolbox}
apptoUrlBreaks{do-}
The last line adds the hyphen to the list of characters after which an URL is allowed to break. You can expand the list by adding "dos" like {doadobdoc}
(This would allow URLs to break after a, b, and c, too.)
There's also a list UrlBigBreaks
. But I haven't checked it out, yet.
Answered by queuverflow on March 2, 2021
You can use the href function twice (or as many times as you link), both linking to the same URL, but the first with the text you want to appear on the first line, and the second with the text you want to appear on the second line. In other words, you decide where the line break occurs. A bit of a bodge but works well for me:
(href{Full URL}{underline{Text up to the end of line 1}} href{Full URL}{underline{Text for the start of line 2}})
Answered by Alison on March 2, 2021
RequirePackage[bookmarks, bookmarksopen=true, plainpages=false, pdfpagelabels, pdfpagelayout=SinglePage, breaklinks = true]{hyperref}
href{https://tex.stackexchange.com/a/576098/147162}{Link to this answer!}}
Answered by Miladiouss on March 2, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP