由于 Overleaf 平台中“缺少 Pygments 输出”,minted 软件包无法工作

由于 Overleaf 平台中“缺少 Pygments 输出”,minted 软件包无法工作

我在 Overleaf 中使用 LaTex。在序言中,我写道

% Typesetting code
\definecolor{bg}{rgb}{0.95,0.95,0.95}
\usepackage{minted}
\usemintedstyle{friendly}
\newminted{python}{mathescape,frame=lines,framesep=4mm,bgcolor=bg}
\newminted{ipython}{mathescape,frame=lines,framesep=4mm,bgcolor=bg}

我在投影机的主体中写道

\begin{frame}[fragile]
\begin{minted}{python}

    In [1]: import numpy as np

    In [2]: x = np.array((2, 4, 6))

    In [3]: y = np.array((10, 10, 10))

    In [4]: x + y  # Vector addition
    Out[4]: array([12, 14, 16])

    In [6]: 2 * x  # Scalar multiplication
    Out[6]: array([ 4,  8, 12])
\end{minted}
\end{frame}

在我编译它之后,Python 代码没有出现在幻灯片中(该幻灯片是空白的。我还收到错误消息:

Package minted Error: Missing Pygments output; \inputminted was I 
probably given a file that does not exist--otherwise, you may need 
the outputdir package option, or may be using an incompatible build tool,
or may be using frozencache with a missing file.

See the minted package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              
                                                  
l.20 \end{minted}
                 
This could be caused by using -output-directory or -aux-directory 
without setting minted's outputdir, or by using a build tool that 
changes paths in ways minted cannot detect, 
or using frozencache with a missing file.

\documentclass{beamer}

\definecolor{bg}{rgb}{0.95,0.95,0.95}
\usepackage{minted}
\usemintedstyle{friendly}
\newminted{python}{mathescape,frame=lines,framesep=4mm,bgcolor=bg}
\newminted{ipython}{mathescape,frame=lines,framesep=4mm,bgcolor=bg}

\begin{document}

\begin{frame}[fragile]
\begin{minted}{python}

    In [1]: import numpy as np

    In [2]: x = np.array((2, 4, 6))

    In [3]: y = np.array((10, 10, 10))

    In [4]: x + y  # Vector addition
    Out[4]: array([12, 14, 16])

    In [6]: 2 * x  # Scalar multiplication
    Out[6]: array([ 4,  8, 12])
\end{minted}
\end{frame}

\end{document}

答案1

您需要将主文件放在顶层,以便 overleaf 调用可以在正确的位置进行。

在左侧边栏中将所有内容拖出目录:

https://www.overleaf.com/read/qttzghkrzfzr

在此处输入图片描述

相关内容