Skip to content

Commit

Permalink
Modify longtable templates to put LaTeX macros each on its line
Browse files Browse the repository at this point in the history
Table body insertion without removing previous EOL may give output which
contain some empty lines but longtable defines \par token to be same as
\empty.
  • Loading branch information
jfbu committed Aug 10, 2022
1 parent 5c9a348 commit fdf6081
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 25 deletions.
10 changes: 7 additions & 3 deletions sphinx/templates/latex/longtable.tex_t
@@ -1,4 +1,5 @@
\begin{savenotes}\sphinxatlongtablestart
\begin{savenotes}
\sphinxatlongtablestart
\sphinxthistablewithglobalstyle
<% if 'booktabs' in table.styles -%>
\sphinxthistablewithbooktabsstyle
Expand Down Expand Up @@ -52,6 +53,9 @@

\endlastfoot
\sphinxtableatstartofbodyhook
<%=- ''.join(table.body) -%>
<%= ''.join(table.body) -%>
\sphinxbottomrule
\end{longtable}\sphinxtableafterendhook\sphinxatlongtableend\end{savenotes}
\end{longtable}
\sphinxtableafterendhook
\sphinxatlongtableend
\end{savenotes}
9 changes: 7 additions & 2 deletions tests/roots/test-latex-table/expects/longtable.tex
@@ -1,6 +1,7 @@
\label{\detokenize{longtable:longtable}}

\begin{savenotes}\sphinxatlongtablestart
\begin{savenotes}
\sphinxatlongtablestart
\sphinxthistablewithglobalstyle
\begin{longtable}[c]{|l|l|}
\sphinxtoprule
Expand Down Expand Up @@ -33,6 +34,7 @@

\endlastfoot
\sphinxtableatstartofbodyhook

\sphinxAtStartPar
cell1\sphinxhyphen{}1
&
Expand All @@ -54,4 +56,7 @@
cell3\sphinxhyphen{}2
\\
\sphinxbottomrule
\end{longtable}\sphinxtableafterendhook\sphinxatlongtableend\end{savenotes}
\end{longtable}
\sphinxtableafterendhook
\sphinxatlongtableend
\end{savenotes}
@@ -1,6 +1,7 @@
\label{\detokenize{longtable:longtable-having-align-option}}

\begin{savenotes}\sphinxatlongtablestart
\begin{savenotes}
\sphinxatlongtablestart
\sphinxthistablewithglobalstyle
\begin{longtable}[r]{|l|l|}
\sphinxtoprule
Expand Down Expand Up @@ -33,6 +34,7 @@

\endlastfoot
\sphinxtableatstartofbodyhook

\sphinxAtStartPar
cell1\sphinxhyphen{}1
&
Expand All @@ -54,4 +56,7 @@
cell3\sphinxhyphen{}2
\\
\sphinxbottomrule
\end{longtable}\sphinxtableafterendhook\sphinxatlongtableend\end{savenotes}
\end{longtable}
\sphinxtableafterendhook
\sphinxatlongtableend
\end{savenotes}
@@ -1,6 +1,7 @@
\label{\detokenize{longtable:longtable-having-caption}}

\begin{savenotes}\sphinxatlongtablestart
\begin{savenotes}
\sphinxatlongtablestart
\sphinxthistablewithglobalstyle
\begin{longtable}[c]{|l|l|}
\sphinxthelongtablecaptionisattop
Expand Down Expand Up @@ -35,6 +36,7 @@

\endlastfoot
\sphinxtableatstartofbodyhook

\sphinxAtStartPar
cell1\sphinxhyphen{}1
&
Expand All @@ -56,4 +58,7 @@
cell3\sphinxhyphen{}2
\\
\sphinxbottomrule
\end{longtable}\sphinxtableafterendhook\sphinxatlongtableend\end{savenotes}
\end{longtable}
\sphinxtableafterendhook
\sphinxatlongtableend
\end{savenotes}
@@ -1,6 +1,7 @@
\label{\detokenize{longtable:longtable-having-problematic-cell}}

\begin{savenotes}\sphinxatlongtablestart
\begin{savenotes}
\sphinxatlongtablestart
\sphinxthistablewithglobalstyle
\begin{longtable}[c]{|*{2}{\X{1}{2}|}}
\sphinxtoprule
Expand Down Expand Up @@ -32,7 +33,8 @@
\endfoot

\endlastfoot
\sphinxtableatstartofbodyhook\begin{itemize}
\sphinxtableatstartofbodyhook
\begin{itemize}
\item {}
\sphinxAtStartPar
item1
Expand Down Expand Up @@ -61,4 +63,7 @@
cell3\sphinxhyphen{}2
\\
\sphinxbottomrule
\end{longtable}\sphinxtableafterendhook\sphinxatlongtableend\end{savenotes}
\end{longtable}
\sphinxtableafterendhook
\sphinxatlongtableend
\end{savenotes}
@@ -1,6 +1,7 @@
\label{\detokenize{longtable:longtable-having-both-stub-columns-and-problematic-cell}}

\begin{savenotes}\sphinxatlongtablestart
\begin{savenotes}
\sphinxatlongtablestart
\sphinxthistablewithglobalstyle
\begin{longtable}[c]{|*{3}{\X{1}{3}|}}
\sphinxtoprule
Expand Down Expand Up @@ -38,7 +39,8 @@
\endfoot

\endlastfoot
\sphinxtableatstartofbodyhook\sphinxstyletheadfamily \begin{itemize}
\sphinxtableatstartofbodyhook
\sphinxstyletheadfamily \begin{itemize}
\item {}
\sphinxAtStartPar
instub1\sphinxhyphen{}1a
Expand Down Expand Up @@ -66,4 +68,7 @@
cell2\sphinxhyphen{}3
\\
\sphinxbottomrule
\end{longtable}\sphinxtableafterendhook\sphinxatlongtableend\end{savenotes}
\end{longtable}
\sphinxtableafterendhook
\sphinxatlongtableend
\end{savenotes}
@@ -1,6 +1,7 @@
\label{\detokenize{longtable:longtable-having-verbatim}}

\begin{savenotes}\sphinxatlongtablestart
\begin{savenotes}
\sphinxatlongtablestart
\sphinxthistablewithglobalstyle
\begin{longtable}[c]{|*{2}{\X{1}{2}|}}
\sphinxtoprule
Expand Down Expand Up @@ -33,6 +34,7 @@

\endlastfoot
\sphinxtableatstartofbodyhook

\begin{sphinxVerbatimintable}[commandchars=\\\{\}]
\PYG{n}{hello} \PYG{n}{world}
\end{sphinxVerbatimintable}
Expand All @@ -55,4 +57,7 @@
cell3\sphinxhyphen{}2
\\
\sphinxbottomrule
\end{longtable}\sphinxtableafterendhook\sphinxatlongtableend\end{savenotes}
\end{longtable}
\sphinxtableafterendhook
\sphinxatlongtableend
\end{savenotes}
@@ -1,6 +1,7 @@
\label{\detokenize{longtable:longtable-having-widths-option}}

\begin{savenotes}\sphinxatlongtablestart
\begin{savenotes}
\sphinxatlongtablestart
\sphinxthistablewithglobalstyle
\begin{longtable}[c]{|\X{30}{100}|\X{70}{100}|}
\noalign{\phantomsection\label{\detokenize{longtable:namedlongtable}}\label{\detokenize{longtable:mylongtable}}}%
Expand Down Expand Up @@ -34,6 +35,7 @@

\endlastfoot
\sphinxtableatstartofbodyhook

\sphinxAtStartPar
cell1\sphinxhyphen{}1
&
Expand All @@ -55,7 +57,10 @@
cell3\sphinxhyphen{}2
\\
\sphinxbottomrule
\end{longtable}\sphinxtableafterendhook\sphinxatlongtableend\end{savenotes}
\end{longtable}
\sphinxtableafterendhook
\sphinxatlongtableend
\end{savenotes}

\sphinxAtStartPar
See {\hyperref[\detokenize{longtable:mylongtable}]{\sphinxcrossref{mylongtable}}}, same as {\hyperref[\detokenize{longtable:namedlongtable}]{\sphinxcrossref{\DUrole{std,std-ref}{this one}}}}.
@@ -1,6 +1,7 @@
\label{\detokenize{longtable:longtable-having-both-widths-and-problematic-cell}}

\begin{savenotes}\sphinxatlongtablestart
\begin{savenotes}
\sphinxatlongtablestart
\sphinxthistablewithglobalstyle
\begin{longtable}[c]{|\X{30}{100}|\X{70}{100}|}
\sphinxtoprule
Expand Down Expand Up @@ -32,7 +33,8 @@
\endfoot

\endlastfoot
\sphinxtableatstartofbodyhook\begin{itemize}
\sphinxtableatstartofbodyhook
\begin{itemize}
\item {}
\sphinxAtStartPar
item1
Expand Down Expand Up @@ -61,4 +63,7 @@
cell3\sphinxhyphen{}2
\\
\sphinxbottomrule
\end{longtable}\sphinxtableafterendhook\sphinxatlongtableend\end{savenotes}
\end{longtable}
\sphinxtableafterendhook
\sphinxatlongtableend
\end{savenotes}
@@ -1,6 +1,7 @@
\label{\detokenize{longtable:longtable-with-tabularcolumn}}

\begin{savenotes}\sphinxatlongtablestart
\begin{savenotes}
\sphinxatlongtablestart
\sphinxthistablewithglobalstyle
\begin{longtable}[c]{|c|c|}
\sphinxtoprule
Expand Down Expand Up @@ -33,6 +34,7 @@

\endlastfoot
\sphinxtableatstartofbodyhook

\sphinxAtStartPar
cell1\sphinxhyphen{}1
&
Expand All @@ -54,4 +56,7 @@
cell3\sphinxhyphen{}2
\\
\sphinxbottomrule
\end{longtable}\sphinxtableafterendhook\sphinxatlongtableend\end{savenotes}
\end{longtable}
\sphinxtableafterendhook
\sphinxatlongtableend
\end{savenotes}
2 changes: 1 addition & 1 deletion tests/test_build_latex.py
Expand Up @@ -765,7 +765,7 @@ def test_reference_in_caption_and_codeblock_in_footnote(app, status, warning):
'caption of normal table}\\label{\\detokenize{index:id36}}') in result
assert ('\\caption{footnote \\sphinxfootnotemark[10] '
'in caption \\sphinxfootnotemark[11] of longtable\\strut}') in result
assert ('\\endlastfoot\n\\sphinxtableatstartofbodyhook%\n'
assert ('\\endlastfoot\n\\sphinxtableatstartofbodyhook\n%\n'
'\\begin{footnotetext}[10]\\sphinxAtStartFootnote\n'
'Foot note in longtable\n%\n\\end{footnotetext}\\ignorespaces %\n'
'\\begin{footnotetext}[11]\\sphinxAtStartFootnote\n'
Expand Down

0 comments on commit fdf6081

Please sign in to comment.