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

标签 python pdf tex latexmk

当我想运行 python 脚本时遇到错误:

错误如下:

enter image description here

代码如下:

#!/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

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

关于 python -latexmk : error: no such option: -d,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47493344/

相关文章:

python - CSV 字符串在 python 列表中转换为十进制

c# - 转换图章页面时 PDF 到 PostScript 的转换速度很慢

java - 使用pdfbox在java中将pdf文件转换为图像时缺少文本

formatting - LyX——在 View 中使用 Elsevier 类时缺少标题、摘要、关键字

python - 如何在 matplotlib 输出中获得与 Latex 输出中相同的字体(-style、-size 等)?

python - 正则表达式 - 将子字符串与字符串匹配

python - 为什么这个循环会随着时间的二次方缩放

python - 如何通过重复字符查找和拆分字符串?

iOS:读取PDF文件的内容

regex - 将 `"`引号改成latex风格