Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I use \begin{verbatim} and \end{verbatim} and have enclosed a Fortran code within it. (I am not using listing for a reason).

However, Verbatim is crossing the boundaries. enter image description here

How do I fix this?

My packages list is:

\documentclass[12pt,a4paper]{article}
\usepackage[latin3]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{listings}
\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}
share|improve this question
1  
Given that it is using a monospace font you either need to keep your fortran lines shorter than the number of characters that fit, or use a smaller font. eg put \small before the verbatim environment. –  David Carlisle Mar 20 '12 at 15:24
    
Isn't there a possibility of it doing the linebreaks automatically? Its a long document, I don't want to sit and find each instance of this. –  user10961 Mar 20 '12 at 15:25
2  
verbatim means obey linebreaks so it turns off all line wrapping (which for fortran is a good thing as the code will be wrong if line wrapped without adding continuation markers) If you don't mind the code having invalid breaks then perhaps you want alltt rather than verbatim. I note you include listings which has a breaklines option,you didn't give your reason for not using listings –  David Carlisle Mar 20 '12 at 15:30
    
How do I use alltt? –  user10961 Mar 20 '12 at 15:39
    
it's part of the base latex distribution: input alltt package then use alltt env instead of verbatim, but you have to take more care of special characters in that case. You should have the package documentation on your system. –  David Carlisle Mar 20 '12 at 15:45
show 1 more comment

1 Answer

up vote 3 down vote accepted

You are loading the listings package hence use key breaklines=true and \begin{lstlisting}...\end{lstlisting}.

\documentclass{article}
\usepackage{xcolor,listings}
\lstloadlanguages{[LaTeX]TeX, [primitive]TeX,fortran}
\lstset{language={[LaTeX]TeX},
      escapeinside={{(*@}{@*)}}, 
       gobble=0,
       stepnumber=1,numbersep=5pt, 
       numberstyle={\footnotesize\color{gray}},%firstnumber=last,
      breaklines=true,
      framesep=5pt,
      basicstyle=\small\ttfamily,
      showstringspaces=false,
      keywordstyle=\ttfamily\textcolor{blue},
      stringstyle=\color{orange},
      commentstyle=\color{black},
      rulecolor=\color{gray!10},
      breakatwhitespace=true,
      showspaces=false,  % shows spacing symbol
      backgroundcolor=\color{gray!15}}
\begin{document}

\begin{lstlisting}
a very long and totruous path which you can check to see if it breaks and where at the end of the line
\end{lstlisting}

\end{document}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.