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

View File

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

View File

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