我在 VS Code 上用 Elsvier 的 latex 模板写了一个草稿,但是在 VS Code 上编译 .tex 文件时,图表的交叉引用出错,显示“图 ??? 显示 xxxx”。但是在 texStudio 上编译时没有错误。
代码如下:
\documentclass[preprint,3p,authoryear]{elsarticle}
\usepackage{amssymb}
\usepackage{cite}
\usepackage{rotating}
%\usepackage[pdftex]{graphicx}
%\usepackage{pdfpages}
\usepackage[cmex10]{amsmath}
\usepackage{tabu}
\usepackage{algorithmic}
\usepackage{array}
\usepackage{booktabs}
\usepackage{url}
\usepackage{varioref}
\usepackage{hyperref}
\usepackage{cleveref}
\journal{Remote Sensing of Environment}
\begin{document}
\begin{frontmatter}
...
% this is about authors, title or something like that...
\end{frontmatter}
\section{Results}
\begin{figure*}[h!]
\centering
\includegraphics[scale=0.48]{figure_eps/condensed__WG_LAInsc_CLUShist__climatology.eps}
\caption{Here shows the histogram of }
\label{fig_nsc_hist_sig}
\end{figure*}
Figure \ref{fig_nsc_hist_sig} shows xxxxx.
\end{document}
在 PDF 中它显示“图 ??? 显示 xxxxx”...并且 VS Code 的 settings.json 是
{
"latex-workshop.latex.recipes": [
{
"name": "xelatexb",
"tools": [
"xelatex",
"bibtex",
"xelatex",
"xelatex"
]
},
{
"name": "xelatex",
"tools": [
"xelatex",
"bibtex",
"xelatex"
]
},
{
"name": "latexmk",
"tools": [
"latexmk"
]
},
{
"name": "xelatex -> bibtex -> xelatex*2",
"tools": [
"xelatex",
"bibtex",
"xelatex",
"xelatex"
]
},
{
"name": "pdflatex -> bibtex -> pdflatex*2",
"tools": [
"pdflatex",
"bibtex",
"pdflatex",
"pdflatex"
]
}
],
"latex-workshop.latex.tools": [
{
"name": "xelatex",
"command": "xelatex",
"args": [
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"%DOC%"
]
},
{
"name": "latexmk",
"command": "latexmk",
"args": [
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"-pdf",
"%DOC%"
]
},
{
"name": "pdflatex",
"command": "pdflatex",
"args": [
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"%DOC%.tex"
]
},
{
"name": "bibtex",
"command": "bibtex",
"args": [
"%DOCFILE%"
]
}
],
"editor.wordWrap": "on",
"workbench.startupEditor": "newUntitledFile",
"latex-workshop.latex.clean.fileTypes": [
"*.aux",
"*.bbl",
"*.blg",
"*.idx",
"*.ind",
"*.lof",
"*.lot",
"*.out",
"*.toc",
"*.acn",
"*.acr",
"*.alg",
"*.glg",
"*.glo",
"*.gls",
"*.ist",
"*.fls",
"*.log",
"*.fdb_latexmk",
"*.gz"
],
"latex-workshop.view.pdf.viewer": "external",
"latex-workshop.view.pdf.external.viewer.command": "/Applications/Skim.app/Contents/SharedSupport/displayline",
"latex-workshop.view.pdf.external.viewer.args": [
"0",
"%PDF%"
],
"latex-workshop.view.pdf.external.synctex.command": "/Applications/Skim.app/Contents/SharedSupport/displayline",
"latex-workshop.view.pdf.external.synctex.args": [
"-r",
"-b",
"%LINE%",
"%PDF%",
"%TEX%",
],
"editor.fontSize": 14,
"workbench.colorTheme": "Visual Studio Light"
}
VS Code 的输出是:
This is BibTeX, Version 0.99d (TeX Live 2020)
The top-level auxiliary file: draft.aux
I found no \citation commands---while reading file draft.aux
I found no \bibdata command---while reading file draft.aux
I found no \bibstyle command---while reading file draft.aux
(There were 3 error messages)
看起来 BibTex 出了点问题。但我在 draft.tex 中有关于文献/论文的引用或外部参考的注释行。我在网上搜索了这个错误,但只发现有人试图运行 .tex 2 次以避免此错误。然而当我运行它两次时,我仍然收到此错误...
这是我运行相同的 draft.tex 并得到正确编译的 texstudio 的设置。
有谁能帮助我吗?非常感谢!
=============================== 很奇怪,我刚刚创建了一个这样的小例子:
\documentclass{article}
\usepackage{graphicx, color}
\usepackage{cite}
\begin{document}
This is for test
\begin{figure}[h]
\centering
\includegraphics[scale=1]{figure_png_jpg/Fig2_cluster_fig_cut.png}
\caption{The main land cover types and }
\label{fig:land_cover}
\end{figure}
The study domain is mapped in Figure \ref{fig:land_cover}
\end{document}
但结果仍然是“图xxx”...为了确保我运行了两次,我点击了VS Code右上角的“构建Latex项目”...然后将其作为pdf文件查看。不幸的是,仍然不起作用....
这是这个小测试文件(名为 test.tex)的日志信息。使用 Elsvier 编写的原始文件名为 draft.tex。
[20:33:21] File watcher - file changed: /Users/xushan/research/TUD/pub/1/ASCAT_DVP_RSE/test.tex
[20:33:21] Parsing a file and its subfiles: /Users/xushan/research/TUD/pub/1/ASCAT_DVP_RSE/test.tex
[20:33:21] Parse fls file.
[20:33:21] Cannot find fls file: /Users/xushan/research/TUD/pub/1/ASCAT_DVP_RSE/test.fls
[20:33:21] Auto build started detecting the change of a file: /Users/xushan/research/TUD/pub/1/ASCAT_DVP_RSE/test.tex
[20:33:21] BUILD command invoked.
[20:33:21] The document of the active editor: file:///Users/xushan/research/TUD/pub/1/ASCAT_DVP_RSE/test.tex
[20:33:21] The languageId of the document: latex
[20:33:21] Building root file: /Users/xushan/research/TUD/pub/1/ASCAT_DVP_RSE/test.tex
[20:33:21] Build root file /Users/xushan/research/TUD/pub/1/ASCAT_DVP_RSE/test.tex
[20:33:21] Recipe step 1: xelatex, -synctex=1,-interaction=nonstopmode,-file-line-error,/Users/xushan/research/TUD/pub/1/ASCAT_DVP_RSE/test
[20:33:21] cwd: /Users/xushan/research/TUD/pub/1/ASCAT_DVP_RSE
[20:33:21] LaTeX build process spawned. PID: 18033.
[20:33:22] LaTeX log parsed with 0 messages.
[20:33:22] A step in recipe finished. PID: 18033.
[20:33:22] Recipe step 2: bibtex, test
[20:33:22] cwd: /Users/xushan/research/TUD/pub/1/ASCAT_DVP_RSE
[20:33:22] LaTeX build process spawned. PID: 18037.
[20:33:22] Recipe returns with error: 2/null. PID: 18037. message: .
[20:33:22] The environment variable $PATH: /Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home/bin:/Users/xushan/opt/anaconda3/bin:/Users/xushan/opt/anaconda3/condabin:/Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/usr/local/laps:/Library/Apple/usr/bin:.:.
[20:33:22] The environment variable $SHELL: /bin/bash
[20:33:22] Cleaning auxiliary files and retrying build after toolchain error.
[20:33:22] File cleaned: /Users/xushan/research/TUD/pub/1/ASCAT_DVP_RSE/test.log
[20:33:22] File cleaned: /Users/xushan/research/TUD/pub/1/ASCAT_DVP_RSE/test.bbl
[20:33:22] File cleaned: /Users/xushan/research/TUD/pub/1/ASCAT_DVP_RSE/test.aux
[20:33:22] File cleaned: /Users/xushan/research/TUD/pub/1/ASCAT_DVP_RSE/test.blg
[20:33:22] File cleaned: /Users/xushan/research/TUD/pub/1/ASCAT_DVP_RSE/test.synctex.gz
[20:33:22] Recipe step 1: xelatex, -synctex=1,-interaction=nonstopmode,-file-line-error,/Users/xushan/research/TUD/pub/1/ASCAT_DVP_RSE/test
[20:33:22] cwd: /Users/xushan/research/TUD/pub/1/ASCAT_DVP_RSE
[20:33:22] LaTeX build process spawned. PID: 18038.
[20:33:23] LaTeX log parsed with 3 messages.
[20:33:23] A step in recipe finished. PID: 18038.
[20:33:23] Recipe step 2: bibtex, test
[20:33:23] cwd: /Users/xushan/research/TUD/pub/1/ASCAT_DVP_RSE
[20:33:23] LaTeX build process spawned. PID: 18042.
[20:33:23] Recipe returns with error: 2/null. PID: 18042. message: .
[20:33:23] The environment variable $PATH: /Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home/bin:/Users/xushan/opt/anaconda3/bin:/Users/xushan/opt/anaconda3/condabin:/Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/usr/local/laps:/Library/Apple/usr/bin:.:.
[20:33:23] The environment variable $SHELL: /bin/bash
答案1
今天也遇到了同样的问题,确实是因为缺少文件导致的.aux
,后来发现应该把 设置autoClean
为onFailed
,不然每次VS Code成功编译你的文件时,都会把等.tex
删除。.aux
.bcf
.loa
因此,如果您没有以下代码,则应添加或修改它:
"latex-workshop.latex.autoClean.run": "onFailed"