直接在 .tex 文件中使用 BibTex 条目

直接在 .tex 文件中使用 BibTex 条目

有没有办法在参考书目环境中使用 BibTex 条目,如下所示:

\begin{thebibliography}{9}
@article{greenwade93,
    author  = "George D. Greenwade",
    title   = "The {C}omprehensive {T}ex {A}rchive {N}etwork ({CTAN})",
    year    = "1993",
    journal = "TUGBoat",
    volume  = "14",
    number  = "3",
    pages   = "342--351"
}

@book{goossens93,
    author    = "Michel Goossens and Frank Mittelbach and Alexander Samarin",
    title     = "The LaTeX Companion",
    year      = "1993",
    publisher = "Addison-Wesley",
    address   = "Reading, Massachusetts"
}

\end{thebibliography}

例如,假设您想快速写一条注释,其中引用了三篇论文,这些论文的 BibTex 条目可用(可能通过 scholar.google.com ),那么直接将它们插入到您的文档中会更容易,而不必创建 .bib 文件或转换 bibtex 条目。

答案1

将我的评论转化为答案:也许filecontents 包可以做你想做的事。

\documentclass{article}

\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@article{greenwade93,
    author  = "George D. Greenwade",
    title   = "The {C}omprehensive {T}ex {A}rchive {N}etwork ({CTAN})",
    year    = "1993",
    journal = "TUGBoat",
    volume  = "14",
    number  = "3",
    pages   = "342--351"
}
@book{goossens93,
    author    = "Michel Goossens and Frank Mittelbach and Alexander Samarin",
    title     = "The LaTeX Companion",
    year      = "1993",
    publisher = "Addison-Wesley",
    address   = "Reading, Massachusetts"
}
\end{filecontents}

\usepackage{natbib}

\begin{document}
Lorem ipsum~\citep{goossens93}.
Dolor sit amet~\citet{greenwade93}.
\bibliographystyle{plainnat}
\bibliography{\jobname} 
\end{document}

与 LaTeX2e 提供的 filecontents 环境相比,filecontents 包提供的 filecontents 环境会覆盖现有文件。

答案2

您可以在有限的范围内使用以下方法实现此目的amsrefs

\documentclass{article}
\usepackage{amsrefs}
\newenvironment{rezabib}
  {\bibdiv\biblist\setupbib}
  {\endbiblist\endbibdiv}

\def\setupbib{\catcode`@=\active}
\begingroup\lccode`~=`@
  \lowercase{\endgroup\def~}#1#{\gatherkey{#1}}
\def\gatherkey#1#2{\gatherkeyaux{#1}#2\gatherkeyaux}
\def\gatherkeyaux#1#2,#3\gatherkeyaux{\bib{#2}{#1}{#3}}

\begin{document}

\nocite{*}

\begin{rezabib}
@article{greenwade93,
    author  = {George D. Greenwade},
    title   = {The {C}omprehensive {T}ex {A}rchive {N}etwork ({CTAN})},
    year    = {1993},
    journal = {TUGBoat},
    volume  = {14},
    number  = {3},
    pages   = {342--351}
}

@book{goossens93,
    author    = {Michel Goossens and Frank Mittelbach and Alexander Samarin},
    title     = {The LaTeX Companion},
    year      = {1993},
    publisher = {Addison-Wesley},
    address   = {Reading, Massachusetts}
}
\end{rezabib}

\end{document}

请注意必须使用括号来分隔字段。条目的起始行中不应有额外的空格

@book{goossens93,

空间限制可能会取消,但不是关于括号分隔的讨论。您不能@在字段中使用(如果真的需要)。

答案3

filecontens自2019 年环境更新以来,该filecontents包不再需要。以下是如何将参考书目直接包含在 .tex 文件中:

\documentclass{article}
\usepackage[style=numeric]{biblatex}
\begin{filecontents}{references.bib}
@book{goossens93,
    author    = {Michel Goossens and Frank Mittelbach and Alexander Samarin},
    title     = {The LaTeX Companion},
    year      = {1993},
    publisher = {Addison-Wesley},
    address   = {Reading, Massachusetts}
}
\end{filecontents}
\addbibresource{references.bib}

\title{My article}
\author{John Doe}

\begin{document}
\maketitle
\section{Introduction}

Here's the reference: \cite{goossens93}

\printbibliography
\end{document}

相关内容