python - latexmk: error: no such option: -d

python - latexmk: error: no such option: -d

当我想要 运行 一个 python 脚本时出现错误:

错误如下:

代码如下:

#!/usr/bin/python
import subprocess
code_dir = "code"
title = "Stanford ACM-ICPC Team Notebook"

def get_sections():
    sections = []
    section_name = None
    with open('contents.txt', 'r') as f:
        for line in f:
            if '#' in line: line = line[:line.find('#')]
            line = line.strip()
            if len(line) == 0: continue
            if line[0] == '[':
                section_name = line[1:-1]
                subsections = []
                if section_name is not None:
                    sections.append((section_name, subsections))
            else:
                tmp = line.split('\t', 1)
                if len(tmp) == 1:
                    raise ValueError('Subsection parse error: %s' % line)
                filename = tmp[0]
                subsection_name = tmp[1]
                if subsection_name is None:
                    raise ValueError('Subsection given without section')
                subsections.append((filename, subsection_name))
    return sections

def get_style(filename):
    ext = filename.lower().split('.')[-1]
    if ext in ['c', 'cc', 'cpp']:
        return 'cpp'
    elif ext in ['java']:
        return 'java'
    elif ext in ['py']:
        return 'py'
    else:
        return 'txt'

# TODO: check if this is everything we need
def texify(s):
    #s = s.replace('\'', '\\'')
    #s = s.replace('\"', '\\"')
    return s

def get_tex(sections):
    tex = ''
    for (section_name, subsections) in sections:
        tex += '\section{%s}\n' % texify(section_name)
        for (filename, subsection_name) in subsections:
            tex += '\subsection{%s}\n' % texify(subsection_name)
            tex += '\raggedbottom\lstinputlisting[style=%s]{%s/%s}\n' % (get_style(filename), code_dir, filename)
            tex += '\hrulefill\n'
        tex += '\n'
    return tex

if __name__ == "__main__":
    sections = get_sections()
    tex = get_tex(sections)
    with open('contents.tex', 'w') as f:
        f.write(tex)
    latexmk_options = ["latexmk", "-pdf", "notebook.tex"]
    subprocess.call(latexmk_options)

我已经尝试安装latexmk,但是没有成功。 你能帮我了解安装 latexmk 的详细说明吗?我已经用谷歌搜索了很多。对于版权,那甚至不是我的代码。它是来自 stanford acm 的代码,可以自己制作。现在我想自己做。

确保可以从命令行访问 latexmk。您可以通过在命令行中键入 latexmk -version 来检查这一点。如果无法从命令行访问它,则需要将 latexmk 路径添加到环境变量。

如果未安装 latexmk,请按照此 link 正确安装 latexmk

我认为按照这些步骤可能会解决您的问题。