From: <fel...@us...> - 2005-07-17 21:29:59
|
Author: felixwiemann Date: 2005-07-17 23:29:51 +0200 (Sun, 17 Jul 2005) New Revision: 3762 Modified: trunk/docutils/docutils/writers/newlatex2e.py trunk/docutils/tools/stylesheets/latex.tex Log: removed a lot of paragraph-handling code; some was unnecessary, some will be replaced by custom paragraph-indentation logic in the Python module; always add space around transitions Modified: trunk/docutils/docutils/writers/newlatex2e.py =================================================================== --- trunk/docutils/docutils/writers/newlatex2e.py 2005-07-17 19:59:35 UTC (rev 3761) +++ trunk/docutils/docutils/writers/newlatex2e.py 2005-07-17 21:29:51 UTC (rev 3762) @@ -701,28 +701,38 @@ def is_invisible(self, node): # Return true if node is invisible or moved away in the LaTeX # rendering. - return (isinstance(node, nodes.Invisible) or - isinstance(node, nodes.footnote) or - isinstance(node, nodes.citation) or - # We never know what's inside raw nodes, and often - # they *are* invisible. So let's have the user take - # care of them. - isinstance(node, nodes.raw) or - # Horizontally aligned image or figure. - node.get('align', None) in ('left', 'center', 'right')) + return (not isinstance(node, nodes.Text) and + (isinstance(node, nodes.Invisible) or + isinstance(node, nodes.footnote) or + isinstance(node, nodes.citation) or + # We never know what's inside raw nodes, and often + # they *are* invisible. So let's have the user take + # care of them. + isinstance(node, nodes.raw) or + # Horizontally aligned image or figure. + node.get('align', None) in ('left', 'center', 'right'))) def is_visible(self, node): return not self.is_invisible(node) def needs_space(self, node): + """ + Two nodes for which `needs_space` is true need auxiliary space. + """ # Return true if node is a visible block-level element. return ((isinstance(node, nodes.Body) or - isinstance(node, nodes.topic) or - #isinstance(node, nodes.rubric) or - isinstance(node, nodes.transition)) and + isinstance(node, nodes.topic)) and not (self.is_invisible(node) or isinstance(node.parent, nodes.TextElement))) + def always_needs_space(self, node): + """ + Always add space around nodes for which `always_needs_space` + is true, regardless of whether the other node needs space as + well. (E.g. transition next to section.) + """ + return isinstance(node, nodes.transition) + def dispatch_departure(self, node): # Call departure method. nodes.SparseNodeVisitor.dispatch_departure(self, node) @@ -733,21 +743,21 @@ self.append(self.context.pop() + self.context.pop()) # Delete \Dcurrent... attribute macros. self.append(self.context.pop()) - # Insert space. - if self.needs_space(node): - # Next sibling. - next_node = node.next_node( - ascend=0, siblings=1, descend=0, - condition=self.is_visible) - if self.needs_space(next_node): - # Insert space. - if isinstance(next_node, nodes.paragraph): - if isinstance(node, nodes.paragraph): - # Space between paragraphs. - self.append(r'\Dparagraphspace') - else: - # Space in front of a paragraph. - self.append(r'\Dauxiliaryparspace') + # Get next sibling. + next_node = node.next_node( + ascend=0, siblings=1, descend=0, + condition=self.is_visible) + # Insert space if necessary. + if (self.always_needs_space(node) or + self.always_needs_space(next_node) or + self.needs_space(node) and self.needs_space(next_node)): + if isinstance(next_node, nodes.paragraph): + if isinstance(node, nodes.paragraph): + # Space between paragraphs. + self.append(r'\Dparagraphspace') else: - # Space in front of something else than a paragraph. - self.append(r'\Dauxiliaryspace') + # Space in front of a paragraph. + self.append(r'\Dauxiliaryparspace') + else: + # Space in front of something else than a paragraph. + self.append(r'\Dauxiliaryspace') Modified: trunk/docutils/tools/stylesheets/latex.tex =================================================================== --- trunk/docutils/tools/stylesheets/latex.tex 2005-07-17 19:59:35 UTC (rev 3761) +++ trunk/docutils/tools/stylesheets/latex.tex 2005-07-17 21:29:51 UTC (rev 3762) @@ -87,33 +87,17 @@ } \providecommand{\Dauxiliaryspace}{% \ifthenelse{\equal{\Dneedvspace}{true}}{\vspace{\Dblocklevelvspace}}{}% - \Dpar\noindent% + \par\noindent% } \providecommand{\Dauxiliaryparspace}{% \ifthenelse{\equal{\Dneedvspace}{true}}{\vspace{\Dblocklevelvspace}}{}% - \Dpar% + \par% } - \providecommand{\Dparagraphspace}{\Dpar} + \providecommand{\Dparagraphspace}{\par} \providecommand{\Dneedvspace}{true} } -\providecommand{\DSparagraphs}{ - \providecommand{\Dnextparindent}{} - \providecommand{\Dnextpar}{\par} - %\newcommand{\Dnextpar}{\par\Dnextparindent} - \providecommand{\Dpar}{% - \Dnextpar% - \Dnextparindent% - \protect\renewcommand{\Dnextpar}{\par}% - \protect\renewcommand{\Dnextparindent}{}% - } - \providecommand{\Dnopar}{% - \protect\renewcommand{\Dnextpar}{\par}% - \protect\renewcommand{\Dnextparindent}{}% - } -} - \providecommand{\DSlinks}{ % Targets and references. \usepackage[colorlinks=false,pdfborder={0 0 0}]{hyperref} @@ -265,12 +249,12 @@ \providecommand{\Dtopictitle}[1]{% \noindent\Dformatboxtitle{#1}% \ifthenelse{\equal{\Dhassubtitle}{false}}{\vspace{1em}}{\vspace{0.5em}}% - \Dpar\noindent% + \par% } \providecommand{\Dtopicsubtitle}[1]{% - \Dformatboxsubtitle{#1}% + \noindent\Dformatboxsubtitle{#1}% \vspace{1em}% - \Dpar\noindent% + \par% } \providecommand{\Dsidebartitle}[1]{\Dtopictitle{#1}} \providecommand{\Dsidebarsubtitle}[1]{\Dtopicsubtitle{#1}} @@ -376,7 +360,6 @@ \par\noindent% #1% \addtocounter{Dtoclevel}{-1}% - \renewcommand{\Dnextparindent}{\noindent}% }{% \par\noindent% \Dmakebox{#1}% @@ -385,7 +368,7 @@ \providecommand{\Dformatrubric}[1]{\textbf{#1}} \Dprovidelength{\Dprerubricspace}{0.3em} \providecommand{\DNrubric}[1]{% - \vspace{\Dprerubricspace}\Dpar\noindent\Dformatrubric{#1}\Dpar\noindent% + \vspace{\Dprerubricspace}\par\noindent\Dformatrubric{#1}\par% } \providecommand{\Dbullet}{} @@ -683,7 +666,7 @@ \providecommand{\Dformatclassifier}[1]{\textsl{#1}} \providecommand{\DNclassifier}[1]{~:~\Dformatclassifier{#1}} \providecommand{\Dformatdefinition}[1]{#1} -\providecommand{\DNdefinition}[1]{\Dpar\Dformatdefinition{#1}} +\providecommand{\DNdefinition}[1]{\par\Dformatdefinition{#1}} \providecommand{\Dlineblockindentation}{2.5em} \providecommand{\DNlineblock}[1]{% @@ -705,7 +688,7 @@ \providecommand{\DNtransition}{% - \Dpar\noindent{}\hspace*{\fill}\hrulefill\hrulefill\hspace*{\fill}% + \hspace*{\fill}\hrulefill\hrulefill\hspace*{\fill}% } @@ -716,14 +699,12 @@ } \providecommand{\Dformatattribution}[1]{---\textup{#1}} \providecommand{\DNblockquote}[1]{% - \renewcommand{\Dnextparindent}{\noindent}% - \renewcommand{\Dnextpar}{}% \Dmakebox{% \Dformatblockquote{#1} }% } \providecommand{\DNattribution}[1]{% - \Dpar% + \par% \begin{flushright}\Dformatattribution{#1}\end{flushright}% } @@ -743,11 +724,10 @@ \Dprovidelength{\Dsidebarwidth}{0.45\linewidth} \providecommand{\DNsidebar}[1]{ \parpic[\Dsidebarposition]{% - \Dpar% - \begin{minipage}[t]{\Dsidebarwidth} + \begin{minipage}[t]{\Dsidebarwidth}% % Doing this with nested minipages is ugly, but I haven't found % another way to place vertical space before and after the fbox. - \vspace{\Dsidebarvmargin} + \vspace{\Dsidebarvmargin}% {% \setlength{\fboxrule}{\Dsidebarframewidth}% \setlength{\fboxsep}{\Dsidebarpadding}% @@ -758,7 +738,7 @@ \end{minipage}% }% }% - \vspace{\Dsidebarvmargin} + \vspace{\Dsidebarvmargin}% \end{minipage}% }% } @@ -783,8 +763,8 @@ }% } \providecommand{\DNcitationreference}[1]{{[}#1{]}} -\Dprovidelength{\Dfootnotesep}{5pt} -\providecommand{\Dfootnotespacing}{% +\Dprovidelength{\Dfootnotesep}{3.5pt} +\providecommand{\Dsetfootnotespacing}{% % Spacing commands executed at the beginning of footnotes. \setlength{\parindent}{0pt}% \hspace{1em}% @@ -793,7 +773,8 @@ % See ltfloat.dtx for details. {% \insert\footins{% - \Dnopar\vspace{\Dfootnotesep}\Dfootnotespacing% + \vspace{\Dfootnotesep}% + \Dsetfootnotespacing% \Dformatfootnote{#1}% }% }% @@ -826,8 +807,6 @@ }% % If there are multiple backrefs, add them now. \Dformatmultiplebackrefs{\Dmultiplebackrefs}% - % Supress next paragraph change. - \renewcommand{\Dnextpar}{}% } \providecommand{\Dsinglefootnotebacklink}[2]{% % Create normal backlink of a footnote label. Parameters: @@ -1088,7 +1067,6 @@ \DSboxcommands \DSfrenchspacing \DSauxiliaryspace -\DSparagraphs \DSlinks \DSsymbols \DSlate |