% -*- Mode: TeX -*- \ifx\thisfileis\anUndefinedMacro\input maybeload \fi \thisfileis{defstring} % abort loading if we're already loaded \input redefine % This file defines the top-level construction % % \defstring\foo "this is a string with \$% special characters" % % which defines the control sequence \foo so that it expands into % a "{" begin-group symbol, a sequence of plain characters as given % by the string, and a "}" end-group symbol. \foo will then be % suitable for \expandafter\index\foo within a footnote, and similar % uses. % \defstring won't work right inside \footnote or any other % construction that reads its argument before \defstring gets % to expand, because it works by changing reader syntax. \makeatletter \newtoks\defstring@toks \def\defstring#1{\def\@defstringdef{\edef#1{\the\defstring@toks}}\begingroup \let\do\@makeother \dospecials \defstring@read} \def\defstring@read#1{\def\@tempa##1#1{\global\defstring@toks{{##1}}\endgroup \@defstringdef}\@tempa} \makeatother