Skip to content

Commit

Permalink
Fix suppression of needed whiteline, encapsulate into \sphinxAtStartPar
Browse files Browse the repository at this point in the history
Define it to do nothing with lualatex engine
  • Loading branch information
jfbu committed Jan 29, 2021
1 parent 185a2d2 commit d6e11b8
Show file tree
Hide file tree
Showing 28 changed files with 468 additions and 247 deletions.
8 changes: 8 additions & 0 deletions doc/latex.rst
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

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

Expand Down
5 changes: 5 additions & 0 deletions sphinx/texinputs/sphinx.sty
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{\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: 2 additions & 2 deletions sphinx/writers/latex.py
Expand Up @@ -1161,9 +1161,9 @@ def visit_paragraph(self, node: Element) -> None:
# (first one is label node)
pass
else:
# the \hskip0pt\relax is to allow hyphenation of first word of
# the \sphinxAtStartPar 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')
self.body.append('\n\\sphinxAtStartPar\n')

def depart_paragraph(self, node: Element) -> None:
self.body.append('\n')
Expand Down
12 changes: 8 additions & 4 deletions tests/roots/test-latex-equations/expects/latex-equations.tex
@@ -1,14 +1,18 @@
\hskip0pt\relax

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

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

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

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

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

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

\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}}
\hskip0pt\relax

\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}&\hskip0pt\relax
\cline{5-5}\sphinxtablestrut{1}&\sphinxtablestrut{2}&\sphinxtablestrut{6}&\sphinxtablestrut{4}&
\sphinxAtStartPar
cell3\sphinxhyphen{}5
\\
\hline
Expand Down
33 changes: 22 additions & 11 deletions tests/roots/test-latex-table/expects/gridtable.tex
Expand Up @@ -4,51 +4,62 @@
\centering
\begin{tabulary}{\linewidth}[t]{|T|T|T|}
\hline
\sphinxstyletheadfamily \hskip0pt\relax
\sphinxstyletheadfamily
\sphinxAtStartPar
header1
&\sphinxstyletheadfamily \hskip0pt\relax
&\sphinxstyletheadfamily
\sphinxAtStartPar
header2
&\sphinxstyletheadfamily \hskip0pt\relax
&\sphinxstyletheadfamily
\sphinxAtStartPar
header3
\\
\hline\hskip0pt\relax
\hline
\sphinxAtStartPar
cell1\sphinxhyphen{}1
&\sphinxmultirow{2}{5}{%
\begin{varwidth}[t]{\sphinxcolwidth{1}{3}}
\hskip0pt\relax

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

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

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

\sphinxAtStartPar
cell5\sphinxhyphen{}1
\par
\vskip-\baselineskip\vbox{\hbox{\strut}}\end{varwidth}%
Expand Down
30 changes: 20 additions & 10 deletions tests/roots/test-latex-table/expects/longtable.tex
Expand Up @@ -2,9 +2,11 @@

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

\endlastfoot
\hskip0pt\relax

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

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

\endlastfoot
\hskip0pt\relax

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

\endlastfoot
\hskip0pt\relax

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

0 comments on commit d6e11b8

Please sign in to comment.