You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

footnotehyper-sphinx.sty 8.9 kB

5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. \NeedsTeXFormat{LaTeX2e}
  2. \ProvidesPackage{footnotehyper-sphinx}%
  3. [2017/10/27 v1.7 hyperref aware footnote.sty for sphinx (JFB)]
  4. %%
  5. %% Package: footnotehyper-sphinx
  6. %% Version: based on footnotehyper.sty 2017/03/07 v1.0
  7. %% as available at https://www.ctan.org/pkg/footnotehyper
  8. %% License: the one applying to Sphinx
  9. %%
  10. %% Refer to the PDF documentation at https://www.ctan.org/pkg/footnotehyper for
  11. %% the code comments.
  12. %%
  13. %% Differences:
  14. %% 1. a partial tabulary compatibility layer added (enough for Sphinx mark-up),
  15. %% 2. use of \spx@opt@BeforeFootnote from sphinx.sty,
  16. %% 3. use of \sphinxunactivateextrasandspace from sphinx.sty,
  17. %% 4. macro definition \sphinxfootnotemark,
  18. %% 5. macro definition \sphinxlongtablepatch
  19. %% 6. replaced an \undefined by \@undefined
  20. \DeclareOption*{\PackageWarning{footnotehyper-sphinx}{Option `\CurrentOption' is unknown}}%
  21. \ProcessOptions\relax
  22. \newbox\FNH@notes
  23. \newdimen\FNH@width
  24. \let\FNH@colwidth\columnwidth
  25. \newif\ifFNH@savingnotes
  26. \AtBeginDocument {%
  27. \let\FNH@latex@footnote \footnote
  28. \let\FNH@latex@footnotetext\footnotetext
  29. \let\FNH@H@@footnotetext \@footnotetext
  30. \newenvironment{savenotes}
  31. {\FNH@savenotes\ignorespaces}{\FNH@spewnotes\ignorespacesafterend}%
  32. \let\spewnotes \FNH@spewnotes
  33. \let\footnote \FNH@footnote
  34. \let\footnotetext \FNH@footnotetext
  35. \let\endfootnote \FNH@endfntext
  36. \let\endfootnotetext\FNH@endfntext
  37. \@ifpackageloaded{hyperref}
  38. {\ifHy@hyperfootnotes
  39. \let\FNH@H@@footnotetext\H@@footnotetext
  40. \else
  41. \let\FNH@hyper@fntext\FNH@nohyp@fntext
  42. \fi}%
  43. {\let\FNH@hyper@fntext\FNH@nohyp@fntext}%
  44. }%
  45. \def\FNH@hyper@fntext{\FNH@fntext\FNH@hyper@fntext@i}%
  46. \def\FNH@nohyp@fntext{\FNH@fntext\FNH@nohyp@fntext@i}%
  47. \def\FNH@fntext #1{%
  48. \ifx\ifmeasuring@\@undefined
  49. \expandafter\@secondoftwo\else\expandafter\@firstofone\fi
  50. % these two lines modified for Sphinx (tabulary compatibility):
  51. {\ifmeasuring@\expandafter\@gobbletwo\else\expandafter\@firstofone\fi}%
  52. {\ifx\equation$\expandafter\@gobbletwo\fi #1}%$
  53. }%
  54. \long\def\FNH@hyper@fntext@i#1{%
  55. \global\setbox\FNH@notes\vbox
  56. {\unvbox\FNH@notes
  57. \FNH@startnote
  58. \@makefntext
  59. {\rule\z@\footnotesep\ignorespaces
  60. \ifHy@nesting\expandafter\ltx@firstoftwo
  61. \else\expandafter\ltx@secondoftwo
  62. \fi
  63. {\expandafter\hyper@@anchor\expandafter{\Hy@footnote@currentHref}{#1}}%
  64. {\Hy@raisedlink
  65. {\expandafter\hyper@@anchor\expandafter{\Hy@footnote@currentHref}%
  66. {\relax}}%
  67. \let\@currentHref\Hy@footnote@currentHref
  68. \let\@currentlabelname\@empty
  69. #1}%
  70. \@finalstrut\strutbox
  71. }%
  72. \FNH@endnote
  73. }%
  74. }%
  75. \long\def\FNH@nohyp@fntext@i#1{%
  76. \global\setbox\FNH@notes\vbox
  77. {\unvbox\FNH@notes
  78. \FNH@startnote
  79. \@makefntext{\rule\z@\footnotesep\ignorespaces#1\@finalstrut\strutbox}%
  80. \FNH@endnote
  81. }%
  82. }%
  83. \def\FNH@startnote{%
  84. \hsize\FNH@colwidth
  85. \interlinepenalty\interfootnotelinepenalty
  86. \reset@font\footnotesize
  87. \floatingpenalty\@MM
  88. \@parboxrestore
  89. \protected@edef\@currentlabel{\csname p@\@mpfn\endcsname\@thefnmark}%
  90. \color@begingroup
  91. }%
  92. \def\FNH@endnote{\color@endgroup}%
  93. \def\FNH@savenotes{%
  94. \begingroup
  95. \ifFNH@savingnotes\else
  96. \FNH@savingnotestrue
  97. \let\@footnotetext \FNH@hyper@fntext
  98. \let\@mpfootnotetext \FNH@hyper@fntext
  99. \let\H@@mpfootnotetext\FNH@nohyp@fntext
  100. \FNH@width\columnwidth
  101. \let\FNH@colwidth\FNH@width
  102. \global\setbox\FNH@notes\box\voidb@x
  103. \let\FNH@thempfn\thempfn
  104. \let\FNH@mpfn\@mpfn
  105. \ifx\@minipagerestore\relax\let\@minipagerestore\@empty\fi
  106. \expandafter\def\expandafter\@minipagerestore\expandafter{%
  107. \@minipagerestore
  108. \let\thempfn\FNH@thempfn
  109. \let\@mpfn\FNH@mpfn
  110. }%
  111. \fi
  112. }%
  113. \def\FNH@spewnotes {%
  114. \endgroup
  115. \ifFNH@savingnotes\else
  116. \ifvoid\FNH@notes\else
  117. \begingroup
  118. \let\@makefntext\@empty
  119. \let\@finalstrut\@gobble
  120. \let\rule\@gobbletwo
  121. \FNH@H@@footnotetext{\unvbox\FNH@notes}%
  122. \endgroup
  123. \fi
  124. \fi
  125. }%
  126. \def\FNH@footnote@envname {footnote}%
  127. \def\FNH@footnotetext@envname{footnotetext}%
  128. \def\FNH@footnote{%
  129. % this line added for Sphinx:
  130. \spx@opt@BeforeFootnote
  131. \ifx\@currenvir\FNH@footnote@envname
  132. \expandafter\FNH@footnoteenv
  133. \else
  134. \expandafter\FNH@latex@footnote
  135. \fi
  136. }%
  137. \def\FNH@footnoteenv{%
  138. % this line added for Sphinx (footnotes in parsed literal blocks):
  139. \catcode13=5 \sphinxunactivateextrasandspace
  140. \@ifnextchar[%
  141. \FNH@footnoteenv@i %]
  142. {\stepcounter\@mpfn
  143. \protected@xdef\@thefnmark{\thempfn}%
  144. \@footnotemark
  145. \def\FNH@endfntext@fntext{\@footnotetext}%
  146. \FNH@startfntext}%
  147. }%
  148. \def\FNH@footnoteenv@i[#1]{%
  149. \begingroup
  150. \csname c@\@mpfn\endcsname #1\relax
  151. \unrestored@protected@xdef\@thefnmark{\thempfn}%
  152. \endgroup
  153. \@footnotemark
  154. \def\FNH@endfntext@fntext{\@footnotetext}%
  155. \FNH@startfntext
  156. }%
  157. \def\FNH@footnotetext{%
  158. \ifx\@currenvir\FNH@footnotetext@envname
  159. \expandafter\FNH@footnotetextenv
  160. \else
  161. \expandafter\FNH@latex@footnotetext
  162. \fi
  163. }%
  164. \def\FNH@footnotetextenv{%
  165. \@ifnextchar[%
  166. \FNH@footnotetextenv@i %]
  167. {\protected@xdef\@thefnmark{\thempfn}%
  168. \def\FNH@endfntext@fntext{\@footnotetext}%
  169. \FNH@startfntext}%
  170. }%
  171. \def\FNH@footnotetextenv@i[#1]{%
  172. \begingroup
  173. \csname c@\@mpfn\endcsname #1\relax
  174. \unrestored@protected@xdef\@thefnmark{\thempfn}%
  175. \endgroup
  176. \ifFNH@savingnotes
  177. \def\FNH@endfntext@fntext{\FNH@nohyp@fntext}%
  178. \else
  179. \def\FNH@endfntext@fntext{\FNH@H@@footnotetext}%
  180. \fi
  181. \FNH@startfntext
  182. }%
  183. \def\FNH@startfntext{%
  184. \setbox\z@\vbox\bgroup
  185. \FNH@startnote
  186. \FNH@prefntext
  187. \rule\z@\footnotesep\ignorespaces
  188. }%
  189. \def\FNH@endfntext {%
  190. \@finalstrut\strutbox
  191. \FNH@postfntext
  192. \FNH@endnote
  193. \egroup
  194. \begingroup
  195. \let\@makefntext\@empty\let\@finalstrut\@gobble\let\rule\@gobbletwo
  196. \FNH@endfntext@fntext {\unvbox\z@}%
  197. \endgroup
  198. }%
  199. \AtBeginDocument{%
  200. \let\FNH@@makefntext\@makefntext
  201. \ifx\@makefntextFB\@undefined
  202. \expandafter\@gobble\else\expandafter\@firstofone\fi
  203. {\ifFBFrenchFootnotes \let\FNH@@makefntext\@makefntextFB \else
  204. \let\FNH@@makefntext\@makefntextORI\fi}%
  205. \expandafter\FNH@check@a\FNH@@makefntext{1.2!3?4,}%
  206. \FNH@@@1.2!3?4,\FNH@@@\relax
  207. }%
  208. \long\def\FNH@check@a #11.2!3?4,#2\FNH@@@#3{%
  209. \ifx\relax#3\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi
  210. \FNH@bad@makefntext@alert
  211. {\def\FNH@prefntext{#1}\def\FNH@postfntext{#2}\FNH@check@b}%
  212. }%
  213. \def\FNH@check@b #1\relax{%
  214. \expandafter\expandafter\expandafter\FNH@check@c
  215. \expandafter\meaning\expandafter\FNH@prefntext
  216. \meaning\FNH@postfntext1.2!3?4,\FNH@check@c\relax
  217. }%
  218. \def\FNH@check@c #11.2!3?4,#2#3\relax{%
  219. \ifx\FNH@check@c#2\expandafter\@gobble\fi\FNH@bad@makefntext@alert
  220. }%
  221. % slight reformulation for Sphinx
  222. \def\FNH@bad@makefntext@alert{%
  223. \PackageWarningNoLine{footnotehyper-sphinx}%
  224. {Footnotes will be sub-optimal, sorry. This is due to the document class or^^J
  225. some package modifying macro \string\@makefntext.^^J
  226. You can try to report this incompatibility at^^J
  227. https://github.com/sphinx-doc/sphinx with this info:}%
  228. \typeout{\meaning\@makefntext}%
  229. \let\FNH@prefntext\@empty\let\FNH@postfntext\@empty
  230. }%
  231. % this macro from original footnote.sty is not used anymore by Sphinx
  232. % but for simplicity sake let's just keep it as is
  233. \def\makesavenoteenv{\@ifnextchar[\FNH@msne@ii\FNH@msne@i}%]
  234. \def\FNH@msne@i #1{%
  235. \expandafter\let\csname FNH$#1\expandafter\endcsname %$
  236. \csname #1\endcsname
  237. \expandafter\let\csname endFNH$#1\expandafter\endcsname %$
  238. \csname end#1\endcsname
  239. \FNH@msne@ii[#1]{FNH$#1}%$
  240. }%
  241. \def\FNH@msne@ii[#1]#2{%
  242. \expandafter\edef\csname#1\endcsname{%
  243. \noexpand\savenotes
  244. \expandafter\noexpand\csname#2\endcsname
  245. }%
  246. \expandafter\edef\csname end#1\endcsname{%
  247. \expandafter\noexpand\csname end#2\endcsname
  248. \noexpand\expandafter
  249. \noexpand\spewnotes
  250. \noexpand\if@endpe\noexpand\@endpetrue\noexpand\fi
  251. }%
  252. }%
  253. % end of footnotehyper 2017/02/16 v0.99
  254. % some extras for Sphinx :
  255. % \sphinxfootnotemark: usable in section titles and silently removed from TOCs.
  256. \def\sphinxfootnotemark [#1]%
  257. {\ifx\thepage\relax\else\protect\spx@opt@BeforeFootnote
  258. \protect\footnotemark[#1]\fi}%
  259. \AtBeginDocument{%
  260. % let hyperref less complain
  261. \pdfstringdefDisableCommands{\def\sphinxfootnotemark [#1]{}}%
  262. % to obtain hyperlinked footnotes in longtable environment we must replace
  263. % hyperref's patch of longtable's patch of \@footnotetext by our own
  264. \let\LT@p@ftntext\FNH@hyper@fntext
  265. % this *requires* longtable to be used always wrapped in savenotes environment
  266. }%
  267. \endinput
  268. %%
  269. %% End of file `footnotehyper-sphinx.sty'.

A Python package for graph kernels, graph edit distances and graph pre-image problem.