Wrap URL (ignores margin) in BibTeX using pdfLaTeX - url

I'm using the breakurl package and the hyperref package with pdfLatex and BibTeX to cite a url. The url is breaking, but not according to my margins. Is there any way I can make the url recognize my margins or force a line break? Thanks in advance.
Code:
\usepackage{hyperref}
\usepackage[vertfit]{breakurl}
#MISC{cmm:dataset,
author = {University of Bristol Centre for Multilevel Modelling},
title = {Datasets used in reviews},
howpublished = {\url{http://www.cmm.bristol.ac.uk/learning-training/multilevel-m-software/exam.shtml}},
}

Sometimes, when LaTeX cannot break lines nicely, it leaves them unadjusted. You can control that behavior putting \sloppy at the beginnig of your document and see if the behavior suits you more. Also, you have spaces in your URL, as I've seen in your post. Remove them. The url package usuallly does a nice job breaking urls (I have not used the breakurl package and my URLs break nicely by the slashes or dashes).

Better to add 'breaklinks' to the options for hyperref or if using url explicitly format the url in the bibtex file "\url{http:....}". This fixed the problem for me. You may still need to redefine the format for the url if the default box does not suit your purposes.

Related

How to set title of TOC in Latex hyperref package

The latex hyperref package makes a really nice, linked table of contents, named according to section name. However, the top level category is by default, the file name. It seems I should be able to change this to the actual title, but I'm not finding any information on how.
Are you sure this is not a 'feature' of your PDF reader? It might try to use the PDFs title (unset by default), which you can set like this:
\hypersetup{
pdftitle = {The title},
pdfauthor = {You}
}
You might also want to check out the TeX StackExchange.

LaTeX: Cite, but don't reference

I'm producing a set of documents in LaTeX, and I would like to provide a single, global bibliography page for the whole set. This is because each document is page-limited: I don't want to take up space with references at the bottom of each one.
This means in each case, I would like to cite in the text, but not produce a reference at the end. I am using bibtex/natbib to handle the referencing.
Simplest example:
\documentclass[]{article}
\bibliographystyle{/usr/share/texmf/bibtex/bst/natbib/plainnat.bst}
\usepackage{natbib}
\begin{document}
In \citet*{MEF2010} I described the method.
\bibliography{bibliography.bib}
\end{document}
How can I do this? Essentially I just want it to cite correctly:
In Bloggs, Blagg and Blog (2010) I described the method.
But not add a references section at the end. Any ideas?
Thanks,
David
Instead of using \bibliography{bibliography.bib} you can try \nobibliography{bibliography.bib}.
You still need to enter the path so it can make the cross-references.
It happens due to missing packages. If you want to resolve the problem then enable the automatic installation packet. After that,First, you run the BibTeX file and generate the Pdf file (instead of pdfLatex file) and then pdfLatex to Pdf

linebreak in url with Bibtex and hyperref package

Why is this item not shown properly in my bibliography?
#misc{ann,
abstract = {ANN is an implbmentation of nearest neighbor search.},
author = {David M. Mount and Sunil Arya},
howpublished = {\url{http://www.cs.umd.edu/~mount/ANN/}},
keywords = {knn},
posted-at = {2010-04-08 00:05:04},
priority = {2},
title = {ANN.},
url = "http://www.cs.umd.edu/~mount/ANN/",
year = {2008}
}
#misc{Nilsson96introductionto,
author = {Nilsson, Nils J.},
citeulike-article-id = {6995464},
howpublished = {\url{http://robotics.stanford.edu/people/nilsson/mlbook.html}},
keywords = {*file-import-10-04-11},
posted-at = {2010-04-11 06:52:28},
priority = {2},
title = {Introduction to Machine Learning: An Early Draft of a Proposed Textbook.},
year = {1996}
}
EDIT:
I am using
\usepackage{hyperref}
not
\usepackage{url}
. It produces error when using url package together with it. So can the two not work together?
I would like to use hyper links inside pdf file, so I want to use hyperref package instead of url package. I googled a bit, and try
\usepackage[hyperindex,breaklinks]{hyperref}
but there is still no line break just as before. How can I do it?
EDIT:
When using url and hyperref together,
if it is just
\usepackage{hyperref}
\usepackage{url}
the compilation by latex is fine, but the link is still hyperlink and has still no linebreak. If I do not use hyperref package, the link has linebreak, but I lose hyper links. Since \url can be used in both hyperref and url packages, how can I specify which package's \url is being used?
If it is
\usepackage{hyperref}
\usepackage[hyphens]{url}
the compilation by latex command will report clash with url:
! LaTex Error: Option clash for package url.
So I wonder how I should do?
You should use them in this order:
\usepackage[hyphens]{url}
\usepackage{hyperref}
You get this error when you use them the other way around.
! LaTex Error: Option clash for package url.
since the hyperref package loads the url package somewhere internally without that hypens option, and then you want to load it with the option, so it clashes.
Turning the order around does what you want and does not give this error (since the package is already loaded hyperref won't load it again with different options)
edit: this was with pdftex, I did not test with other tools.
edit2:
or as mentioned by PatrickT in a comment: \PassOptionsToPackage{hyphens}{url} if you're using a class that already loads the package, e.g. beamer.
I just ran across almost the same problem and found it solved by putting
\PassOptionsToPackage{hyphens}{url}
before the
\usepackage[...]{hyperref}
If you mean the too-wide spacing, that's because the URLs seems to not allow line-breaks. Why this happens is another question, and the answer depends on your preamble (the packages you use etc.). In principle, if properly used, the url package should allow line breaks.
EDIT
This problem (and its solution) is described here (sending you to a Google cache since the site is offline at the moment). Bottom line: either use the breakurl package, or PDFLaTeX, or both.
Weird, I load the url package (with no option) and hyphenation is done at the slashes / if needed.
Anyway, simple workaround:
howpublished = {\url{http://www.cs.umd.edu/}\url{~mount/ANN/}},
Manual job, but it splits up the URL yes or yes.
for me only this worked:
\usepackage[hyphens]{url}
\usepackage{hyperref}
...
\usepackage{biblatex}
\setcounter{biburlnumpenalty}{100}
\setcounter{biburlucpenalty}{100}
\setcounter{biburllcpenalty}{100}
Taken from: https://tex.stackexchange.com/questions/22854/url-line-breaks-with-biblatex
Normally URLs are hyphenated, but in your bibliography they seem not to be. When the URLs don't fit on one line, they are moved to the next line, and the text before them is stretched to fill out the preceding lines. Since there is only one place to break the line, it's not very likely that the preceding text will fit nicely into a whole number of lines, and so you get all the extra space.
EDIT: When you changed your bib entry, you happened to change it in such a way that the text did fit nicely. This is just a coincidence, you didn't fix your problem.
I suspect that putting
\usepackage{url}
in your preamble will solve it.
If url package doesn't help, try:
\usepackage{xurl}
\usepackage{hyperref}
Package xurl is an expanded version of url, which allows line breaking at every point in the url. Call xurl before hyperref.
Source: Does the hyperref breaklinks option have any effect?
I add this package:
\usepackage[hyphens]{url}
and in the bibtex I used:
howpublished = {**\url{**http://www.......**}**}
and it works out.
This simple solution worked for me:
\usepackage{hyperref}
\usepackage{breakurl}
The URLs are now perfect.
At the preamble, just put \usepackage{breaker} somewhere after \usepackage{hyper ref}. The \burl command is defined and, by default, the package also turns the \url command into a synonym of \burl.

URL latex linebreak

When a URL is over a line and goes onto a second line, the hyperlink only uses the first line. Is there a way to get around this and yet still have the URL on multiple lines?
You should use the url package:
\usepackage{url}
...
\url{http://long.url.com/... .../stuff}
and it will break it for you at an appropriate place.
I suggest using package:
\usepackage{xurl}
This works fine for me on overleaf.
Example:
\url{https://www.tudelft.nl/ewi/over-de-faculteit/afdelingen/intelligent-systems/pattern-recognition-bioinformatics/pattern-recognition-laboratory/data-and-software/dd-tools/}
At the preamble, just put \usepackage{breakurl} somewhere after \usepackage{hyperref}. The \burl command is defined and, by default, the package also turns the \url command into a synonym of \burl.
Do it the following way. You are good to go!
\begin{document}
\sloppy
For me only this worked:
\PassOptionsToPackage{hyphens}{url}
\usepackage{hyperref}
and with this code to add line breaks after every normal alphabetic character and with *-~'":
\expandafter\def\expandafter\UrlBreaks\expandafter{\UrlBreaks% save the current one
\do\a\do\b\do\c\do\d\do\e\do\f\do\g\do\h\do\i\do\j%
\do\k\do\l\do\m\do\n\do\o\do\p\do\q\do\r\do\s\do\t%
\do\u\do\v\do\w\do\x\do\y\do\z\do\A\do\B\do\C\do\D%
\do\E\do\F\do\G\do\H\do\I\do\J\do\K\do\L\do\M\do\N%
\do\O\do\P\do\Q\do\R\do\S\do\T\do\U\do\V\do\W\do\X%
\do\Y\do\Z\do\*\do\-\do\~\do\'\do\"\do\-}%
answer complited from this site:
https://tex.stackexchange.com/questions/3033/forcing-linebreaks-in-url/10401
What packages (hyperref,url) and drivers (pdftex, dvips, etc.) are you using? Are you using the breaklinks option to hyperref?
According to the TeX FAQ you might want to try the breakurl package, though it appears you may simply be out of luck in some cases.
What worked best for me (with pdflatex) was
\usepackage[pdftex]{hyperref}
and then just \url{http://stackoverflow.com/} to create URLs. It only broke URLs at . and /, which was okay for my document. Importantly, other approaches I tried created PDFs where only the first line of the URL was a clickable link, and the destination URL was truncated to this portion, which is pretty confusing and bad.
Long URLs that contain underscores (_) in path segments will not be broken when using \PassOptionsToPackage{hyphens}{url}\usepackage{hyperref}. However, I found that I could solve this problem by manually breaking lines in the displayed label using \\\\, like this:
\href{http://www.researchgate.net/profile/Nick\_Brooks2/publication/220012411\_Cultural\_responses\_to\_aridity\_in\_the\_Middle\_Holocene\_and\_increased\_social\_complexity/links/0922b4f398ad68bc96000000.pdf}{http://www.researchgate.net/profile/Nick\_Brooks2/publication/220012411\_\\Cultural\_responses\_to\_aridity\_in\_the\_Middle\_Holocene\_and\_increased\_social\_\\complexity/links/0922b4f398ad68bc96000000.pdf}
This results in URLs that are a bit prettier (IMO) than the use of \usepackage{breakurl} and \burl, as suggested by Debajyoti Mondal, and allows you to display the full URL if you wish.
There is a simple answer. Use \usepackage[hidelinks]{hyperref} before \begin{document}

LaTeX help with href

I am trying to create a hyperlink using LaTeX. When I use the command pdflatex to compile the file, I get an error.
The relevant lines of the document are:
\documentclass[12pt]{article}
\usepackage{hyperref}
\begin{document}
...
\href{http://www.cs.utah.edu/dept/old/texinfo/as/gprof_toc.html}{gprof}
pdflatex created a file called missfont.log, which contains this:
mktextfm pzdr
What am I doing wrong?
Do you have the pzdr font installed? If you're on Debian or Ubuntu, try installing the texlive-fonts-recommended package.
Does the hyperref package purport to make hyperlinks to arbitrary web pages? I thought it was just for intra-document links (which it does automatically). I would do
\usepackage{url}
and
\url{http://foo.com}
to format a URL in your document.
ADDED: Thanks Will, I didn't know that about href. But if you're creating a document that's mainly targeting paper as the intended medium, I think the url package for formatting URLs is the way to go. But if you think the href package subsumes the url package, I'd love to be set straight on that.

Resources