doxygen中的编号锚点 [英] Numbered anchors in doxygen

查看:238
本文介绍了doxygen中的编号锚点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,我在Doxygen上有很多锚点图片.

I have quite a lot of anchors to picture in doxygen, e.g.

\anchor pic_foo
\image html foo.gif "My Caption"
\anchor pic_bar
\image html bar.gif "My Caption"

每次我使用\ref链接其中之一时,我都必须弥补 一些不错的描述,以便锚的原始名称不会出现在 输出.

Everytime when I use \ref to link one of those, I have to make up some nice description so the raw name of the anchor doesn't appear in output.

是否有可能在doxygen中使用编号的锚点 链接文本将在哪里显示该锚点的编号?理想地 像这样:

Is it possible to have something like numbered anchors in doxygen where the link text will be the number of that anchor? Ideally something like:

\anchor pic_foo
\image html foo.gif "My Caption"
\anchor pic_bar
\image html bar.gif "My Caption"

As Figure \ref pic_foo shows... Figure \ref pic_bar is...

理想情况下应翻译为:

As Figure 1 shows... Figure 2 is...

其中的数字是链接.我会对每种计数方案(全局文档或本地页面)感到满意.

where the number is the link. I would be happy with every kind of counting scheme (documentation global or page local).

推荐答案

我认为使用doxygen不可能在页面内或整个文档中自动显示数字(我很乐意予以纠正这里).但是,解决您的问题的一个简单方法是将锚文本替换为拼写数字,即一个",两个",三个" ...等.或者,如果您有很多数字,则可以使用罗马数字.普通数字似乎不能用作锚点链接.

I don't think that automatic number of figures, either within a page or across the whole documentation, is possible with doxygen (I would be happy to be corrected here). However, an easy solution to your question is the replace your anchor text with spelt out numbers, i.e. "one", "two", "three"... etc. Alternatively, if you have lots of figures you could use Roman numerals. Plain numbers don't seem to work as anchor links.

您的示例将变得如此,在图形标题中带有其他文本,

Your example will then become, with additional text in the figure captions,

\anchor one
\image html foo.gif "Figure one: My Caption"
\anchor two
\image html bar.gif "Figure two: My Caption"

As Figure \ref one shows... Figure \ref two is...

导致

Here Figure one shows... Figure two is...

具有onetwo的超链接到您的图形.

with one and two hyperlinks to your figures.

然后,您可以在配置文件中定义一个别名,例如\fref,定义为Figure \ref,它将自动在超链接的数字前加上文本"Figure".

You can then define a alias in your configuration file, say \fref, defined to be Figure \ref which will automatically preceed the hyperlinked numbers with the text "Figure".

此解决方案可以接受吗?我能想到的唯一其他选择是对氧气输出进行后期处理,但是上述解决方案到目前为止是最简单的.

Is this solution acceptable? The only other alternative I can think of involves post processing the doxygen output, but the above solution is by far the simplest.

更新

以下Python代码会将锚点引用转换为递增计数器:

The following Python code will transform anchor references to an incrementing counter:

# Test documentation.
s = r"""
\anchor pic_foo
\image html foo.gif "My Caption"
\anchor pic_bar
\image html bar.gif "My Caption"

As Figure \ref pic_foo shows... Figure \ref pic_bar is...
"""

# Split string into a list of lines.
s = s.split('\n')

# Dictionaries for mapping anchor names to an incrementing counter.
d = {}

numbers = {1: 'one',
    2 : 'two',
    3 : 'three'}

counter = 1

# Find all anchor links and map to the next counter value.
for line in s:
    if r'\anchor' in line:
        d[line.split(r'\anchor ')[1]] = numbers[counter]
        counter += 1

# Reform original string.
s = '\n'.join(s)

# Replace anchor links with appropriate counter value.
for key, value in d.items():
    s = s.replace(key, value)

print s

运行此脚本会得到输出

\anchor one
\image html foo.gif "My Caption"
\anchor two
\image html bar.gif "My Caption"

As Figure \ref one shows... Figure \ref two is...

修改上述脚本以从标准输入中读取并写入标准输出是微不足道的,因此可以轻松地将其与INPUT_FILTER配置文件选项结合使用.

It is trivial to modify the above script to read from standard input and write to standard out, so this can easily be used in conjunction with the INPUT_FILTER configuration file option.

要注意的一件事是,必须扩展字典numbers以允许包含三个以上的数字.这又是微不足道的,但可能不容易扩展.提供了从任意数字到适当的单词的映射的解决方案(请参阅本网站上的其他问题),因此我不必费心在这里实现它.

One thing to note is that the dictionary numbers has to be extended to allow for more than three figures to be included. This is again trivial, but probably not easily scalable. Solutions for mapping from arbitrary numbers to the appropriate word(s) are available (see other questions on this site) so I haven't bothered to implement this here.

这篇关于doxygen中的编号锚点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆