【发布时间】:2019-05-08 05:39:38
【问题描述】:
我正在尝试使用sphinxcontrib.bibtex 在某些文档中包含引用/参考。它说你可以set the style 使用:
.. bibliography: refs.bib
:style: plain
它带有以下样式:alpha、plain,它们创建的参考标签如下所示:
-
alpha:[ZieglerBenderSchreiber+14]或[TMT14]或[PCY+16a] -
plain:[1],[2],[3]
我发现alpha 不一致,但我认为plain 的数字缺乏上下文。要自定义格式,它提供了以下示例:
from pybtex.style.formatting.unsrt import Style as UnsrtStyle
from pybtex.style.template import toplevel # ... and anything else needed
from pybtex.plugin import register_plugin
class MyStyle(UnsrtStyle):
def format_XXX(self, e):
template = toplevel [
# etc.
]
return template.format_data(e)
register_plugin('pybtex.style.formatting', 'mystyle', MyStyle)
sphinx 失败了:
sphinx-build -M html . out
Running Sphinx v1.8.3
Configuration error:
There is a syntax error in your configuration file: bad input (conf.py, line 92)
Did you change the syntax from 2.x to 3.x?
它似乎在后台使用pybtex,因此请遵循该文档中的示例:
from pybtex.style.formatting import BaseStyle
from pybtex.richtext import Text, Tag
class MyStyle(BaseStyle):
def format_article(self, entry):
return Text('Article ', Tag('em', entry.fields['title']))
from pybtex.plugin import register_plugin
register_plugin('pybtex.style.formatting', 'mystyle', MyStyle)
狮身人面像失败了:
Exception occurred:
File "/home/josh/codes/docs/conf.py", line 88, in format_article
return Text('Article ', Tag('em', entry.fields['title']))
AttributeError: 'dict' object has no attribute 'fields'
The full traceback has been saved in /tmp/sphinx-err-dftwlzvr.log, if you want to report the issue to the developers.
...我认为这只是自定义参考书目条目文本而不是标签文本。如何自定义标签文本?我更喜欢以下之一:
- 只是括号数字 (
[1]),如plain,但带有上标标签 - 类似于
[ref.12]类似于eq.12或fig.12 - 类似于
alpha,但字符数一致
【问题讨论】:
标签: python python-sphinx restructuredtext pybtex