## LaTeX forum ⇒ Text Formatting ⇒ verbatim | Verbatim Environment causes critical Errors Topic is solved

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Puppy
Posts: 2
Joined: Thu Jun 21, 2012 2:02 pm

### verbatim | Verbatim Environment causes critical Errors

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:
\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-

\section{Anhang}\subsection{Matlab Code zur Ermittlung des Drifts der Verstärker}\begin{verbatim}clear all close allclc %opa129udat=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=0for i=1:600:length(dat(:,2))     n=n+1;     if i+1200>=length(dat(:,2)) break     enddrift(n)=mean(dat(i+600:i+1200,2))-mean(dat(i:i+600,2));endfigureplot([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'); %femtodisplay('---------------------------------');clear a;dat2=load('../Messdaten/femto_rauschneu.csv');figureplot(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=0for i=1:600:length(dat2(:,2))     n=n+1;     if i+1200>=length(dat2(:,2)) break     enddrift(n)=mean(dat2(i+600:i+1200,2))-mean(dat2(i:i+600,2));endfigureplot([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-
\section{Anhang} \subsection{Matlab Code zur Ermittlung des Drifts der Verstärker}\begin{verbatim}clear all close allclc %opa129udat=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=0for i=1:600:length(dat(:,2))     n=n+1;     if i+1200>=length(dat(:,2)) break     enddrift(n)=mean(dat(i+600:i+1200,2))-mean(dat(i:i+600,2));endfigureplot([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'); %femtodisplay('---------------------------------');clear a;dat2=load('../Messdaten/femto_rauschneu.csv');figureplot(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=0for i=1:600:length(dat2(:,2))     n=n+1;     if i+1200>=length(dat2(:,2)) break     enddrift(n)=mean(dat2(i+600:i+1200,2))-mean(dat2(i:i+600,2));endfigureplot([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:
! Missing $inserted.<inserted text>$l.25 ylabel('Drift in µV/min') I've inserted a begin-math/end-math symbol since I thinkyou 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 Kottwitz on Thu Jun 21, 2012 5:16 pm, edited 2 times in total.

cgnieder
Site Moderator
Posts: 1973
Joined: Sat Apr 16, 2011 7:27 pm
Location: Germany
Contact:
The error appears next to where you've written
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:
\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:
\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
------------------------------
chemmacros · chemformula · leadsheets · xsim

localghost
Site Moderator
Posts: 9206
Joined: Fri Feb 02, 2007 12:06 pm
Location: Braunschweig, Germany
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).
\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.

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.
drift.m.zip
The Matlab sample code.
LaTeX Community Moderator

¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1

cgnieder
Site Moderator
Posts: 1973
Joined: Sat Apr 16, 2011 7:27 pm
Location: Germany
Contact:
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
------------------------------
chemmacros · chemformula · leadsheets · xsim

localghost
Site Moderator
Posts: 9206
Joined: Fri Feb 02, 2007 12:06 pm
Location: Braunschweig, Germany
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

¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1

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