如何防止sphinx在交叉引用的目标中将大写字母替换为小写字母?

问题描述 投票:0回答:1

之所以如此,是因为我目前正在使用 sphinx 将旧文档更改为新文档。旧文档使用 t2t 文件,其中有很多用大写字母编写的参考文献。我将 t2t 转换为 rst,并且必须进行一些调整,所以大部分都有效。 但有一个问题尚未解决:Sphinx 在转换为 .tex 文件时将参考目标的大写字母更改为小写,但不会将 hyperrefs 中的大写字母更改为小写。

现在我已将 testfile.t2t 转换为 testfile.rst,还使用了一些脚本,其中大部分都有效。问题是 sphinx-build 更改了参考目标,例如:

.. _test-ONE:

小写版本:

\label{\detokenize{testfile:test-one}}

但文本本身中的引用保持其大写字母相同,例如:

`test_ONE <#test-ONE>`__ 

变成:

{\hyperref[\detokenize{testfile:test-ONE}]{\sphinxsamedocref{test_ONE}}}

因此,超级参考不起作用。

(这种转换也发生在 html 输出中)

现在我正在考虑编写一个脚本,仅仅将 .rst 文件的所有链接更改为小写就太多了,并且必须有一个使用 sphinx 本身的简单解决方案,但我自己还没有找到任何有效的解决方案。

所以我要么需要sphinx来防止将目标转换为小写,要么也将将超引用转换为小写。

...

我找到了一个解决方案,指出我应该将以下内容添加到我的conf.py中,这可以防止sphinx转换为小写,但它不起作用:

latex_elements = {
    'preamble': r'''
        \usepackage{textcase}
        \let\MakeUppercase\relax
        \let\MakeTextUppercase\relax
    '''

我还没有找到将 hyperrefs 转换为小写的解决方案。

python-sphinx restructuredtext
1个回答
0
投票

参考名称的小写是一项重构文本功能。

问题不仅限于 LaTeX,在 HTML 中也会是:

<p id="test-one">The problem is sphinx-build changes a reference target
to a lower case version.</p>
<p>The references within the text itself stays the same
with its capital letters,
like: <a class="reference external" href="#test-ONE">test_ONE</a>.</p>

解决方案是将嵌入式 URI 引用替换为 嵌入式别名(这也有助于引用 ID 中不支持的字符):

The references within the text are normalized, too,
if they use an alias 
like: `see the first test <test-ONE_>`__.

如果引用文本和引用名称相同,则无需嵌入目标(简单引用时反引号是可选的):

Use the reference name (with any casing) 
in a simple reference or reference phrase, 
like test-one_, `Test-one`_ or `test-ONE`_.
© www.soinside.com 2019 - 2024. All rights reserved.