在doxygen中编号的锚点

pmr*_*pmr 6 anchor doxygen

我在doxygen中有相当多的锚点,例如

\anchor pic_foo
\image html foo.gif "My Caption"
\anchor pic_bar
\image html bar.gif "My Caption"
Run Code Online (Sandbox Code Playgroud)

每当我用它\ref来链接其中一个时,我必须编写一些不错的描述,因此锚的原始名称不会出现在输出中.

是否有可能在doxygen中有类似编号的锚点,其中链接文本将是该锚点的编号?理想情况如下:

\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...
Run Code Online (Sandbox Code Playgroud)

理想情况下应转化为:

As Figure 1 shows... Figure 2 is...
Run Code Online (Sandbox Code Playgroud)

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

Chr*_*ris 4

我认为 doxygen 不可能自动计算页面内或整个文档中的数字数量(我很乐意在这里得到纠正)。但是,解决您问题的一个简单方法是用拼写出来的数字替换锚文本,即“一”、“二”、“三”...等。或者,如果您有很多数字,则可以使用罗马数字。普通数字似乎不能用作锚链接。

然后,您的示例将变成,并在图形标题中添加附加文本,

\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...
Run Code Online (Sandbox Code Playgroud)

导致

Here Figure one shows... Figure two is...
Run Code Online (Sandbox Code Playgroud)

与您的数字的onetwo链接。

然后,您可以在配置文件中定义一个别名,例如\fref,定义为Figure \ref将自动在超链接数字前面添加文本“Figure”。

这个解决方案可以接受吗?我能想到的唯一其他替代方案涉及对 doxygen 输出进行后处理,但上述解决方案是迄今为止最简单的。

更新

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

# 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
Run Code Online (Sandbox Code Playgroud)

运行此脚本会产生输出

\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...
Run Code Online (Sandbox Code Playgroud)

修改上述脚本以从标准输入读取并写入标准输出很简单,因此可以轻松地与INPUT_FILTER配置文件选项结合使用。

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

  • 很不错。当我实现脚注时,我偶然发现了另一种可能的解决方案。你可以使用JQuery!在我意识到这一点之后,我对 doxygen 文档的思考达到了一个全新的水平。 (2认同)