2

I'd like to implement a global option on a package that I maintain, as per Mats's suggestion (here). The package is sepfootnotes, and the suggested modification will allow footnotes' content definitions optionally to take global scope. This will make sepfootnotes compatible with the subfiles package.

So, the basic idea is to put a macro before \@namedef, say \sep@scope, and then let users define this macro either as \global or as something else to keep it local.

My question is: what should this something else be? What is the safest default expansion for this macro: \relax?

sepfootnotes.sty (beta, minimal)

\NeedsTeXFormat{LaTeX2e}[1996/06/01]
\ProvidesPackage{sepfootnotes}[2016/07/17 v0.3c Footnotes in separate file]

\DeclareOption{global}{\sep@opt@globaltrue}
\newif\ifsep@opt@global
\ProcessOptions

\newcommand\sep@scope{\relax}
\ifsep@opt@global
 \renewcommand\sep@scope{\global}
\fi

\newcommand\sep@namedef[2]{\sep@scope\@namedef{prefix#1}{#2}}
\newcommand\sep@nameuse[1]{\@nameuse{prefix#1}}

\newcommand\sepfootnotecontent{\sep@namedef}
\newcommand\sepfootnote{\sep@nameuse}

\endinput

doc.tex

\documentclass{article}
\usepackage[global]{sepfootnotes}[2016/07/17 v0.3c]

\begin{document}

\begingroup
 \sepfootnotecontent{key}{content}
\endgroup

my \sepfootnote{key}

\end{document}
10
  • Does it need to expand to anything?
    – cfr
    Commented Jul 18, 2016 at 1:07
  • I don't know. You mean, does \sep@scope need to expand to anything? Or the expansion of \sep@scope itself? Commented Jul 18, 2016 at 4:38
  • I would probably go with \let\sep@scope\global or \let\sep@scope\empty. If the choice for the latter is \relax, is it more than {}, since it's also not expandable.
    – Werner
    Commented Jul 18, 2016 at 5:15
  • The only thing I’d really be concerned about is that someone might want to use other prefixes as well. Now, according to the syntax rules of p. 275, \long\relax\def\test{A test}, say, shouldn’t be legal, which suggests that \let\sep@scope\@empty is the right thing to do; nevertheless, I’ve tried the above input with both TeXLive’s pdftex and with the TeX program incorporated in OzTeX (This is TeX, Version 3.14159), and both accepted it.
    – GuM
    Commented Jul 18, 2016 at 7:15
  • @GustavoMezzetti I believe that it should always be \long, because a footnote can consist of more than one paragraph.
    – egreg
    Commented Jul 18, 2016 at 8:11

1 Answer 1

4

The suggested code is Ok, although a better default would probably be

\newcommand\sep@scope{}

but it introduces four csnames that are not really needed (\ifsep@opt@global, \sep@opt@globaltrue, \sep@opt@globalfalse, \sep@scope

an alternative scheme would be

\NeedsTeXFormat{LaTeX2e}[1996/06/01]
\ProvidesPackage{sepfootnotes}[2016/07/17 v0.3c Footnotes in separate file]

\newcommand\sep@namedef[2]{\@namedef{prefix#1}{#2}}
\DeclareOption{global}{\renewcommand\sep@namedef[2]{\global\@namedef{prefix#1}{#2}}}
\ProcessOptions


\newcommand\sep@nameuse[1]{\@nameuse{prefix#1}}

\newcommand\sepfootnotecontent{\sep@namedef}
\newcommand\sepfootnote{\sep@nameuse}

\endinput
3
  • I will try to adapt your scheme to the actual \sep@namedef, as it actually expands to something much longer than that. I will drop \sep@scope, which is good, but keep \ifsep@opt@global and then modify the relevant line of \sep@namedef to \ifsep@opt@global \global \@namedef {...}\else \@namedef{...}\fi Commented Jul 18, 2016 at 13:02
  • Hi David and Eduardo. Trying to implement this, I would need some handholding. Is this accomplished by (1) moving up \newcommand\sep@namereplace [3] {\@namedef{sepfootnotes@text@#1@#2}{#3}} to the top, (2) \renewcommand that in the \DeclareOption part and finally (3) replace \@namedef{sepfootnotes@text@#1@#2}{#3} in \sep@namedef with \sep@namereplace{#1}{#2}{#3}? Or am I missing the/a point?
    – Mats
    Commented Jul 18, 2016 at 18:53
  • The order in which macros are defined doesn't matter until they are used. There must be counterexamples but I think this is safe to say about my package. (By the way, I decided merely to prepend \ifsep@opt@global\global\fi to occurrences of \@namedef) Commented Jul 18, 2016 at 23:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .