I am using listing package for inserting code snippets in my thesis in several chapters of my thesis. I use the following style to insert code snippets :

   \lstset{emph={sensors, string}, emphstyle={\color{blue}\bfseries\emph}, 
caption={Code snippet of the building automation domain.}, escapechar=\#,  

I am getting the following errors. My compilation indicates error at
this code location \lstinputlisting{code-snippet/extract-vocabsec.txt}

Pdflatex> Argument of \lst@for has an extra }
pdflatex> <inserted text>
pdflatex>   \par
pdflatex> l.140 ...isting{code-snippet/extract-vocabsec.txt}
pdflatex> Runaway argument?
pdflatex> ! Paragraph ended before \lst@for was complete
pdflatex> <to be read again>
pdflatex>   \par
pdflatex> l.140 ...isting{code-snippet/extract-vocabsec.txt}

for reference, I have added following header of my main compilation document.



\definecolor{javared}{rgb}{0.6,0,0} % for strings
\definecolor{javagreen}{rgb}{0.25,0.5,0.35} % comments
\definecolor{javapurple}{rgb}{0.5,0,0.35} % keywords
\definecolor{javadocblue}{rgb}{0.25,0.35,0.75} % javadoc

\lstset{ %
%language=Java,                 % choose the language of the code
basicstyle=\ttfamily,     % the size of the fonts that are used for the code
numbers=left,                   % where to put the line-numbers
numberstyle=\tiny,              % the size of the fonts that are used for the line-numbers
stepnumber=1,                   % the step between two line-numbers. If it is 1 each line will be numbered
numbersep=5pt,                  % how far the line-numbers are from the code
backgroundcolor=\color{white},  % choose the background color. You must add \usepackage{color}
showspaces=false,               % show spaces adding particular underscores
showstringspaces=false,         % underline spaces within strings
showtabs=false,                 % show tabs within strings adding particular underscores
tabsize=2,                      % sets default tabsize to 2 spaces
captionpos=b,                   % sets the caption-position to bottom
breaklines=true,                % sets automatic line breaking
breakatwhitespace=false,        % sets if automatic breaks should only happen at whitespace
escapeinside={\%*}{*)}          % if you want to add a comment within your code 



extract-vocabsec.txt file contains the following code

regions:  #\label{vocab:regions-start}#
    Building: integer;
    Floor: integer;
    Room: integer;  #\label{vocab:regions-end}#
structs:                  #\label{vocab:structs-start}#
    BadgeDetectedStruct    #\label{vocab:badgedetectedstructs-start}#
        badgeID: string;
        timeStamp: long;   #\label{vocab:badgedetectedstructs-end}#
    TempStruct            #\label{vocab:tempstruct-start}#
        tempValue: double;
        unitOfMeasurement: string;  #\label{vocab:structs-end}#
    sensors:                        #\label{vocab:sensors-start}#
        BadgeReader                 #\label{vocab:badgereader-start}# 
            generate badgeDetected: BadgeDetectedStruct;  #\label{vocab:badgereader-end}# 
        TemperatureSensor               #\label{vocab:tempsensor-end}#
            generate tempMeasurement: TempStruct;  #\label{vocab:sensors-end}#
    actuators:                   #\label{vocab:actuators-start}#
        Heater                 #\label{vocab:heater}#
            action Off();      #\label{vocab:action-end}#
            action SetTemp(setTemp: TempStruct);   #\label{vocab:actuators-end}#
    storages:       #\label{vocab:storages-start}#
        ProfileDB   #\label{vocab:profile-start}#
            generate  profile: TempStruct accessed-by badgeID: string;  #\label{vocab:storages-end}#
    userinterfaces:   #\label{vocab:ui-start}#
        EndUserGUI   #\label{vocab:endusergui-start}#
            command Off();  #\label{vocab:command-off}#
            action DisplayData(displayTemp: TempStruct);    #\label{vocab:displaydata}#     
            request profile(badgeID);    #\label{vocab:profile-ui}# 
  • Comment: emphstyle should not end with \emph, that command takes an argument thus may f things up. \itshape might be better
    – daleif
    Oct 29 '13 at 15:21
  • Thanks daleif for your effort! However, I use the above style to include code snippet in whole thesis. I am not facing problem of using \emph in other code snippets. Oct 29 '13 at 15:25
  • 1
    Forgetting about the fact that your MWE misses the xcolor package, I tested your settings for article class and it works really fine!
    – Pouya
    Oct 29 '13 at 15:41
  • Thanks pouya. I have tried your setting. I am getting the same error. Oct 29 '13 at 16:07
  • 1
    Without seeing (an unabridged version of) code-snippet/extract-vocabsec.txt it's difficult to say more.
    – egreg
    Oct 29 '13 at 18:25

Comment out line no. 376 in aesm_edspia.cls


assuming the document class is like http://aesm.asso.univ-poitiers.fr/files/Modele_Latex.zip

  • Many Many thanks Samcarter for the answer. The problem is solved now. However, this produces a new problem. The title of each chapter is now in CAPITAL. Any suggestion on this? Oct 30 '13 at 10:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.