2

I have a long line, which could be a url but is not always a url so I cant use url/burl package. I want to specify where to break (at &), and how to do it.

Long line:

long-example-url.com/foo.php?foofighter=bar&session=89c371a38aa60a9a59f46c9bbdc9fb2d&fun=yes

not long line:

long-example-url.com/foo.php?foofighter=bar      &session=89c371a38aa60a9a59f46c9bbdc9fb2d&fun=yes

insert a \ at the end of the line and indent at the next to indicate the break.

How do I do this? (the text is inside a framed and is using verbatim environment)

MWE:

\documentclass[11pt]{article}
\usepackage{framed}

\begin{document}

\begin{framed}
  \begin{verbatim}
    Example:

    long-example-url.com/foo.php?foofighter=bar&session=89c371a38aa60a9a59f46c9bbdc9fb2d&fun=yes
  \end{verbatim}
\end{framed}

\end{document}
2
  • Welcome to TeX.sx! Usually, we don't put a greeting or a “thank you” in our posts. While this might seem strange at first, it is not a sign of lack of politeness, but rather part of our trying to keep everything very concise. Accepting and upvoting answers is the preferred way here to say “thank you” to users who helped you. Please always try to supply a minimal working example (MWE) we can play with.
    – masu
    Oct 24, 2013 at 8:36
  • 4
    verbatim doesn't allow line breaks: it's supposed not to, since it's for reproducing code listings.
    – egreg
    Oct 24, 2013 at 9:09

2 Answers 2

1

I put the following line in my Praeamble on top of using the url-package:

\renewcommand{\UrlBreaks}{\do\/\do\+}

after each \do, you can specify one sign, where the url shall break.

Maybe it helps.

1

Reconsidering my answer one more time. You can use the listings package for this, but it can break before AND after the characters from the group other. So it will be broken off after the & sign, not before.

\documentclass{minimal}

\usepackage{listings}
\usepackage{xcolor} % coloring only

\begin{document}

\newcommand\brch{\textbackslash}

\lstset{%
    alsoletter={0123456789=},
    breakatwhitespace=false,
    breaklines,
    breakautoindent=true,
    breakindent=20pt,
    prebreak=\raisebox{0ex}[0ex][0ex]{\color{green}\textbackslash},
}

\begin{lstlisting}
long-example-url.com/foo.php?foofighter=bar&session=89c371a38aa60a9a59f46c9bbdc9fb2d&fun=yes
\end{lstlisting}

\end{document}

The only painful stuff is to specify the alsoletter option. I've just asked a question about the automatization of that.

You must log in to answer this question.

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