# Create a switch from a given macro

I would like to create the equivalent of what \bfseries is for \textbf, relative to the command \shadowtext, which is defined as:

\newcommand\shadowtext[1]%
{%
\begingroup%
\settowidth{\st@temp@width}{#1}%
\settoheight{\st@temp@height}{#1}%
\setlength{\st@pic@width}{\st@temp@width}%
\setlength{\st@pic@height}{\st@temp@height}%
%
\edef\num@tw{\strip@pt\st@temp@width}%
\edef\num@th{\strip@pt\st@temp@height}%
\edef\num@pw{\strip@pt\st@pic@width}%
\edef\num@ph{\strip@pt\st@pic@height}%
\begin{picture}(\num@pw,\num@ph)(0,0)
\put(0,\num@offsety){\makebox(\num@tw,\num@th)[tl]{\ignorespaces #1}}
\end{picture}}%
\endgroup%
\ignorespaces%
}


My first naive try was to make the argument optional, but that of course didn't work out :).

So, how do i turn \shadowtext into a switch like \bfseries?

• Here is the definition: \long macro:->\not@math@alphabet \bfseries \mathbf \fontseries \bfdefault \selectfont Apr 26 '14 at 16:18
• \bfseries is just an instruction telling TeX “from now on, typeset in boldface”; there is no look up in advance of the material to be typeset in boldface. Your \shadowtext macro needs to know what it must operate on. Apr 26 '14 at 16:24
• This is often referred to as a switch, since it doesn't require turns something on from that point forward.
– Werner
Apr 26 '14 at 16:24
• @egreg so there is no way of saying: "from now on add a shadow to all the text"? Apr 26 '14 at 16:35
• @Jansen no way in general no. Note that \textbf is defined in terms of \bfseries , not the other way round. Apr 26 '14 at 16:37

I'm not sure what happens if the content is other than text, but I made sure to make it work with embedded \pars. However, considering that the standard macro form \shadowtext{} cannot line break, this offers a notable improvement.

Use \beginshadowtext and \endshadowtext like environment delimiters.

Note: the \kerns are needed because the underlying \shadowtext macro is a bit funky. You will note from the first line of output that the macro form does not align with the paragraph indent. Also on the same line of text, a space had to be manually added at the end of the macro-form invocation, which should not be the case. So the \kerns in my environment are to compensate for those deficiencies.

\documentclass{article}
\usepackage{stringstrings}
\isnextbyte[q]{\par}{#1}%
}
\isnextbyte[q]{\par}{#2}%
}
\parskip 1em
\begin{document}