1

I'm writing a report with multiple programming languages. At the moment I'm trying to include a Makefile.

When I do:

\lstinputlisting[language=make]{./Kodeeksempler/makefile}

I get the following error compiling with texlive in texmaker:

! Missing $ inserted.
<inserted text>
$
l.22 ]{./Kodeeksempler/makefile}

Line 22 of the makefile in question contains the following:

BUILD_DIR=build/host

.. So I know the error message is wrong, as that should be able to display fine. Any help would be greatly appreciated. The same occurs when I try to do lstlisting around the makefile regularly like so:

\begin{lstlisting}
clean:
     $(RM) ./build
     $(RM) ./bin
     @echo "Static libraries persist in ./lib"

     ${BUILD_DIR}/%.d: %.cpp
     $(CXX) -MT ${BUILD_DIR}/$(@:.d=.o) -MM $(CXXFLAGS) $^ > $@

-include $(DEPS)
\end{lstlisting}

EDIT:

I seem to have narrowed down that the error occurs around the line:

-include $(DEPS)

When I remove it, lstlisting includes it just fine.

EDIT2: This is the lstset I use in my preamble:

 \lstset{language=make,                 % Sprog
     basicstyle=\ttfamily\scriptsize,       % Opsaetning af teksten
     keywords={for,if,while,else,elseif,        % Noegleord at fremhaeve
          end,break,return,case,
          switch,function},
     keywordstyle=\color{blue},             % Opsaetning af noegleord
     commentstyle=\color{commentGreen},     % Opsaetning af kommentarer
     stringstyle=\color{stringPurple},      % Opsaetning af strenge
     showstringspaces=false,                    % Mellemrum i strenge enten vist eller blanke
     numbers=left, numberstyle=\tiny,       % Linjenumre
     extendedchars=true,                    % Tillader specielle karakterer
    columns=flexible,                       % Kolonnejustering
    breaklines, breakatwhitespace=true,     % Bryd lange linjer
}

I have noticed that even when I omit the last part of the makefile, it seems to work.

EDIT3:

So I found the issue! Appearently the @ key was used as an escape character for an old lstset for C code, and it came back in as a result of a merge conflict. Line 199 in the preamble contained the following:

 \lstset{escapechar=@,style=customc}

I removed it, and now it works. Thank you all for your patience.

  • 2
    Define special characters? Is the file uf8? As always on this site we prefer full examples we can copy and (attempt to) compile without having to add anything – daleif Oct 5 '15 at 19:00
  • I have updated my question now. I finally seem to have narrowed down where the issue is. – Martin Oct 5 '15 at 19:56
  • 1
    But please update it to a complete example, there is no preamble, no documentclass. If you add up complete example, the ever present mwe, then it is a lot easier to help you – daleif Oct 5 '15 at 19:58
  • you must have a \lstset in your document or the document class. And I suppose that you have the option mathescape set. – user2478 Oct 5 '15 at 20:02
  • @Herbert: I don't think that's the problem: if you make a minimal document with just \usepackage{listings} in the preamble and the Makefile from the question, it compiles fine. – Arun Debray Oct 5 '15 at 20:07

Your Answer

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

Browse other questions tagged or ask your own question.