我正在按照这个教程进行操作,https://www.latex-tutorial.com/tutorials/,学习一点乳胶。我无法弄清楚如何在参考书目中添加对网站的引用。我在 Windows 10 上使用 Texworks 编辑器,并且“模式”设置为pdflatex+makeindex+bibtex
。因此,以下是我的乳胶代码的相关部分:
在hello_latex.tex
文件中:
\documentclass{article}
\title{About cats}
\date{2013-11-20}
\author{name}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{float}
\usepackage{subcaption}
\begin{document}
\newpage
%... a bunch of stuff
\paragraph{} Here is an example of a citation embedded in text. Random citation \cite{BOOK:1} embedded in text.
\paragraph{} Here is an example of an article citation. Yet another random citation \cite{ARTICLE:4} embedded in text.
\paragraph{} Here is an example of an "inbook" citation with page numbers mentioned. Another random citation \cite{INBOOK:3} embedded in text.
\paragraph{} Here is example of a website citation. One more random citation \cite{example} embedded in text.
\newpage
\bibliography{hello_latex}
\bibliographystyle{ieeetr}
\end{document}
在hello_latex.bib
文件中:
@BOOK{BOOK:1,
AUTHOR="John Doe",
TITLE="The Book without Title",
PUBLISHER="Dummy Publisher",
YEAR="2100",
}
@INBOOK{INBOOK:3,
AUTHOR="John Doe",
TITLE="The Book without Title",
PUBLISHER="Dummy Publisher",
YEAR="2100",
PAGES="100-200",
}
@ARTICLE{ARTICLE:4,
AUTHOR="John Doe",
TITLE="Title",
JOURNAL="Journal",
YEAR="2017",
}
@MISC{WEBSITE:1,
HOWPUBLISHED = "\url{http://example.com}",
AUTHOR = "Intel",
TITLE = "Example Website",
MONTH = "Dec",
YEAR = "1988",
NOTE = "Accessed on 2012-11-11"
}
我发现让引用工作对我来说非常难以预测。如果一次性添加整套引用,编译就会出错。因此,我不得不逐一重复该过程,才能让 BOOK、ARTICLE 和 INBOOK 引用工作,最后我甚至无法让 WEBSITE 引用工作。
控制台输出是一些我无法理解的警告。
Undefined control sequence.
l.19 Intel, ``Example website.'' \url
{http://example.com}, Dec 1988.
LaTeX Warning: Citation `BOOK:2' on page 1 undefined on input line 28.
LaTeX Warning: Citation `BOOK:1' on page 7 undefined on input line 178.
LaTeX Warning: Citation `ARTICLE:4' on page 7 undefined on input line 179.
LaTeX Warning: Citation `INBOOK:3' on page 7 undefined on input line 180.
LaTeX Warning: Citation `WEBSITE:1' on page 7 undefined on input line 181.
LaTeX Warning: There were undefined references.
LaTeX Warning: Label(s) may have changed. Rerun to get cross-references right.
LaTeX Warning: Citation `BOOK:2' on page 1 undefined on input line 28.
LaTeX Warning: Citation `BOOK:1' on page 7 undefined on input line 178.
LaTeX Warning: Citation `ARTICLE:4' on page 7 undefined on input line 179.
LaTeX Warning: Citation `INBOOK:3' on page 7 undefined on input line 180.
LaTeX Warning: Citation `WEBSITE:1' on page 7 undefined on input line 181.
答案1
您的问题来自 bib 文件中的以下几行:
@MISC{WEBSITE:1,
HOWPUBLISHED = "\url{http://example.com}",
命令仅\url
在调用包后定义。您必须在序言中加载其中一个包。url
hyperref
此处的 bib 条目键在 TeX 代码中WEBSITE:1
引用时不适用: 。将有效引用的键更改为: 。\cite{example}
\cite{WEBSITE:1}
使用以下 MWE
\RequirePackage{filecontents}
\begin{filecontents*}{\jobname.bib}
@BOOK{BOOK:1,
AUTHOR = "John Doe",
TITLE = "The Book without Title",
PUBLISHER = "Dummy Publisher",
YEAR = "2100",
}
@INBOOK{INBOOK:3,
AUTHOR="John Doe",
TITLE="The Book without Title",
PUBLISHER="Dummy Publisher",
YEAR="2100",
PAGES="100-200",
}
@ARTICLE{ARTICLE:4,
AUTHOR="John Doe",
TITLE="Title",
JOURNAL="Journal",
YEAR="2017",
}
@MISC{WEBSITE:1,
HOWPUBLISHED = "\url{http://example.com}",
AUTHOR = "Intel",
TITLE = "Example Website",
MONTH = "Dec",
YEAR = "1988",
NOTE = "Accessed on 2012-11-11",
}
\end{filecontents*}
\documentclass{article}
\title{About cats}
\date{2013-11-20}
\author{name}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{float}
\usepackage{subcaption}
\usepackage{url} % <====================================================
\begin{document}
%... a bunch of stuff
\paragraph{} Here is an example of a citation embedded in text. Random
citation \cite{BOOK:1} embedded in text.
\paragraph{} Here is an example of an article citation. Yet another
random citation \cite{ARTICLE:4} embedded in text.
\paragraph{} Here is an example of an "inbook" citation with page
numbers mentioned. Another random citation \cite{INBOOK:3} embedded in
text.
\paragraph{} Here is example of a website citation. One more random
citation \cite{WEBSITE:1} embedded in text. % <===========================
\bibliographystyle{ieeetr}
\bibliography{\jobname}
\end{document}
编译时您将获得以下结果,且没有任何错误:
当然你必须用,,,pdflatex
进行编译。bibtex
pdflatex
pdflatex
您的错误信息
l.19 Intel, ``Example website.'' \url
{http://example.com}, Dec 1988.
LaTeX Warning: Citation `BOOK:2' on page 1 undefined on input line 28.
有两个原因:
- 如上所述,您需要加载包
url
或hyperrref
获取定义的命令\url
。 - 消息
Citation
BOOK:2' 在第 1 页未定义means that you missed to call
bibtex hello_latexto get the bibliography file
hello_latex.bbl. You can use the terminal/console to type and execute this command or check how your used editor invokes
bibtex`(抱歉,我不使用您的编辑器,请检查它的文档)。