我正在尝试使用该包将 BibTeX 文件的文字内容包含到我的 LaTeX 文档中,listings
但遇到了一个问题。
由于 BibTeX 似乎不受原生支持(尽管 TeX 和 BibTeX 受原生支持),因此我不得不定义语言语法高亮:
\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]
为了包含 .bib 文件,我使用:
\begin{figure}[h]
\centering
\lstinputlisting[language={BibTeX}]{mybibtex.txt}
\caption{Check out by BibTeX contents!}
\label{fig:bibtex}
\end{figure}
...但我被告知:
! Undefined control sequence.\[email protected]@CheckMerge {\lst@thestyle{\lst@FontAdjust \setbox \... @article
...当我编译 LaTeX 时。
如何将 .bib 文件的内容包含到我的文档中?我正在使用 Texmaker 3.1。
最小工作示例
麦格
\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}
论坛
@article{myarticle ,
language = {English},
title = {MWE title},
abstract = {MWE abstract},
keywords = {MWE;Stack Overflow;BibTeX},
}
答案1
与阅读文档时的想法相反,这些关键字似乎是 want keywords
,而不是otherkeywords
;还有另一个问题:morecomment=[s]...
wants二參數。
\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}