首页 > 解决方案 > 如何在 Sphinx 生成的 Latex 文档中添加版权声明?

问题描述

我已经设置了copyright配置值,它正确地出现在 HTML 输出中。但是,它根本没有出现在 LaTeX 输出中,而且我找不到任何可以让它出现的 LaTeX 输出选项。

如何使用 Sphinx 在 LaTeX 输出中自动包含版权声明?当然,我可以手动添加它或编写一个小脚本来添加它,但我希望在 Sphinx 框架内应该可以。

显然,需要改进以使其更容易。

标签: latexpython-sphinxcopyright-display

解决方案


如果你想要每一页的版权(在标题页和它的后面),你可以用这个满嘴的 LaTeX 宏来做到这一点(对不起,它会忽略copyright配置值)

latex_elements = {
    'preamble': r'''
\makeatletter
   \fancypagestyle{normal}{
% this is the stuff in sphinx.sty
    \fancyhf{}
    \fancyfoot[LE,RO]{{\py@HeaderFamily\thepage}}
% we comment this out and
    %\fancyfoot[LO]{{\py@HeaderFamily\nouppercase{\rightmark}}}
    %\fancyfoot[RE]{{\py@HeaderFamily\nouppercase{\leftmark}}}
% add copyright stuff
    \fancyfoot[LO,RE]{{This is \textcopyright\ 2019, Sphinx Team.}}
% again original stuff
    \fancyhead[LE,RO]{{\py@HeaderFamily \@title\sphinxheadercomma\py@release}}
    \renewcommand{\headrulewidth}{0.4pt}
    \renewcommand{\footrulewidth}{0.4pt}
    }
% this is applied to each opening page of a chapter
   \fancypagestyle{plain}{
    \fancyhf{}
    \fancyfoot[LE,RO]{{\py@HeaderFamily\thepage}}
    \renewcommand{\headrulewidth}{0pt}
    \renewcommand{\footrulewidth}{0.4pt}
% add copyright stuff for example at left of footer on odd pages,
% which is the case for chapter opening page by default
    \fancyfoot[LO,RE]{{This is \textcopyright\ 2019, Sphinx Team.}}
    }
\makeatother
''',
}

有关 LaTeX 语法的更多信息,请参阅fancyhdr 文档。你必须用 LaTeX 来逃避任何令人担忧的角色,比如$.

从 Sphinx 1.8.3 开始,您可以将 LaTeX 材料直接放在标题页的背面(对于'manual'docclass,因为 docclass 没有这样的概念'howto' ),您可以通过\sphinxbackoftitlepage它是可选的 LaTeX 宏,您可以在'preamble'或中定义'maketitle'。请参阅文档(您需要向下滚动到'maketitle')。

仅在一个位置发布版权似乎确实更有意义,所以为什么不在标题页的后面,因为它默认为空。('manual'文档类)


推荐阅读