6

Considering the following verbatim:

\begin{verbatim}
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
\end{verbatim}

How to make sure that the verbatim text is not going out of the page, but going on the following line as soon as the width of the page has been passed?

Please note that I am looking for a solution without the listing package.


EDIT (to describe my problem a bit more)

I am having a long report in which I use a lot verbatim. From time to time, the text of the verbatim is going out of the page. Furthermore, I do use the listing package with box for some special programming code. I would like to keep the same verbatim format, but with auto "end of line" for the verbatim code. Is there a simple way for doing it?


EDIT 2

if you take the following verbatim with a very long string :

\begin{verbatim}
$ mylinuxcommand 
!+.++++.....+++-+++-!^!^+............................................;+++-^^!--.........+++--!^!^+.++++.....+++-+++-^!^+............................................;+++-^^!--.........+++--!^!^+.++++.....+++-+++-!^!^+............................................;+++-^^!--.........+++--!^!^
$ myotherlinuxcommand
true
$ mylastcommand
"Thank you for your help"
\end{verbatim}

On your pdf, only a part of this string is displayed (It stays on the same line, it's "continuing" out of the page). As on below (pdf dislay) :

$ mylinuxcommand

!+.++++.....+++-+++-!^!^+............................................;+++-^^!-

$ myotherlinuxcommand

true

$ mylastcommand

"Thank you for your help"

I wish it could go on the next line automatically, so that all the content of this long string is displayed. The displayed result would give, on the pdf (pdf display):

$ mylinuxcommand

!+.++++.....+++-+++-!^!^+........................................

....;+++-^^!--.........+++--!^!^+.++++.....+++-+++-^!^+......

.....................................;+++-^^!--.........+++--

!^!^+.++++.....+++-+++-!^!^+.................................

...........;+++-^^!--.........+++--!^!^

$ myotherlinuxcommand

true

$ mylastcommand

"Thank you for your help"

So that the entire long string from the verbatim is displayed on the pdf. A long string should be automatically cut when it reaches the width of the page, and the rest recursivally displayed on the other line. Please note that this long string can change, but globally the structure and chars used remain the same.

17
  • 1
    That wouldn't be verbatim, which is about representing “exactly” the input. Can you make a more realistic example?
    – egreg
    Commented Oct 13, 2013 at 10:05
  • You guessed right; that's why I'm asking for a “real world” example, so we can point to a better solution for your needs.
    – egreg
    Commented Oct 13, 2013 at 10:11
  • Please, take a look at tex.stackexchange.com/questions/113906/…
    – user13907
    Commented Oct 13, 2013 at 10:21
  • I do not see how the link solve my issue. Could you please show me how it actually does? Thank you. (It looks way to complicated for the issue I am facing?)
    – Martingal
    Commented Oct 13, 2013 at 10:37
  • 1
    I really do not understand WHY it is considered as duplicate ! I don't understand what is the link between these 2 topics! I think it is quite unfair.
    – Martingal
    Commented Oct 13, 2013 at 14:05

1 Answer 1

7

You can do with the help of the verbatim command and some low level hackery:

\documentclass{article}
\usepackage{verbatim}
\newenvironment{spverbatim}
 {\verbatim\splitchars}
 {\endverbatim}
\newcommand{\splitchars}{%
  \definesplitchar{\!}%
  \definesplitchar{\.}%
  \definesplitchar{\+}%
  \definesplitchar{\-}%
  \definesplitchar{\^}%
  \definesplitchar{\;}%
}
\newcommand{\definesplitchar}[1]{%
  \begingroup\lccode`~=`#1\relax
  \lowercase{\endgroup\def~}{\char`#1\hspace{0pt plus 0.1pt minus 0.1pt}}%
  \catcode`#1=\active
}

\begin{document}
\begin{spverbatim}
$ mylinuxcommand 
!+.++++.....+++-+++-!^!^+............................................;+++-^^!--.........+++--!^!^+.++++.....+++-+++-^!^+............................................;+++-^^!--.........+++--!^!^+.++++.....+++-+++-!^!^+............................................;+++-^^!--.........+++--!^!^
$ myotherlinuxcommand
true
$ mylastcommand
"Thank you for your help"
\end{spverbatim}
\end{document}

enter image description here

1
  • 1
    THANK YOU VERY MUCH FOR YOUR HELP AND YOUR CONTINUOUS SUPPORT. It works pretty good! Enjoy your sunday, and thank you again ;)
    – Martingal
    Commented Oct 13, 2013 at 14:40

You must log in to answer this question.

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