TeX - LaTeX Asked by Bee on February 2, 2021
In my dissertation I have a long URL containing many underscore characters as word separators (Wiki software did this). These URLs break at an underscore (good!), but too late, causing the line of text to extend into the margin. There is an earlier underscore, but the break doesn’t happen there. I’d rather have one line with shorter text, than one line that extends into the margin.
I’m using a document class particular to my school, derived from amsbook, which uses hyperref. I’ve read a lot of forum posts on similar issues, but (a) did not find one that exactly matched my problem (underscores breaking, but not at the best one), and (b) the solutions others suggested did not work for me: I tried passing the [hyphens] option, to no effect (as expected). I also tried the breakurl package, but my system uses pdflatex, which is not supported by breakurl.
I’d be very grateful for your advice – the school flagged my dissertation because these URLs protrude into the required margin, and I’ve run out of things to try. Last resort would be to show the URL as plain text and force other formatting – I’d like to avoid that.
My attempt at a MWE:
documentclass[hidelinks,12pt]{amsbook}
RequirePackage[bookmarks, bookmarksopen=true, plainpages=false, pdfpagelabels, pdfpagelayout=SinglePage, breaklinks = true]{hyperref}
begin{document}
chapter{Troubleshooting long URLs}
section{Test 1}
A complete list of participants and presentations can be found on the conference web site: url{http://ruraro.rintint.edu/events/shipshops/index.php/Perplexity_and_Action_-_an_Interdisciplinary_Approach_to_Rationale_Synchro_Theory}
end{document}
After compiling with pdflatex (actually, I’m using Sublime Text CTRL-B), the URL breaks twice: first after events/ and second after Interdisciplinary_ although I’d prefer if the second break occurred after an_ instead.
EDIT: Naively, to me the crux seems to be how LaTeX (and all the packages involved) choose at which underscore to break the URL! Why not at the last underscore before the end of the line (margin-wise)? Currently it breaks at the first underscore after the paragraph.
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 February 2, 2021
documentclass[hidelinks,12pt]{amsbook}
RequirePackage[bookmarks, bookmarksopen=true, plainpages=false, pdfpagelabels, pdfpagelayout=SinglePage, breaklinks = true]{hyperref}
begin{document}
chapter{Troubleshooting long URLs}
section{Test 1}
A complete list of participants and presentations can be found on the conference web site: href
{http://ruraro.rintint.edu/events/shipshops/index.php/Perplexity_and_Action_-_an_Interdisciplinary_Approach_to_Rationale_Synchro_Theory}%
{texttt{http://ruraro.rintint.edu/events/shiplinebreak shops/index.php/Perplexitystring_andstring_Actionstring_-string_anstring_Interdisciplinalinebreak rystring_Approachstring_tostring_Rationalestring_Synchrostring_Theory}}
end{document}
Answered by David Carlisle on February 2, 2021
Put the url on a separate paragraph and use a parbox
. It also works within a list:
documentclass[hidelinks,12pt]{amsbook}
RequirePackage[bookmarks, bookmarksopen=true, plainpages=false, pdfpagelabels, pdfpagelayout=SinglePage, breaklinks = true]{hyperref}
usepackage{enumitem}
begin{document}
chapter{Troubleshooting long URLs}
section{Test 1}
A complete list of participants and presentations can be found on the conference web site: medskip
noindent%
parbox{linewidth}{url{http://ruraro.rintint.edu/events/shipshops/index.php/Perplexity_and_Action_-_an_Interdisciplinary_Approach_to_Rationale_Synchro_Theory}}
begin{itemize}[leftmargin = 1.6parindent, before = bigskip]
itemparbox[t]{dimexprlinewidth-leftmarginrelax}{url{http://ruraro.rintint.edu/events/shipshops/index.php/Perplexity_and_Action_-_an_Interdisciplinary_Approach_to_Rationale_Synchro_Theory}}
end{itemize}
end{document}
Answered by Bernard on February 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