gpt4 book ai didi

anchor - doxygen 中的编号 anchor

转载 作者:行者123 更新时间:2023-12-04 15:25:11 30 4
gpt4 key购买 nike

我有很多 anchor 可以在 doxygen 中描绘,例如

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

每次使用时 \ref要链接其中之一,我必须弥补
一些很好的描述,所以 anchor 的原始名称不会出现在
输出。

是否有可能在 doxygen 中有类似编号的 anchor
链接文本将是该 anchor 的编号?理想情况下
就像是:
\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...

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

最佳答案

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

然后,您的示例将变为,在图标题中带有附加文本,

\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超链接到您的数字。

然后你可以在你的配置文件中定义一个别名,比如 \fref ,定义为 Figure \ref它将自动在超链接数字之前加上文本“图”。

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

更新

以下 Python 代码将 anchor 引用转换为递增计数器:
# 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 结合使用。配置文件选项。

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

关于anchor - doxygen 中的编号 anchor ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11799435/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com