Skip to content

Commit

Permalink
Fix sphinx-doc#8780: long words in narrow columns may not be hyphenated
Browse files Browse the repository at this point in the history
This is done by adding '\hskip0pt\relax\n' whenever a paragraph starts.
  • Loading branch information
jfbu committed Jan 28, 2021
1 parent 7f63c54 commit 185a2d2
Show file tree
Hide file tree
Showing 28 changed files with 269 additions and 244 deletions.
1 change: 1 addition & 0 deletions CHANGES
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
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
4 changes: 3 additions & 1 deletion sphinx/writers/latex.py
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 \hskip0pt\relax is to allow hyphenation of first word of
# a paragraph in narrow contexts such as in a table cell
self.body.append('\\hskip0pt\\relax\n')

def depart_paragraph(self, node: Element) -> None:
self.body.append('\n')
Expand Down
7 changes: 4 additions & 3 deletions tests/roots/test-latex-equations/expects/latex-equations.tex
@@ -1,13 +1,14 @@
\hskip0pt\relax
Equation without a label.
\begin{equation*}
\begin{split}E = mc^2\end{split}
\end{equation*}
\end{equation*}\hskip0pt\relax
Equation with label.
\begin{equation}\label{equation:equations:test}
\begin{split}E = hv\end{split}
\end{equation}
\end{equation}\hskip0pt\relax
Second equation without label.
\begin{equation*}
\begin{split}c^2 = a^2 + b^2\end{split}
\end{equation*}
\end{equation*}\hskip0pt\relax
Equation with label \eqref{equation:equations:test} is important.
15 changes: 10 additions & 5 deletions tests/roots/test-latex-table/expects/complex_spanning_cell.tex
@@ -1,10 +1,10 @@
\label{\detokenize{complex:complex-spanning-cell}}
\label{\detokenize{complex:complex-spanning-cell}}\hskip0pt\relax
table having …
\begin{itemize}
\item {}
\item {} \hskip0pt\relax
consecutive multirow at top of row (1\sphinxhyphen{}1 and 1\sphinxhyphen{}2)

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

\end{itemize}
Expand All @@ -16,39 +16,44 @@
\hline
\sphinxmultirow{3}{1}{%
\begin{varwidth}[t]{\sphinxcolwidth{1}{5}}
\hskip0pt\relax
cell1\sphinxhyphen{}1
\par
\vskip-\baselineskip\vbox{\hbox{\strut}}\end{varwidth}%
}%
&\sphinxmultirow{3}{2}{%
\begin{varwidth}[t]{\sphinxcolwidth{1}{5}}
\hskip0pt\relax
cell1\sphinxhyphen{}2
\par
\vskip-\baselineskip\vbox{\hbox{\strut}}\end{varwidth}%
}%
&
&\hskip0pt\relax
cell1\sphinxhyphen{}3
&\sphinxmultirow{3}{4}{%
\begin{varwidth}[t]{\sphinxcolwidth{1}{5}}
\hskip0pt\relax
cell1\sphinxhyphen{}4
\par
\vskip-\baselineskip\vbox{\hbox{\strut}}\end{varwidth}%
}%
&\sphinxmultirow{2}{5}{%
\begin{varwidth}[t]{\sphinxcolwidth{1}{5}}
\hskip0pt\relax
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}}
\hskip0pt\relax
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}&
\cline{5-5}\sphinxtablestrut{1}&\sphinxtablestrut{2}&\sphinxtablestrut{6}&\sphinxtablestrut{4}&\hskip0pt\relax
cell3\sphinxhyphen{}5
\\
\hline
Expand Down
18 changes: 11 additions & 7 deletions tests/roots/test-latex-table/expects/gridtable.tex
Expand Up @@ -4,47 +4,51 @@
\centering
\begin{tabulary}{\linewidth}[t]{|T|T|T|}
\hline
\sphinxstyletheadfamily
\sphinxstyletheadfamily \hskip0pt\relax
header1
&\sphinxstyletheadfamily
&\sphinxstyletheadfamily \hskip0pt\relax
header2
&\sphinxstyletheadfamily
&\sphinxstyletheadfamily \hskip0pt\relax
header3
\\
\hline
\hline\hskip0pt\relax
cell1\sphinxhyphen{}1
&\sphinxmultirow{2}{5}{%
\begin{varwidth}[t]{\sphinxcolwidth{1}{3}}
\hskip0pt\relax
cell1\sphinxhyphen{}2
\par
\vskip-\baselineskip\vbox{\hbox{\strut}}\end{varwidth}%
}%
&
&\hskip0pt\relax
cell1\sphinxhyphen{}3
\\
\cline{1-1}\cline{3-3}\sphinxmultirow{2}{7}{%
\begin{varwidth}[t]{\sphinxcolwidth{1}{3}}
\hskip0pt\relax
cell2\sphinxhyphen{}1
\par
\vskip-\baselineskip\vbox{\hbox{\strut}}\end{varwidth}%
}%
&\sphinxtablestrut{5}&
&\sphinxtablestrut{5}&\hskip0pt\relax
cell2\sphinxhyphen{}3
\\
\cline{2-3}\sphinxtablestrut{7}&\sphinxstartmulticolumn{2}%
\sphinxmultirow{2}{9}{%
\begin{varwidth}[t]{\sphinxcolwidth{2}{3}}
\hskip0pt\relax
cell3\sphinxhyphen{}2
\par
\vskip-\baselineskip\vbox{\hbox{\strut}}\end{varwidth}%
}%
\sphinxstopmulticolumn
\\
\cline{1-1}
\cline{1-1}\hskip0pt\relax
cell4\sphinxhyphen{}1
&\multicolumn{2}{l|}{\sphinxtablestrut{9}}\\
\hline\sphinxstartmulticolumn{3}%
\begin{varwidth}[t]{\sphinxcolwidth{3}{3}}
\hskip0pt\relax
cell5\sphinxhyphen{}1
\par
\vskip-\baselineskip\vbox{\hbox{\strut}}\end{varwidth}%
Expand Down
20 changes: 10 additions & 10 deletions tests/roots/test-latex-table/expects/longtable.tex
Expand Up @@ -2,9 +2,9 @@

\begin{savenotes}\sphinxatlongtablestart\begin{longtable}[c]{|l|l|}
\hline
\sphinxstyletheadfamily
\sphinxstyletheadfamily \hskip0pt\relax
header1
&\sphinxstyletheadfamily
&\sphinxstyletheadfamily \hskip0pt\relax
header2
\\
\hline
Expand All @@ -13,9 +13,9 @@
\multicolumn{2}{c}%
{\makebox[0pt]{\sphinxtablecontinued{\tablename\ \thetable{} \textendash{} continued from previous page}}}\\
\hline
\sphinxstyletheadfamily
\sphinxstyletheadfamily \hskip0pt\relax
header1
&\sphinxstyletheadfamily
&\sphinxstyletheadfamily \hskip0pt\relax
header2
\\
\hline
Expand All @@ -26,19 +26,19 @@
\endfoot

\endlastfoot

\hskip0pt\relax
cell1\sphinxhyphen{}1
&
&\hskip0pt\relax
cell1\sphinxhyphen{}2
\\
\hline
\hline\hskip0pt\relax
cell2\sphinxhyphen{}1
&
&\hskip0pt\relax
cell2\sphinxhyphen{}2
\\
\hline
\hline\hskip0pt\relax
cell3\sphinxhyphen{}1
&
&\hskip0pt\relax
cell3\sphinxhyphen{}2
\\
\hline
Expand Down
20 changes: 10 additions & 10 deletions tests/roots/test-latex-table/expects/longtable_having_align.tex
Expand Up @@ -2,9 +2,9 @@

\begin{savenotes}\sphinxatlongtablestart\begin{longtable}[r]{|l|l|}
\hline
\sphinxstyletheadfamily
\sphinxstyletheadfamily \hskip0pt\relax
header1
&\sphinxstyletheadfamily
&\sphinxstyletheadfamily \hskip0pt\relax
header2
\\
\hline
Expand All @@ -13,9 +13,9 @@
\multicolumn{2}{c}%
{\makebox[0pt]{\sphinxtablecontinued{\tablename\ \thetable{} \textendash{} continued from previous page}}}\\
\hline
\sphinxstyletheadfamily
\sphinxstyletheadfamily \hskip0pt\relax
header1
&\sphinxstyletheadfamily
&\sphinxstyletheadfamily \hskip0pt\relax
header2
\\
\hline
Expand All @@ -26,19 +26,19 @@
\endfoot

\endlastfoot

\hskip0pt\relax
cell1\sphinxhyphen{}1
&
&\hskip0pt\relax
cell1\sphinxhyphen{}2
\\
\hline
\hline\hskip0pt\relax
cell2\sphinxhyphen{}1
&
&\hskip0pt\relax
cell2\sphinxhyphen{}2
\\
\hline
\hline\hskip0pt\relax
cell3\sphinxhyphen{}1
&
&\hskip0pt\relax
cell3\sphinxhyphen{}2
\\
\hline
Expand Down
20 changes: 10 additions & 10 deletions tests/roots/test-latex-table/expects/longtable_having_caption.tex
Expand Up @@ -4,9 +4,9 @@
\sphinxthelongtablecaptionisattop
\caption{caption for longtable\strut}\label{\detokenize{longtable:id1}}\\*[\sphinxlongtablecapskipadjust]
\hline
\sphinxstyletheadfamily
\sphinxstyletheadfamily \hskip0pt\relax
header1
&\sphinxstyletheadfamily
&\sphinxstyletheadfamily \hskip0pt\relax
header2
\\
\hline
Expand All @@ -15,9 +15,9 @@
\multicolumn{2}{c}%
{\makebox[0pt]{\sphinxtablecontinued{\tablename\ \thetable{} \textendash{} continued from previous page}}}\\
\hline
\sphinxstyletheadfamily
\sphinxstyletheadfamily \hskip0pt\relax
header1
&\sphinxstyletheadfamily
&\sphinxstyletheadfamily \hskip0pt\relax
header2
\\
\hline
Expand All @@ -28,19 +28,19 @@
\endfoot

\endlastfoot

\hskip0pt\relax
cell1\sphinxhyphen{}1
&
&\hskip0pt\relax
cell1\sphinxhyphen{}2
\\
\hline
\hline\hskip0pt\relax
cell2\sphinxhyphen{}1
&
&\hskip0pt\relax
cell2\sphinxhyphen{}2
\\
\hline
\hline\hskip0pt\relax
cell3\sphinxhyphen{}1
&
&\hskip0pt\relax
cell3\sphinxhyphen{}2
\\
\hline
Expand Down
Expand Up @@ -2,9 +2,9 @@

\begin{savenotes}\sphinxatlongtablestart\begin{longtable}[c]{|*{2}{\X{1}{2}|}}
\hline
\sphinxstyletheadfamily
\sphinxstyletheadfamily \hskip0pt\relax
header1
&\sphinxstyletheadfamily
&\sphinxstyletheadfamily \hskip0pt\relax
header2
\\
\hline
Expand All @@ -13,9 +13,9 @@
\multicolumn{2}{c}%
{\makebox[0pt]{\sphinxtablecontinued{\tablename\ \thetable{} \textendash{} continued from previous page}}}\\
\hline
\sphinxstyletheadfamily
\sphinxstyletheadfamily \hskip0pt\relax
header1
&\sphinxstyletheadfamily
&\sphinxstyletheadfamily \hskip0pt\relax
header2
\\
\hline
Expand All @@ -27,24 +27,24 @@

\endlastfoot
\begin{itemize}
\item {}
\item {} \hskip0pt\relax
item1

\item {}
\item {} \hskip0pt\relax
item2

\end{itemize}
&
&\hskip0pt\relax
cell1\sphinxhyphen{}2
\\
\hline
\hline\hskip0pt\relax
cell2\sphinxhyphen{}1
&
&\hskip0pt\relax
cell2\sphinxhyphen{}2
\\
\hline
\hline\hskip0pt\relax
cell3\sphinxhyphen{}1
&
&\hskip0pt\relax
cell3\sphinxhyphen{}2
\\
\hline
Expand Down

0 comments on commit 185a2d2

Please sign in to comment.