2

I have a listing that I use to display some code. I use filecontents to specify the content and lstinputlisting to display it.

The resulting pdf looks ok (used PDFLaTex), but above my code I get:

%% LaTeX2e file ‘[]’
%% generated by the ‘filecontents’ environment
%% from source ‘[]’ on 2016/12/29.

any way to get ride of this ?

5
  • 2
    Use filecontents* instead of filecontents. Commented Dec 29, 2016 at 10:30
  • 1
    Or tell listings to ignore the first lines with the firstline option. Commented Dec 29, 2016 at 14:45
  • @PeterGrill but that would force it to span two columns ? (I use a two columns layout)
    – Vince
    Commented Dec 29, 2016 at 19:45
  • @UlrikeFischer works :) would be happy to valid the answer, if provided as such
    – Vince
    Commented Dec 29, 2016 at 19:46
  • 1
    What do you mean about spanning two columns? The filecontents environment only writes its content to an external file, there is nothing that can span two columns. The starred version of the environment writes a file without the header you mention. Commented Dec 29, 2016 at 20:06

1 Answer 1

3

As mentioned by Peter in his comment you can avoid to get the preamble in a file generated by a filecontents environment by using the starred version of filecontents. If this is not possible you can suppress the starting lines with the firstline option:

\documentclass{article}
\begin{filecontents}{mylisting1.txt}
bla
\end{filecontents}

\begin{filecontents*}{mylisting2.txt}
bla
\end{filecontents*}


\usepackage{listings}
\begin{document}
\lstinputlisting[firstline=5,frame=single]{mylisting1.txt}

\lstinputlisting[frame=single]{mylisting2.txt}

\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .