Featured Book

LaTeX Beginners Guide

Who is online

In total there are 5 users online :: 0 registered, 0 hidden and 5 guests (based on users active over the past 5 minutes)
Most users ever online was 1327 on Tue Nov 05, 2013 7:11 pm

Users browsing this forum: No registered users and 5 guests

Partner Sites

TeXwelt - Fragen und Antworten goLaTeX
TeXblog
TeXnicCenter
TeXample

verbatim | Verbatim Environment causes critical Errors Topic is solved

Add tags Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)

verbatim | Verbatim Environment causes critical Errors

Postby Puppy on Thu Jun 21st, 2012

Hi, this is my first post regarding LaTeX problems. If I forgot to include any important information please ask so I can provide it.

My problem has to do with the verbatim and the listing packages. I use MiKTeX 2.9 with TechnicCenter RC1 stable version.

My document looks like this:
Code: Select all  •  Open in writeLaTeX
\documentclass[a4paper,12pt]{article}
\usepackage{a4wide
}%papierrand
\usepackage{graphicx}
\usepackage{graphics}
\usepackage{german}
\usepackage{float}
\usepackage[latin1]{inputenc
}%latin1 inputenc gibt das ß und die umlaute her
\usepackage{amsmath}%formelnumerierungen und anordnungszeugs
%\usepackage[Ausrichtung]{floatflt}%bilder mit text umzu
\usepackage[T1]{fontenc}
\usepackage{url}
\usepackage{subfigure}
\usepackage{setspace
} %1.5 facher zeilenabstand
\onehalfspacing                         %1.5 facher zeilenabstand
\usepackage[left=3cm,right=3cm,top=2cm,bottom=2cm]{geometry}
\def\bra#1{\ensuremath{\langle{#1}\vert}}
\def\ket#1{\ensuremath{\vert{#1}\rangle}
}
%\usepackage{hyperref}
\usepackage{url}
\usepackage[pdffitwindow=true, pdftex]{hyperref}
\usepackage{color
}
%\usepackage{listings} 
\usepackage{verbatim}
\begin{document}

...
\input{bla.tex}
.
.
.
\input{appendix.tex}
\end{document
}

In the appendix.tex is a verbatim environment which I want to use since listings produce only errors with any kind of matlab code I want to include. none of the errors are known anybody else. So i though ok screw you nicely formated text, you will be just black and white. and now this:

-appendix.tex-

Code: Select all  •  Open in writeLaTeX
\section{Anhang}
\subsection{Matlab Code zur Ermittlung des Drifts der Verstärker}
\begin{verbatim
}
clear all
close all
clc

%opa129u
dat=load('../Messdaten/opa129u_rauschneu2.txt');
plot(1:length(dat),dat(:,2)*10^3)
std(dat(:,2))
rms=sqrt(sum((dat(:,2)-mean(dat(:,2))).^2)/length(dat))
n=0
for i=1:600:length(dat(:,2))
    n=n+1;
    if i+1200>=length(dat(:,2)) break
    end
drift(n)=mean(dat(i+600:i+1200,2))-mean(dat(i:i+600,2));
end
figure
plot([1:length(drift)],10^6*abs(drift),'-o');
set(gca,'FontSize',14)
title('Drift des OPA129U mit 1GOhm Rückkoppelwiderstand')
xlabel('Zeit in Minuten');

print('-djpeg100','../Bilder/driftopa129U.jpg');

%femto
display('---------------------------------');
clear a;
dat2=load('../Messdaten/femto_rauschneu.csv');
figure
plot(1:length(dat2),(dat2(:,2)-mean(dat2(:,2)))*10^3,'k',1:length(dat(:,2)),10^3*(dat(:,2)-mean(dat(:,2))),'r')
std(dat2(:,2))
rms=sqrt(sum((dat2(:,2)-mean(dat2(:,2))).^2)/length(dat2))
n=0
for i=1:600:length(dat2(:,2))
    n=n+1;
    if i+1200>=length(dat2(:,2)) break
    end
drift(n)=mean(dat2(i+600:i+1200,2))-mean(dat2(i:i+600,2));
end
figure
plot([1:length(drift)],10^6*abs(drift),'-o');
set(gca,'FontSize',14)
title('Drift des Femt- DLCPA 200 bei eienr Verstärkung von 10^9 V/A')
xlabel('Zeit in Minuten');

print('-djpeg100','../Bilder/driftfemto.jpg');

%drift
\end{verbatim}

\subsection{current distance}
\begin{figure}[H]
        \centering
                \includegraphics[width=0.80\textwidth]{../Bilder/platzhalter.jpg}
        \caption{Platzhalter Strom abstandskurve}
        \label{dikurve}
\end{figure
}


this code works fine - 0 errors - however this is not the code I want to present. If I modify this code to:

-appendix.tex-
Code: Select all  •  Open in writeLaTeX
\section{Anhang}

\subsection{Matlab Code zur Ermittlung des Drifts der Verstärker}
\begin{verbatim
}
clear all
close all
clc

%opa129u
dat=load('../Messdaten/opa129u_rauschneu2.txt');
plot(1:length(dat),dat(:,2)*10^3)
std(dat(:,2))
rms=sqrt(sum((dat(:,2)-mean(dat(:,2))).^2)/length(dat))
n=0
for i=1:600:length(dat(:,2))
    n=n+1;
    if i+1200>=length(dat(:,2)) break
    end
drift(n)=mean(dat(i+600:i+1200,2))-mean(dat(i:i+600,2));
end
figure
plot([1:length(drift)],10^6*abs(drift),'-o');
set(gca,'FontSize',14)
title('Drift des OPA129U mit 1GOhm Rückkoppelwiderstand')
xlabel('Zeit in Minuten');
ylabel('Drift in µV/min')
print('-djpeg100','../Bilder/driftopa129U.jpg');

%femto
display('---------------------------------');
clear a;
dat2=load('../Messdaten/femto_rauschneu.csv');
figure
plot(1:length(dat2),(dat2(:,2)-mean(dat2(:,2)))*10^3,'k',1:length(dat(:,2)),10^3*(dat(:,2)-mean(dat(:,2))),'r')
std(dat2(:,2))
rms=sqrt(sum((dat2(:,2)-mean(dat2(:,2))).^2)/length(dat2))
n=0
for i=1:600:length(dat2(:,2))
    n=n+1;
    if i+1200>=length(dat2(:,2)) break
    end
drift(n)=mean(dat2(i+600:i+1200,2))-mean(dat2(i:i+600,2));
end
figure
plot([1:length(drift)],10^6*abs(drift),'-o');
set(gca,'FontSize',14)
title('Drift des Femt- DLCPA 200 bei eienr Verstärkung von 10^9 V/A')
xlabel('Zeit in Minuten');
ylabel('Drift in µV/min')
print('-djpeg100','../Bilder/driftfemto.jpg');

%drift
\end{verbatim}

\subsection{current distance}
\begin{figure}[H]
        \centering
                \includegraphics[width=0.80\textwidth]{../Bilder/platzhalter.jpg}
        \caption{Platzhalter Strom abstandskurve}
        \label{dikurve}
\end{figure
}

I get this errors:
Code: Select all  •  Open in writeLaTeX
! Missing $ inserted.
<inserted text>
                $
l.25 ylabel('Drift in µV/min')
                             
I've inserted a begin-math/end-math symbol since I think
you left one out. Proceed, with fingers crossed.

! TeX capacity exceeded, sorry [main memory size=3000000].
'->\leavevmode \kern \z@
                         \char `\'
l.25 ylabel('Drift in µV/min')
                             
If you really absolutely need more capacity,
you can ask a wizard to enlarge me.

 
Here is how much of TeX's memory you used:
 8291 strings out of 494045
 122945 string characters out of 3145942
 2999999 words of memory out of 3000000
 11276 multiletter control sequences out of 15000+200000
 17117 words of font info for 41 fonts, out of 3000000 for 9000
 715 hyphenation exceptions out of 8191
 29i,11n,32p,2452b,355s stack positions out of 5000i,500n,10000p,200000b,50000s
!  ==> Fatal error occurred, no output PDF file produced!

I have no idea why I tried to fix this for three days now. I hope anybody can help me.
Last edited by Stefan_K on Thu Jun 21st, 2012, edited 2 times in total.
Puppy
 
Posts: 2
Joined: Thu Jun 21st, 2012

Re: verbatim | Verbatim Environment causes critical Errors

Postby cgnieder on Thu Jun 21st, 2012

The error appears next to where you've written
Code: Select all  •  Open in writeLaTeX
ylabel('Drift in µV/min')

Since this doesn't appear in the code that's working it's a good guess that this the one causing the trouble. I would especially think that the µ causes the problems.

Indeed can the error be reproduced with this minimal working example:
Code: Select all  •  Open in writeLaTeX
\documentclass{article}
\usepackage[latin1]{inputenc}
\begin{document}

\begin{verbatim}
 ylabel('Drift in µV/min')
\end{verbatim}

\end{document
}


A similar code with utf8 encoding works nicely, though:
Code: Select all  •  Open in writeLaTeX
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{textgreek}
\usepackage{newunicodechar}
\newunicodechar{µ}{\textmu}
\begin{document}

\begin{verbatim}
 ylabel('Drift in µV/min')
\end{verbatim}

\end{document
}

I guess that changing the encoding of your source would cause more trouble than solve anything but unfortunately I don't know enough about encodings to be able to help you. Maybe someone else has an idea?

Regards
Clemens
------------------------------
New German Q&A site about TeX: http://texwelt.de/wissen
System: TeXlive 2013, OpenSUSE 12.3
User avatar
cgnieder
Site Moderator
 
Posts: 1670
Joined: Sat Apr 16th, 2011
Location: Germany

Re: verbatim | Verbatim Environment causes critical Errors  Topic is solved

Postby localghost on Sat Jun 23rd, 2012

Clemens already pointed out the source of the error. And it can be fixed amazingly simple by loading the textcomp package.

While this is working for the verbatim package, it doesn't neither with listings nor with its extension listingsutf8 (from the oberdiek bundle).

If you want your listings to have nice syntax highlighting, you can use the minted package as a possible alternative. Tips on how to make it work are given in the forum [1]. For a detailed description of its capabilities refer to the package manual. A small example based on your code (see attachment).
Code: Select all  •  Open in writeLaTeX
\documentclass[11pt,a4paper,ngerman]{article}
\usepackage[T1]{fontenc}
\usepackage{selinput}
\SelectInputMappings{
  adieresis={ä},
  germandbls={ß},
  Euro={}
}
\usepackage{babel}
\usepackage[hmargin=3cm,vmargin=2cm]{geometry}
\usepackage{minted}
\usepackage{textcomp}

\begin{document}
  \inputminted[linenos,fontsize=\footnotesize]{matlab}{drift.m}
\end{document
}

For more clarity I swapped the actual Matlab code into an external file (see attachment). Line 30 of the Matlab code is a bit problematic because due to missing blank spaces it cannot be wrapped.

Finally some remarks regarding the code you presented.

  • The a4wide package is obsolete. It isn't needed here anyway because you pass the a4paper option to the document class and use the geometry package.
  • The subfigure package is obsolete. Use its direct successor subfig or a more sophisticated package.
  • The german package is obsolete. For documents in German replace it with babel along with the ngerman language option (in my example given globally to the document class so that other packages may benefit).
  • The setspace package can be directly loaded with a corresponding option for the desired line spacing.
    Code: Select all  •  Open in writeLaTeX
    \usepackage[onehalfspacing]{setspace}
  • You only need to load the graphicx package, which in turn loads graphics.
  • Replace color with the more sophisticated xcolor.
  • Use float with caution.
  • Think about using the braket package.
  • Think about using a class from the KOMA-Script bundle.

For details and a deeper understanding of their capabilities refer to the respective manuals of the involved packages.

[1] View topic: Code Listings that can be referenced


Best regards and welcome to the board
Thorsten
Attachments
tmp.pdf
The output obtained by the given example.
(82.2 KiB) Downloaded 45 times
drift.m.zip
The Matlab sample code.
(686 Bytes) Downloaded 43 times
LaTeX Community Moderator
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes


¹ System: openSUSE 13.1 (Linux 3.11.10), TeX Live 2013 (vanilla), TeXworks 0.5 (r1351)
² Posting stopped indefinitely due to offenses
User avatar
localghost
Site Moderator
 
Posts: 9219
Joined: Fri Feb 2nd, 2007
Location: Braunschweig, Germany

Re: verbatim | Verbatim Environment causes critical Errors

Postby cgnieder on Sat Jun 23rd, 2012

Wow. Do you know what textcomp does to fix this? Defining the right symbol for µ, I suppose...

I've never heard of listingsutf8 before. A nice one, even if only \lstinputlisting is patched.
Clemens
------------------------------
New German Q&A site about TeX: http://texwelt.de/wissen
System: TeXlive 2013, OpenSUSE 12.3
User avatar
cgnieder
Site Moderator
 
Posts: 1670
Joined: Sat Apr 16th, 2011
Location: Germany

Re: verbatim | Verbatim Environment causes critical Errors

Postby localghost on Sat Jun 23rd, 2012

cgnieder wrote:Wow. Do you know what textcomp does to fix this? Defining the right symbol for µ, I suppose... […]

That's correct. The package just supports the Text Companion fonts by providing corresponding symbols. In this case it's \textmu that makes the difference.
LaTeX Community Moderator
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes


¹ System: openSUSE 13.1 (Linux 3.11.10), TeX Live 2013 (vanilla), TeXworks 0.5 (r1351)
² Posting stopped indefinitely due to offenses
User avatar
localghost
Site Moderator
 
Posts: 9219
Joined: Fri Feb 2nd, 2007
Location: Braunschweig, Germany

Re: verbatim | Verbatim Environment causes critical Errors

Postby Puppy on Wed Jun 27th, 2012

Wow, thanks for the help. Yes the µ made problems. Now without it, even nicely colored code is archiveable. Thank you guys very much.
Puppy
 
Posts: 2
Joined: Thu Jun 21st, 2012


Return to Text Formatting

Who is online

Users browsing this forum: No registered users and 5 guests