在 VSCode 里调用 latexmk 显示不了参考文献,不知道是 LaTeX-Workshop 的问题还是宏包的问题?

发布于 2021-11-17 10:39:56

编译环境

操作系统

  • Windows 10

TeX发行版

  • TeX Live 2021

我的问题

我的文件夹下有两个文件:MWE.tex 和 reference.bib,在该文件夹下命令行运行 latexmk -pdfxe --shell-escape 能正确生成带参考文献的 pdf,但在 VSCode 中运行则生成不了参考文献,如果把 MWE.tex 第 10 行的 basicstyle=\ttfamily, 删去,则在 VSCode 中也能生成带参考文献的pdf。

MWE.tex 如下

\documentclass{ctexart}
\bibliographystyle{unsrt}

\usepackage{accsupp} % https://tex.stackexchange.com/a/57172
\newcommand{\emptyaccsupp}[1]{\BeginAccSupp{ActualText={}}#1\EndAccSupp{}}
\usepackage{listings}
\lstset{
    numbers=left,
    numberstyle=\emptyaccsupp,
    basicstyle=\ttfamily,
}
\usepackage{minted}
\setminted{
    linenos=true,
}
\renewcommand{\theFancyVerbLine}{
    \emptyaccsupp{\arabic{FancyVerbLine}}
} % texdoc minted

\begin{document}
根据\cite{Chen}
\begin{lstlisting}[language=C]
a
b
\end{lstlisting}
\begin{minted}{python}
c
d
\end{minted}
\bibliography{reference}
\end{document}

reference.bib 如下:

@article{Chen,
  title   = {用},
  author  = {陈},
  journal = {高},
  volume  = {11},
  number  = {5},
  pages   = {56--56},
  year    = {2008}
}

VSCode 中的 recipes 和 tools 设置如下:

"latex-workshop.latex.recipes": [
    {
        "name": "latexmk-Xe with shell escape",
        "tools": [
            "latexmk-Xe-with-shell-escape"
        ]
    },
],
"latex-workshop.latex.tools": [
    {
        "name": "latexmk-Xe-with-shell-escape",
        "command": "latexmk",
        "args": [
            "-synctex=1",
            "--shell-escape",
            "-interaction=nonstopmode",
            "-file-line-error",
            "-pdfxe",
            "-outdir=%OUTDIR%",
            "%DOCFILE%"
        ],
        "env": {}
    },
]

代码中所用的 accsupp 宏包是为了完成这样的效果:用 Adobe Acrobat Reader DC 打开生成的 pdf 并选择其中的代码环境时,不把行号也选进去。可见 https://tex.stackexchange.com/a/57172

跑出来的正确 pdf 如下:

image.png

显示不了参考文献的 pdf 如下:

image.png

我感觉我的 VSCode 配置应该也没错呀,为啥命令行能跑通(能生成参考文献),VSCode 跑不通(不能生成参考文献)呢?为啥删掉 basicstyle=\ttfamily, 就又能跑通呢?这为什么会影响参考文献的生成呢?我不知道问题出在哪。

谢谢!

附件压缩包 MWE.zip 内包括 MWE.tex、reference.bib 和 VSCode workspace 的 settings.json,供复现问题。在配置文件里我既试了@u40 在 install-latex 里提供的配置,也试了我自己的完整配置,都不能成功生成参考文献,也不知道问题出在哪。
MWE.zip

查看更多

关注者
0
被浏览
1.9k
1 个回答
雾月
雾月 2021-11-17
这家伙很懒,什么也没写!

应该是vscode的配置问题。LaTeX Workshop 配置有点迷。

宏包本身没有冲突。

而且,listingminted 使用一个就好了。

撰写答案

请登录后再发布答案,点击登录

发布
问题

分享
好友

手机
浏览

扫码手机浏览