Skip to content

Commit b794539

Browse files
committed
LaTeX support for sphinx-doc#13326
1 parent 12b4700 commit b794539

File tree

2 files changed

+35
-22
lines changed

2 files changed

+35
-22
lines changed

sphinx/texinputs/sphinxlatexobjects.sty

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
%% MODULE RELEASE DATA AND OBJECT DESCRIPTIONS
22
%
33
% change this info string if making any custom modification
4-
\ProvidesPackage{sphinxlatexobjects}[2023/07/23 documentation environments]
4+
\ProvidesPackage{sphinxlatexobjects}[2025/02/11 documentation environments]
55

66
% Provides support for this output mark-up from Sphinx latex writer:
77
%
@@ -279,18 +279,39 @@
279279
\newcommand{\pysigstopmultiline}{\sphinxsigismultilinefalse\itemsep\sphinxsignaturesep}%
280280

281281
% Production lists
282+
% This simply outputs the lines as is, in monospace font. Refers #13326.
283+
% (the left padding for multi-line alignment is from the nodes themselves,
284+
% and latex is configured below to obey such horizontal whitespace).
285+
%
286+
% - The legacy code used longtable and hardcoded the separator as ::=
287+
% via dedicated macros defined by the environment itself.
288+
% - Here the separator is part of the node. Any extra LaTeX mark-up would
289+
% have to originate from the writer itself to decorate it.
290+
% - The legacy code used strangely \parindent and \indent. Possibly
291+
% (unchecked) due to an earlier tabular usage, but a longtable does not
292+
% work in paragraph mode, so \parindent was without effect and
293+
% \indent only caused some extra blank line above display.
294+
% - The table had some whitespace on its left, which we imitate here via
295+
% \parindent usage (which works in our context...).
282296
%
283297
\newenvironment{productionlist}{%
284-
% \def\sphinxoptional##1{{\Large[}##1{\Large]}}
285-
\def\production##1##2{\\\sphinxcode{\sphinxupquote{##1}}&::=&\sphinxcode{\sphinxupquote{##2}}}%
286-
\def\productioncont##1{\\& &\sphinxcode{\sphinxupquote{##1}}}%
287-
\parindent=2em
288-
\indent
289-
\setlength{\LTpre}{0pt}%
290-
\setlength{\LTpost}{0pt}%
291-
\begin{longtable}[l]{lcl}
298+
\bigskip % imitate close enough legacy vertical whitespace, which was
299+
% visibly excessive
300+
\ttfamily % needed for space tokens to have same width as letters
301+
\parindent1em % width of a "quad", font-dependent, usually circa width of 2
302+
% letters
303+
\obeylines % line in = line out
304+
\parskip\z@skip % prevent the parskip vertical whitespace between lines,
305+
% which are technically to LaTeX now each its own paragraph
306+
\@vobeyspaces % line in = line out, obey whitespace
307+
%\indent % avoid suppression of indent of first line, if it happens to
308+
% be located immediately after a sectioning division
309+
% now a technicality to, only locally to this environment, prevent the
310+
% suppression of indentation of first line, if it comes right after
311+
% \section. Cf package indentfirst from which the code is borrowed.
312+
\let\@afterindentfalse\@afterindenttrue\@afterindenttrue
292313
}{%
293-
\end{longtable}
314+
\par % does not hurt...
294315
}
295316

296317
% Definition lists; requested by AMK for HOWTO documents. Probably useful

sphinx/writers/latex.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -678,20 +678,12 @@ def depart_productionlist(self, node: Element) -> None:
678678
self.in_production_list = False
679679

680680
def visit_production(self, node: Element) -> None:
681-
if node['tokenname']:
682-
tn = node['tokenname']
683-
self.body.append(self.hypertarget(f'grammar-token-{tn}'))
684-
self.body.append(r'\production{%s}{' % self.encode(tn))
685-
else:
686-
self.body.append(r'\productioncont{')
687-
688-
# remove name/padding and seperator child nodes,
689-
# these are handled by '\production' and '\productioncont'
690-
# TODO: remove special LaTeX handling of production nodes
691-
node[:] = node[2:]
681+
# Nothing to do, the productionlist LaTeX environment
682+
# is configured to render line per line the nodes
683+
pass
692684

693685
def depart_production(self, node: Element) -> None:
694-
self.body.append('}' + CR)
686+
pass
695687

696688
def visit_transition(self, node: Element) -> None:
697689
self.body.append(self.elements['transition'])

0 commit comments

Comments
 (0)