Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am trying to include the literal contents of a BibTeX file in my LaTeX document using the listings package but am running into an issue.

As BibTeX does not appear to be natively supported (though TeX and BibTeX are), I have had to define the language syntax highlighting:

 \lstdefinelanguage{BibTeX}
  {otherkeywords={%
      @article,@book,@collectedbook,@conference,@electronic,@ieeetranbstctl,%
      @inbook,@incollectedbook,@incollection,@injournal,@inproceedings,%
      @manual,@mastersthesis,@misc,@patent,@periodical,@phdthesis,@preamble,%
      @proceedings,@standard,@string,@techreport,@unpublished%
      },%
    sensitive=false,
    morecomment=[s]{@comment}
  }[keywords,comments]

To include a .bib file, I am using:

\begin{figure}[h]
\centering
\lstinputlisting[language={BibTeX}]{mybibtex.txt}
\caption{Check out by BibTeX contents!}
\label{fig:bibtex}
\end{figure}

...but am told:

! Undefined control sequence.\lst@OutputToken...lst@CheckMerge {\lst@thestyle{\lst@FontAdjust \setbox \... @article

...when I compile the LaTeX.

How do I include the contents of .bib file in my document? I am using Texmaker 3.1.

Minimum Working Example

mwe.tex

\documentclass{article}            
\usepackage{listings}
\usepackage{color}

\lstset{%
 backgroundcolor=\color{red},
 basicstyle=\tiny\ttfamily,
 breaklines = true
}%

\lstdefinelanguage{BibTeX}
  {otherkeywords={%
      @article
      },%
    sensitive=false,
    morecomment=[s]{@comment}
  }[keywords,comments]


\begin{document}
%\lstinputlisting[language={BibTeX}]{mwe.bib} % problematic line
\lstinputlisting{mwe.bib}

\end{document}

mwe.bib

@article{myarticle ,
language = {English},
title = {MWE title},
abstract = {MWE abstract},
keywords = {MWE;Stack Overflow;BibTeX},
}
share|improve this question
1  
Can you add a minimal working example (MWE) that illustrates your problem. I have tried the snippet and it does not show that problem (but I don't get syntax highlight either). –  Guido Dec 7 '12 at 21:07
    
I have added as close to an MWE as I could with the problematic line commented out. It seems that applying my language definition causes the compiler issue but I still don't know how to resolve it. –  Mat Dec 7 '12 at 22:02
    
Since you have some responses below that seem to answer your question, please consider marking one of them as ‘Accepted’ by clicking on the tickmark below their vote count (see How do you accept an answer?). This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). It's part of this site's idea to identify good questions and answers through upvotes and acceptance of answers. –  Jubobs Mar 1 at 19:22

1 Answer 1

up vote 4 down vote accepted

Contrarily to what one might think reading the documentation, those keywords seem to want keywords, rather than otherkeywords; there is another glitch: morecomment=[s]... wants two arguments.

\begin{filecontents*}{\jobname.bib}
@article{myarticle,
  language = {English},
  title = {MWE title},
  abstract = {MWE abstract},
  keywords = {MWE;Stack Overflow;BibTeX},
}
\end{filecontents*}
\documentclass{article}
\usepackage{listings}
\usepackage{xcolor}

\lstset{%
 backgroundcolor=\color[gray]{.85},
 basicstyle=\small\ttfamily,
 breaklines = true,
 keywordstyle=\color{red!75},
 columns=fullflexible,
}%

\lstdefinelanguage{BibTeX}
  {keywords={%
      @article,@book,@collectedbook,@conference,@electronic,@ieeetranbstctl,%
      @inbook,@incollectedbook,@incollection,@injournal,@inproceedings,%
      @manual,@mastersthesis,@misc,@patent,@periodical,@phdthesis,@preamble,%
      @proceedings,@standard,@string,@techreport,@unpublished%
      },
   comment=[l][\itshape]{@comment},
   sensitive=false,
  }

\begin{document}

\lstinputlisting[language=BibTeX]{\jobname.bib}

\end{document}

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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