SF.net SVN: docutils:[10215 ] trunk/docutils
milde--- via Docutils-checkins <[email protected]> Wed, 20 Aug 2025 12:04:20 +0000
| Newsgroups | gmane.text.docutils.cvs |
|---|---|
| Message-ID | <[email protected]> |
Revision: 10215
http://sourceforge.net/p/docutils/code/10215
Author: milde
Date: 2025-08-20 12:04:19 +0000 (Wed, 20 Aug 2025)
Log Message:
-----------
LaTeX writer: set anchor for math-block with target/label.
The "hyperref" LaTeX package sets an anchor for hyperlinks to math blocks,
if they are numbered. The "math" directive generates unnumbered math blocks.
Prepend a `\phantomsection` to manually set an anchor so that hyperlinks
go to the right place.
Modified Paths:
--------------
trunk/docutils/HISTORY.rst
trunk/docutils/docutils/writers/latex2e/__init__.py
trunk/docutils/test/functional/expected/latex_memoir.tex
trunk/docutils/test/functional/expected/standalone_rst_latex.tex
trunk/docutils/test/functional/expected/standalone_rst_xetex.tex
Modified: trunk/docutils/HISTORY.rst
===================================================================
--- trunk/docutils/HISTORY.rst 2025-08-20 09:39:58 UTC (rev 10214)
+++ trunk/docutils/HISTORY.rst 2025-08-20 12:04:19 UTC (rev 10215)
@@ -41,7 +41,11 @@
- Better error reports for hyperlinks with embedded URI or alias.
+* docutils/writers/latex2e/__init__.py
+ - Prepend ``\phantomsection`` to labelled math-blocks.
+
+
Release 0.22 (2026-07-29)
=========================
@@ -189,6 +193,7 @@
* docutils/transforms/references.py
+ - Make `AnonymousHyperlinks` transform idempotent.
- New transform `CitationReferences`. Marks citation_references
as resolved if BibTeX is used by the backend (LaTeX).
@@ -196,10 +201,6 @@
- Removed `Compound` transform.
-* docutils/transforms/references.py
-
- - Make `AnonymousHyperlinks` transform idempotent.
-
* docutils/transforms/universal.py
- `Messages` transform now also handles "loose" system messages
Modified: trunk/docutils/docutils/writers/latex2e/__init__.py
===================================================================
--- trunk/docutils/docutils/writers/latex2e/__init__.py 2025-08-20 09:39:58 UTC (rev 10214)
+++ trunk/docutils/docutils/writers/latex2e/__init__.py 2025-08-20 12:04:19 UTC (rev 10215)
@@ -2725,16 +2725,21 @@
def visit_math_block(self, node) -> None:
self.requirements['amsmath'] = r'\usepackage{amsmath}'
+ math_env = pick_math_environment(node.astext())
+ self.out.append('%\n')
+ if node['ids'] and math_env.endswith('*'): # non-numbered equation
+ self.out.append('\\phantomsection\n')
for cls in node['classes']:
self.provide_fallback('inline')
- self.out.append(r'\DUrole{%s}{' % cls)
- math_env = pick_math_environment(node.astext())
- self.out += [f'%\n\\begin{{{math_env}}}\n',
+ self.out.append(f'\\DUrole{{{cls}}}{{%\n')
+ self.out += [f'\\begin{{{math_env}}}\n',
node.astext().translate(unichar2tex.uni2tex_table),
'\n',
*self.ids_to_labels(node, set_anchor=False, newline=True),
f'\\end{{{math_env}}}']
- self.out.append('}' * len(node['classes']))
+ if node['classes']:
+ self.out.append('\n')
+ self.out.append('}' * len(node['classes']))
raise nodes.SkipNode # content already processed
def depart_math_block(self, node) -> None:
Modified: trunk/docutils/test/functional/expected/latex_memoir.tex
===================================================================
--- trunk/docutils/test/functional/expected/latex_memoir.tex 2025-08-20 09:39:58 UTC (rev 10214)
+++ trunk/docutils/test/functional/expected/latex_memoir.tex 2025-08-20 12:04:19 UTC (rev 10215)
@@ -1807,6 +1807,7 @@
The determinant of the matrix
%
+\phantomsection
\begin{equation*}
\mathbf{M} = \left(\begin{matrix}a&b\\c&d\end{matrix}\right)
\label{eq-m}
@@ -1827,6 +1828,7 @@
The Schrödinger equation
%
+\phantomsection
\begin{equation*}
i\hbar \frac{\partial }{\partial t}\Psi = \hat{H}\Psi ,
\label{eq-schrodinger}
Modified: trunk/docutils/test/functional/expected/standalone_rst_latex.tex
===================================================================
--- trunk/docutils/test/functional/expected/standalone_rst_latex.tex 2025-08-20 09:39:58 UTC (rev 10214)
+++ trunk/docutils/test/functional/expected/standalone_rst_latex.tex 2025-08-20 12:04:19 UTC (rev 10215)
@@ -1822,6 +1822,7 @@
The determinant of the matrix
%
+\phantomsection
\begin{equation*}
\mathbf{M} = \left(\begin{matrix}a&b\\c&d\end{matrix}\right)
\label{eq-m}
@@ -1842,6 +1843,7 @@
The Schrödinger equation
%
+\phantomsection
\begin{equation*}
i\hbar \frac{\partial }{\partial t}\Psi = \hat{H}\Psi ,
\label{eq-schrodinger}
Modified: trunk/docutils/test/functional/expected/standalone_rst_xetex.tex
===================================================================
--- trunk/docutils/test/functional/expected/standalone_rst_xetex.tex 2025-08-20 09:39:58 UTC (rev 10214)
+++ trunk/docutils/test/functional/expected/standalone_rst_xetex.tex 2025-08-20 12:04:19 UTC (rev 10215)
@@ -1851,6 +1851,7 @@
The determinant of the matrix
%
+\phantomsection
\begin{equation*}
\mathbf{M} = \left(\begin{matrix}a&b\\c&d\end{matrix}\right)
\label{eq-m}
@@ -1871,6 +1872,7 @@
The Schrödinger equation
%
+\phantomsection
\begin{equation*}
i\hbar \frac{\partial }{\partial t}\Psi = \hat{H}\Psi ,
\label{eq-schrodinger}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
_______________________________________________
Docutils-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/docutils-checkins