LaTeX forum ⇒ Text Formattingverbatim | 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

Postby Puppy » Thu Jun 21, 2012 2:21 pm

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:
  1. \documentclass[a4paper,12pt]{article}
  2. \usepackage{a4wide}%papierrand
  3. \usepackage{graphicx}
  4. \usepackage{graphics}
  5. \usepackage{german}
  6. \usepackage{float}
  7. \usepackage[latin1]{inputenc}%latin1 inputenc gibt das ß und die umlaute her
  8. \usepackage{amsmath}%formelnumerierungen und anordnungszeugs
  9. %\usepackage[Ausrichtung]{floatflt}%bilder mit text umzu
  10. \usepackage[T1]{fontenc}
  11. \usepackage{url}
  12. \usepackage{subfigure}
  13. \usepackage{setspace} %1.5 facher zeilenabstand
  14. \onehalfspacing %1.5 facher zeilenabstand
  15. \usepackage[left=3cm,right=3cm,top=2cm,bottom=2cm]{geometry}
  16. \def\bra#1{\ensuremath{\langle{#1}\vert}}
  17. \def\ket#1{\ensuremath{\vert{#1}\rangle}}
  18. %\usepackage{hyperref}
  19. \usepackage{url}
  20. \usepackage[pdffitwindow=true, pdftex]{hyperref}
  21. \usepackage{color}
  22. %\usepackage{listings}
  23. \usepackage{verbatim}
  24. \begin{document}
  25.  
  26. ...
  27. \input{bla.tex}
  28. .
  29. .
  30. .
  31. \input{appendix.tex}
  32. \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-

  1. \section{Anhang}
  2. \subsection{Matlab Code zur Ermittlung des Drifts der Verstärker}
  3. \begin{verbatim}
  4. clear all
  5. close all
  6. clc
  7.  
  8. %opa129u
  9. dat=load('../Messdaten/opa129u_rauschneu2.txt');
  10. plot(1:length(dat),dat(:,2)*10^3)
  11. std(dat(:,2))
  12. rms=sqrt(sum((dat(:,2)-mean(dat(:,2))).^2)/length(dat))
  13. n=0
  14. for i=1:600:length(dat(:,2))
  15. n=n+1;
  16. if i+1200>=length(dat(:,2)) break
  17. end
  18. drift(n)=mean(dat(i+600:i+1200,2))-mean(dat(i:i+600,2));
  19. end
  20. figure
  21. plot([1:length(drift)],10^6*abs(drift),'-o');
  22. set(gca,'FontSize',14)
  23. title('Drift des OPA129U mit 1GOhm Rückkoppelwiderstand')
  24. xlabel('Zeit in Minuten');
  25.  
  26. print('-djpeg100','../Bilder/driftopa129U.jpg');
  27.  
  28. %femto
  29. display('---------------------------------');
  30. clear a;
  31. dat2=load('../Messdaten/femto_rauschneu.csv');
  32. figure
  33. plot(1:length(dat2),(dat2(:,2)-mean(dat2(:,2)))*10^3,'k',1:length(dat(:,2)),10^3*(dat(:,2)-mean(dat(:,2))),'r')
  34. std(dat2(:,2))
  35. rms=sqrt(sum((dat2(:,2)-mean(dat2(:,2))).^2)/length(dat2))
  36. n=0
  37. for i=1:600:length(dat2(:,2))
  38. n=n+1;
  39. if i+1200>=length(dat2(:,2)) break
  40. end
  41. drift(n)=mean(dat2(i+600:i+1200,2))-mean(dat2(i:i+600,2));
  42. end
  43. figure
  44. plot([1:length(drift)],10^6*abs(drift),'-o');
  45. set(gca,'FontSize',14)
  46. title('Drift des Femt- DLCPA 200 bei eienr Verstärkung von 10^9 V/A')
  47. xlabel('Zeit in Minuten');
  48.  
  49. print('-djpeg100','../Bilder/driftfemto.jpg');
  50.  
  51. %drift
  52. \end{verbatim}
  53.  
  54. \subsection{current distance}
  55. \begin{figure}[H]
  56. \centering
  57. \includegraphics[width=0.80\textwidth]{../Bilder/platzhalter.jpg}
  58. \caption{Platzhalter Strom abstandskurve}
  59. \label{dikurve}
  60. \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-
  1. \section{Anhang}
  2.  
  3. \subsection{Matlab Code zur Ermittlung des Drifts der Verstärker}
  4. \begin{verbatim}
  5. clear all
  6. close all
  7. clc
  8.  
  9. %opa129u
  10. dat=load('../Messdaten/opa129u_rauschneu2.txt');
  11. plot(1:length(dat),dat(:,2)*10^3)
  12. std(dat(:,2))
  13. rms=sqrt(sum((dat(:,2)-mean(dat(:,2))).^2)/length(dat))
  14. n=0
  15. for i=1:600:length(dat(:,2))
  16. n=n+1;
  17. if i+1200>=length(dat(:,2)) break
  18. end
  19. drift(n)=mean(dat(i+600:i+1200,2))-mean(dat(i:i+600,2));
  20. end
  21. figure
  22. plot([1:length(drift)],10^6*abs(drift),'-o');
  23. set(gca,'FontSize',14)
  24. title('Drift des OPA129U mit 1GOhm Rückkoppelwiderstand')
  25. xlabel('Zeit in Minuten');
  26. ylabel('Drift in µV/min')
  27. print('-djpeg100','../Bilder/driftopa129U.jpg');
  28.  
  29. %femto
  30. display('---------------------------------');
  31. clear a;
  32. dat2=load('../Messdaten/femto_rauschneu.csv');
  33. figure
  34. plot(1:length(dat2),(dat2(:,2)-mean(dat2(:,2)))*10^3,'k',1:length(dat(:,2)),10^3*(dat(:,2)-mean(dat(:,2))),'r')
  35. std(dat2(:,2))
  36. rms=sqrt(sum((dat2(:,2)-mean(dat2(:,2))).^2)/length(dat2))
  37. n=0
  38. for i=1:600:length(dat2(:,2))
  39. n=n+1;
  40. if i+1200>=length(dat2(:,2)) break
  41. end
  42. drift(n)=mean(dat2(i+600:i+1200,2))-mean(dat2(i:i+600,2));
  43. end
  44. figure
  45. plot([1:length(drift)],10^6*abs(drift),'-o');
  46. set(gca,'FontSize',14)
  47. title('Drift des Femt- DLCPA 200 bei eienr Verstärkung von 10^9 V/A')
  48. xlabel('Zeit in Minuten');
  49. ylabel('Drift in µV/min')
  50. print('-djpeg100','../Bilder/driftfemto.jpg');
  51.  
  52. %drift
  53. \end{verbatim}
  54.  
  55. \subsection{current distance}
  56. \begin{figure}[H]
  57. \centering
  58. \includegraphics[width=0.80\textwidth]{../Bilder/platzhalter.jpg}
  59. \caption{Platzhalter Strom abstandskurve}
  60. \label{dikurve}
  61. \end{figure}

I get this errors:
  1. ! Missing $ inserted.
  2. <inserted text>
  3. $
  4. l.25 ylabel('Drift in µV/min')
  5.  
  6. I've inserted a begin-math/end-math symbol since I think
  7. you left one out. Proceed, with fingers crossed.
  8.  
  9. ! TeX capacity exceeded, sorry [main memory size=3000000].
  10. '->\leavevmode \kern \z@
  11. \char `\'
  12. l.25 ylabel('Drift in µV/min')
  13.  
  14. If you really absolutely need more capacity,
  15. you can ask a wizard to enlarge me.
  16.  
  17.  
  18. Here is how much of TeX's memory you used:
  19. 8291 strings out of 494045
  20. 122945 string characters out of 3145942
  21. 2999999 words of memory out of 3000000
  22. 11276 multiletter control sequences out of 15000+200000
  23. 17117 words of font info for 41 fonts, out of 3000000 for 9000
  24. 715 hyphenation exceptions out of 8191
  25. 29i,11n,32p,2452b,355s stack positions out of 5000i,500n,10000p,200000b,50000s
  26. ! ==> 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.

Link:
BBcode:
HTML:
Hide post links
Show post links

User avatar
cgnieder
Site Moderator
Posts: 1948
Joined: Sat Apr 16, 2011 7:27 pm
Location: Germany
Contact:

Postby cgnieder » Thu Jun 21, 2012 10:14 pm

The error appears next to where you've written
  1. 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 Infominimal working example:
  1. \documentclass{article}
  2. \usepackage[latin1]{inputenc}
  3. \begin{document}
  4.  
  5. \begin{verbatim}
  6. ylabel('Drift in µV/min')
  7. \end{verbatim}
  8.  
  9. \end{document}


A similar code with utf8 encoding works nicely, though:
  1. \documentclass{article}
  2. \usepackage[utf8]{inputenc}
  3. \usepackage{textgreek}
  4. \usepackage{newunicodechar}
  5. \newunicodechar{µ}{\textmu}
  6. \begin{document}
  7.  
  8. \begin{verbatim}
  9. ylabel('Drift in µV/min')
  10. \end{verbatim}
  11.  
  12. \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

Link:
BBcode:
HTML:
Hide post links
Show post links

User avatar
localghost
Site Moderator
Posts: 9206
Joined: Fri Feb 02, 2007 12:06 pm
Location: Braunschweig, Germany

Postby localghost » Sat Jun 23, 2012 11:15 am

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).
  1. \documentclass[11pt,a4paper,ngerman]{article}
  2. \usepackage[T1]{fontenc}
  3. \usepackage{selinput}
  4. \SelectInputMappings{
  5. adieresis={ä},
  6. germandbls={ß},
  7. Euro={€}
  8. }
  9. \usepackage{babel}
  10. \usepackage[hmargin=3cm,vmargin=2cm]{geometry}
  11. \usepackage{minted}
  12. \usepackage{textcomp}
  13.  
  14. \begin{document}
  15. \inputminted[linenos,fontsize=\footnotesize]{matlab}{drift.m}
  16. \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.
    1. \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 139 times
drift.m.zip
The Matlab sample code.
(686 Bytes) Downloaded 57 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

Link:
BBcode: Topic is solved[/url]" title="Click to select post's link in BBcode format" onclick="this.focus();this.select();" />
HTML: Topic is solved</a>" title="Click to select post's link in HTML format" onclick="this.focus();this.select();" />
Hide post links
Show post links

User avatar
cgnieder
Site Moderator
Posts: 1948
Joined: Sat Apr 16, 2011 7:27 pm
Location: Germany
Contact:

Postby cgnieder » Sat Jun 23, 2012 2:32 pm

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

Link:
BBcode:
HTML:
Hide post links
Show post links

User avatar
localghost
Site Moderator
Posts: 9206
Joined: Fri Feb 02, 2007 12:06 pm
Location: Braunschweig, Germany

Postby localghost » Sat Jun 23, 2012 6:58 pm

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

Link:
BBcode:
HTML:
Hide post links
Show post links

Puppy
Posts: 2
Joined: Thu Jun 21, 2012 2:02 pm

Postby Puppy » Wed Jun 27, 2012 9:16 am

Wow, thanks for the help. Yes the µ made problems. Now without it, even nicely colored code is archiveable. Thank you guys very much.

Link:
BBcode:
HTML:
Hide post links
Show post links


Return to “Text Formatting”

Who is online

Users browsing this forum: No registered users and 1 guest