More powerful parsed-literal for LaTeX output

This commit is contained in:
jfbu
2017-01-14 23:10:21 +01:00
parent 8c21abeccc
commit 06924cc21c
3 changed files with 29 additions and 16 deletions

View File

@@ -1,6 +1,6 @@
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{footnotehyper-sphinx}%
[2016/10/27 v0.9f hyperref aware footnote.sty for sphinx (JFB)]
[2017/01/14 v1.5.2 hyperref aware footnote.sty for sphinx (JFB)]
%%
%% Package: footnotehyper-sphinx
%% Version: based on footnotehyper.sty v0.9f (2016/10/03)
@@ -15,6 +15,7 @@
%% 4. \sphinxfootnotemark, and use of \spx@opt@BeforeFootnote from sphinx.sty.
%% Note: with \footnotemark[N]/\footnotetext[N] syntax, hyperref
%% does not insert an hyperlink. This is _not_ improved here.
%% 5. use of \sphinxunactivateextrasandspace for parsed literals
%%
\DeclareOption*{\PackageWarning{footnotehyper}{Option `\CurrentOption' is unknown}}%
\ProcessOptions\relax
@@ -92,7 +93,7 @@
%% \spx@opt@BeforeFootnote is defined in sphinx.sty
\def\FNH@fixed@footnote {\spx@opt@BeforeFootnote\ifx\@currenvir\fn@footnote
\expandafter\FNH@footnoteenv\else\expandafter\fn@latex@@footnote\fi }%
\def\FNH@footnoteenv {\@ifnextchar[\FNH@xfootnoteenv%]
\def\FNH@footnoteenv {\sphinxunactivateextrasandspace\@ifnextchar[\FNH@xfootnoteenv%]
{\stepcounter\@mpfn
\protected@xdef\@thefnmark{\thempfn}\@footnotemark
\def\FNH@endfntext@next{\FNH@endfntext@link}\fn@startfntext}}%

View File

@@ -559,10 +559,10 @@
% \sphinxbreaksbeforeactivelist\sphinxbreaksafteractivelist\do\-}%
}
\newcommand*\sphinxbreaksatspaceinparsedliteral{%
\lccode`~32 \lowercase{\def~}{\leavevmode
\lccode`~32 \lowercase{\def~}{\ifmmode\@xobeysp\else\leavevmode
\nobreak\hskip\z@ plus\fontdimen3\font minus\fontdimen4\font
\discretionary{\copy\sphinxvisiblespacebox}{\sphinxafterbreak}
{\kern\fontdimen2\font}%
{\kern\fontdimen2\font}\fi
}\lccode`\~`\~
}
% now the hack for \url to work (hyperref is required dependency):
@@ -573,20 +573,21 @@
}%
\long\def\spx@hack@hyper@normalise@aux#1\hyper@n@rmalise#2#3\spx@undefined{%
\ifx\spx@hack@hyper@normalise@aux#2%
\def\hyper@normalise
{#1\let\do\@makeother
\sphinxbreaksbeforeactivelist\sphinxbreaksafteractivelist\do\-%
\hyper@n@rmalise}%
\def\hyper@normalise{#1\sphinxunactivateextras\hyper@n@rmalise}%
\else
\PackageWarning{sphinx}{Could not patch \string\url\space command.%
^^J Not using active characters in alltt environment}%
\let\do\@makeother
\sphinxbreaksbeforeactivelist\sphinxbreaksafteractivelist\do\-%
^^J Not using extra active characters in alltt environment}%
\sphinxunactivateextras
\fi
}%
\newcommand*{\sphinxunactivateextras}{\let\do\@makeother
\sphinxbreaksbeforeactivelist\sphinxbreaksafteractivelist\do\-}%
\newcommand*{\sphinxunactivateextrasandspace}{\catcode13=5\catcode32=10\relax
\sphinxunactivateextras}%
% now for the modified alltt environment
\newenvironment{sphinxalltt}
{\begin{alltt}%
{% at start of next line to work around Emacs/AUCTeX issue with this file
\begin{alltt}%
\ifspx@opt@parsedliteralwraps
\sbox\sphinxcontinuationbox {\spx@opt@verbatimcontinued}%
\sbox\sphinxvisiblespacebox {\spx@opt@verbatimvisiblespace}%
@@ -594,8 +595,10 @@
\sphinxbreaksviaactiveinparsedliteral
\sphinxbreaksatspaceinparsedliteral
\spx@hack@hyper@normalise
\everymath\expandafter{\the\everymath\catcode`\^=7\catcode`\_=8 }%
\everydisplay\expandafter{\the\everydisplay\catcode`\^=7\catcode`\_=8 }%
\fi }
{\end{alltt}}% \end{alltt} (<-- only to fix Emacs/AUCTeX fontification issue)
{\end{alltt}}
% Topic boxes

View File

@@ -1030,14 +1030,20 @@ class LaTeXTranslator(nodes.NodeVisitor):
self.body.append('%%\n\\begin{footnotetext}[%s]'
'\\sphinxAtStartFootnote\n' % node['number'])
else:
self.body.append('%%\n\\begin{footnote}[%s]'
'\\sphinxAtStartFootnote\n' % node['number'])
if self.in_parsed_literal:
self.body.append('\\begin{footnote}[%s]' % node['number'])
else:
self.body.append('%%\n\\begin{footnote}[%s]' % node['number'])
self.body.append('\\sphinxAtStartFootnote\n')
def depart_collected_footnote(self, node):
if 'footnotetext' in node:
self.body.append('%\n\\end{footnotetext}')
else:
self.body.append('%\n\\end{footnote}')
if self.in_parsed_literal:
self.body.append('\\end{footnote}')
else:
self.body.append('%\n\\end{footnote}')
self.in_footnote -= 1
def visit_label(self, node):
@@ -1434,6 +1440,9 @@ class LaTeXTranslator(nodes.NodeVisitor):
attrs = node.attributes
pre = [] # in reverse order
post = []
if self.in_parsed_literal:
pre = ['\\begingroup\\sphinxunactivateextrasandspace\\relax ']
post = ['\\endgroup ']
include_graphics_options = []
is_inline = self.is_inline(node)
if 'width' in attrs: