1

I am using the listings package which does great things for C++, Java. but what about for a makefile, which isn't one of the supported languages? I just want the equivalent of listings, nothing fancy, just to embed the text.

I would be happy to include an external makefile, or to paste it in (I'd love to have a choice as in listings). No special formatting required. What do I do? Some kind of verbatim?

  • 1
    If no special formatting is required, a plain verbatim might do. – egreg May 17 '15 at 23:40
  • 4
    The listings package appears to provide support for make. In lstlang2.sty you find \lst@definelanguage[gnu]{make} and \lst@definelanguage{make}. – Andrew May 18 '15 at 0:10
  • Wow, I searched for that (using google) and didn't find it. – Dov May 18 '15 at 1:27
  • 1
    See listings documentation, Section 2.4 and Table 1. – Mike Renfro May 18 '15 at 4:03
  • @Mike Renfro Why not just post this as an answer? Otherwise I can post my correct code as an answer, but it seems unfair since you found it. – Dov May 18 '15 at 13:15
1

The listings package has a make option:

\documentclass{article}
\usepackage{listings}
\begin{document}

 \begin{lstlisting}[language=make]
   # I am a comment
   CC=g++
   # CFLAGS options passed to the compiler.
   CFLAGS=-c -Wall

   all: hello

   hello: main.o factorial.o hello.o
   $(CC) main.o factorial.o hello.o -o hello

   clean:
   rm *.o hello
\end{lstlisting}
\end{document}

Having said, this, it doesn't work very well. For example, adding keywordstyle=\color{red} to the options list for the lstlisting environment should make the keywords red, but it doesn't. (According to lstlang2.sty, both CC and CFLAGS are keywords.)

I had a quick look at the code but I can't see what the problem is. See How can I highlight text before a character with listing for a solution/workaround.

| improve this answer | |

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.