Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ Bugs fixed
:confval:`numfig` is not True
* #8442: LaTeX: some indexed terms are ignored when using xelatex engine
(or pdflatex and :confval:`latex_use_xindy` set to True) with memoir class
* #8780: LaTeX: long words in narrow columns may not be hyphenated

Testing
--------
Expand Down
6 changes: 1 addition & 5 deletions doc/extdev/deprecated.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,13 @@ The following is a list of deprecated interfaces.

.. tabularcolumns:: |>{\raggedright}\Y{.4}|>{\centering}\Y{.1}|>{\centering}\Y{.12}|>{\raggedright\arraybackslash}\Y{.38}|

.. |LaTeXHyphenate| raw:: latex

\hspace{0pt}

.. list-table:: deprecated APIs
:header-rows: 1
:class: deprecated
:widths: 40, 10, 10, 40

* - Target
- |LaTeXHyphenate|\ Deprecated
- Deprecated
- (will be) Removed
- Alternatives

Expand Down
8 changes: 8 additions & 0 deletions doc/latex.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1024,6 +1024,14 @@ Environments
Miscellany
~~~~~~~~~~

- Every text paragraph in document body starts with `\sphinxAtStartPar`.
Currently, this is used to insert a zero width horizontal skip which
is a trick to allow TeX hyphenation of the first word of a paragraph
in a narrow context (like a table cell). For ``'lualatex'`` which
does not need the trick, the `\sphinxAtStartPar` does nothing.

.. versionadded:: 3.5.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know this change will break PDF generation. But it would be better to add big change into the next major release. It's planned for this April.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To the best of my knowledge the change can not break PDF generation. As far as I can tell, at worst it could add an extra blank line if the first child is implemented via a "vertical" environment: typically a list, but this seems excluded: in my understanding a list can not be first child of a paragraph node. An image is not a problem if it is not embedded into "figure" (for example I image inserted from a substitution). I tested that math like equation or align do not seem to be affected. At any rate there is no way I can see this can break PDF build whatever nodes follow. The only thing it can cause is this extra blank line. But I can not construct an example from rst source creating this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To the best of my knowledge the change can not break PDF generation.

Okay. I understand and agreed this does not break PDF generation. Let us see what will be reported.

(for example I image inserted from a substitution)

Fortunately, reST's substitution only allows inline elements. Nobody can't insert non "inline" elements under the paragraph node without hacks (by raw node or extensions).

A substitution definition block contains an embedded inline-compatible directive (without the leading ".. "), such as "image" or "replace".
https://docutils.sourceforge.io/docs/ref/rst/restructuredtext.html#substitution-definitions


- The section, subsection, ... headings are set using *titlesec*'s
``\titleformat`` command.

Expand Down
5 changes: 5 additions & 0 deletions sphinx/texinputs/sphinx.sty
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,11 @@
\DisableKeyvalOption{sphinx}{numfigreset}
\DisableKeyvalOption{sphinx}{nonumfigreset}
\DisableKeyvalOption{sphinx}{mathnumfig}
% To allow hyphenation of first word in narrow contexts; no option,
% customization to be done via 'preamble' key
\newcommand*\sphinxAtStartPar{\nobreak\hskip\z@skip}
% No need for the \hspace{0pt} trick (\hskip\z@skip) with luatex
\ifdefined\directlua\let\sphinxAtStartPar\@empty\fi
% user interface: options can be changed midway in a document!
\newcommand\sphinxsetup[1]{\setkeys{sphinx}{#1}}

Expand Down
4 changes: 3 additions & 1 deletion sphinx/writers/latex.py
Original file line number Diff line number Diff line change
Expand Up @@ -1161,7 +1161,9 @@ def visit_paragraph(self, node: Element) -> None:
# (first one is label node)
pass
else:
self.body.append('\n')
# the \sphinxAtStartPar is to allow hyphenation of first word of
# a paragraph in narrow contexts such as in a table cell
self.body.append('\n\\sphinxAtStartPar\n')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The children of paragraph node are regularly text nodes or inline nodes. It is defined at the doctree specification.
https://docutils.sourceforge.io/docs/ref/doctree.html

Almost of the inline nodes are decorated text. But, some of them are not; for example, math, image, problematic and raw. Additionally, some extensions might generate broken doctree under the paragraph node.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A math node is fine (via the math role), an image (via a substitution) also is no problem. As per raw latex, also inserted by a substitution then if the raw latex starts some list environment it will be shifted one line down, but it seems then a user error to do this, the raw directive should have been used directly to insert the LaTeX "display" material in place of "inline" material. I can not think of a natural example causing a problem, after all docutils "paragraph" concept pretty well matches with latex "paragraph" concept I hope.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. From my perspective, docutils' paragraph model and LaTeX's horizontal mode are similar. (But I did not mention that yesterday because I'm not familiar with LaTeX's mode :-p)


def depart_paragraph(self, node: Element) -> None:
self.body.append('\n')
Expand Down
5 changes: 5 additions & 0 deletions tests/roots/test-latex-equations/expects/latex-equations.tex
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@

\sphinxAtStartPar
Equation without a label.
\begin{equation*}
\begin{split}E = mc^2\end{split}
\end{equation*}
\sphinxAtStartPar
Equation with label.
\begin{equation}\label{equation:equations:test}
\begin{split}E = hv\end{split}
\end{equation}
\sphinxAtStartPar
Second equation without label.
\begin{equation*}
\begin{split}c^2 = a^2 + b^2\end{split}
\end{equation*}
\sphinxAtStartPar
Equation with label \eqref{equation:equations:test} is important.
15 changes: 15 additions & 0 deletions tests/roots/test-latex-table/expects/complex_spanning_cell.tex
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
\label{\detokenize{complex:complex-spanning-cell}}
\sphinxAtStartPar
table having …
\begin{itemize}
\item {}
\sphinxAtStartPar
consecutive multirow at top of row (1\sphinxhyphen{}1 and 1\sphinxhyphen{}2)

\item {}
\sphinxAtStartPar
consecutive multirow at end of row (1\sphinxhyphen{}4 and 1\sphinxhyphen{}5)

\end{itemize}
Expand All @@ -16,39 +19,51 @@
\hline
\sphinxmultirow{3}{1}{%
\begin{varwidth}[t]{\sphinxcolwidth{1}{5}}

\sphinxAtStartPar
cell1\sphinxhyphen{}1
\par
\vskip-\baselineskip\vbox{\hbox{\strut}}\end{varwidth}%
}%
&\sphinxmultirow{3}{2}{%
\begin{varwidth}[t]{\sphinxcolwidth{1}{5}}

\sphinxAtStartPar
cell1\sphinxhyphen{}2
\par
\vskip-\baselineskip\vbox{\hbox{\strut}}\end{varwidth}%
}%
&
\sphinxAtStartPar
cell1\sphinxhyphen{}3
&\sphinxmultirow{3}{4}{%
\begin{varwidth}[t]{\sphinxcolwidth{1}{5}}

\sphinxAtStartPar
cell1\sphinxhyphen{}4
\par
\vskip-\baselineskip\vbox{\hbox{\strut}}\end{varwidth}%
}%
&\sphinxmultirow{2}{5}{%
\begin{varwidth}[t]{\sphinxcolwidth{1}{5}}

\sphinxAtStartPar
cell1\sphinxhyphen{}5
\par
\vskip-\baselineskip\vbox{\hbox{\strut}}\end{varwidth}%
}%
\\
\cline{3-3}\sphinxtablestrut{1}&\sphinxtablestrut{2}&\sphinxmultirow{2}{6}{%
\begin{varwidth}[t]{\sphinxcolwidth{1}{5}}

\sphinxAtStartPar
cell2\sphinxhyphen{}3
\par
\vskip-\baselineskip\vbox{\hbox{\strut}}\end{varwidth}%
}%
&\sphinxtablestrut{4}&\sphinxtablestrut{5}\\
\cline{5-5}\sphinxtablestrut{1}&\sphinxtablestrut{2}&\sphinxtablestrut{6}&\sphinxtablestrut{4}&
\sphinxAtStartPar
cell3\sphinxhyphen{}5
\\
\hline
Expand Down
15 changes: 15 additions & 0 deletions tests/roots/test-latex-table/expects/gridtable.tex
Original file line number Diff line number Diff line change
Expand Up @@ -5,46 +5,61 @@
\begin{tabulary}{\linewidth}[t]{|T|T|T|}
\hline
\sphinxstyletheadfamily
\sphinxAtStartPar
header1
&\sphinxstyletheadfamily
\sphinxAtStartPar
header2
&\sphinxstyletheadfamily
\sphinxAtStartPar
header3
\\
\hline
\sphinxAtStartPar
cell1\sphinxhyphen{}1
&\sphinxmultirow{2}{5}{%
\begin{varwidth}[t]{\sphinxcolwidth{1}{3}}

\sphinxAtStartPar
cell1\sphinxhyphen{}2
\par
\vskip-\baselineskip\vbox{\hbox{\strut}}\end{varwidth}%
}%
&
\sphinxAtStartPar
cell1\sphinxhyphen{}3
\\
\cline{1-1}\cline{3-3}\sphinxmultirow{2}{7}{%
\begin{varwidth}[t]{\sphinxcolwidth{1}{3}}

\sphinxAtStartPar
cell2\sphinxhyphen{}1
\par
\vskip-\baselineskip\vbox{\hbox{\strut}}\end{varwidth}%
}%
&\sphinxtablestrut{5}&
\sphinxAtStartPar
cell2\sphinxhyphen{}3
\\
\cline{2-3}\sphinxtablestrut{7}&\sphinxstartmulticolumn{2}%
\sphinxmultirow{2}{9}{%
\begin{varwidth}[t]{\sphinxcolwidth{2}{3}}

\sphinxAtStartPar
cell3\sphinxhyphen{}2
\par
\vskip-\baselineskip\vbox{\hbox{\strut}}\end{varwidth}%
}%
\sphinxstopmulticolumn
\\
\cline{1-1}
\sphinxAtStartPar
cell4\sphinxhyphen{}1
&\multicolumn{2}{l|}{\sphinxtablestrut{9}}\\
\hline\sphinxstartmulticolumn{3}%
\begin{varwidth}[t]{\sphinxcolwidth{3}{3}}

\sphinxAtStartPar
cell5\sphinxhyphen{}1
\par
\vskip-\baselineskip\vbox{\hbox{\strut}}\end{varwidth}%
Expand Down
10 changes: 10 additions & 0 deletions tests/roots/test-latex-table/expects/longtable.tex
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
\begin{savenotes}\sphinxatlongtablestart\begin{longtable}[c]{|l|l|}
\hline
\sphinxstyletheadfamily
\sphinxAtStartPar
header1
&\sphinxstyletheadfamily
\sphinxAtStartPar
header2
\\
\hline
Expand All @@ -14,8 +16,10 @@
{\makebox[0pt]{\sphinxtablecontinued{\tablename\ \thetable{} \textendash{} continued from previous page}}}\\
\hline
\sphinxstyletheadfamily
\sphinxAtStartPar
header1
&\sphinxstyletheadfamily
\sphinxAtStartPar
header2
\\
\hline
Expand All @@ -27,18 +31,24 @@

\endlastfoot

\sphinxAtStartPar
cell1\sphinxhyphen{}1
&
\sphinxAtStartPar
cell1\sphinxhyphen{}2
\\
\hline
\sphinxAtStartPar
cell2\sphinxhyphen{}1
&
\sphinxAtStartPar
cell2\sphinxhyphen{}2
\\
\hline
\sphinxAtStartPar
cell3\sphinxhyphen{}1
&
\sphinxAtStartPar
cell3\sphinxhyphen{}2
\\
\hline
Expand Down
10 changes: 10 additions & 0 deletions tests/roots/test-latex-table/expects/longtable_having_align.tex
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
\begin{savenotes}\sphinxatlongtablestart\begin{longtable}[r]{|l|l|}
\hline
\sphinxstyletheadfamily
\sphinxAtStartPar
header1
&\sphinxstyletheadfamily
\sphinxAtStartPar
header2
\\
\hline
Expand All @@ -14,8 +16,10 @@
{\makebox[0pt]{\sphinxtablecontinued{\tablename\ \thetable{} \textendash{} continued from previous page}}}\\
\hline
\sphinxstyletheadfamily
\sphinxAtStartPar
header1
&\sphinxstyletheadfamily
\sphinxAtStartPar
header2
\\
\hline
Expand All @@ -27,18 +31,24 @@

\endlastfoot

\sphinxAtStartPar
cell1\sphinxhyphen{}1
&
\sphinxAtStartPar
cell1\sphinxhyphen{}2
\\
\hline
\sphinxAtStartPar
cell2\sphinxhyphen{}1
&
\sphinxAtStartPar
cell2\sphinxhyphen{}2
\\
\hline
\sphinxAtStartPar
cell3\sphinxhyphen{}1
&
\sphinxAtStartPar
cell3\sphinxhyphen{}2
\\
\hline
Expand Down
10 changes: 10 additions & 0 deletions tests/roots/test-latex-table/expects/longtable_having_caption.tex
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
\caption{caption for longtable\strut}\label{\detokenize{longtable:id1}}\\*[\sphinxlongtablecapskipadjust]
\hline
\sphinxstyletheadfamily
\sphinxAtStartPar
header1
&\sphinxstyletheadfamily
\sphinxAtStartPar
header2
\\
\hline
Expand All @@ -16,8 +18,10 @@
{\makebox[0pt]{\sphinxtablecontinued{\tablename\ \thetable{} \textendash{} continued from previous page}}}\\
\hline
\sphinxstyletheadfamily
\sphinxAtStartPar
header1
&\sphinxstyletheadfamily
\sphinxAtStartPar
header2
\\
\hline
Expand All @@ -29,18 +33,24 @@

\endlastfoot

\sphinxAtStartPar
cell1\sphinxhyphen{}1
&
\sphinxAtStartPar
cell1\sphinxhyphen{}2
\\
\hline
\sphinxAtStartPar
cell2\sphinxhyphen{}1
&
\sphinxAtStartPar
cell2\sphinxhyphen{}2
\\
\hline
\sphinxAtStartPar
cell3\sphinxhyphen{}1
&
\sphinxAtStartPar
cell3\sphinxhyphen{}2
\\
\hline
Expand Down
Loading