8

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}%
   \addtolength{\st@pic@width}{\st@shadowoffsetx}%
   \addtolength{\st@pic@height}{\st@shadowoffsety}%
   %
   \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}%
   \edef\num@offsetx{\strip@pt\st@shadowoffsetx}%
   \edef\num@offsety{\strip@pt\st@shadowoffsety}%
   \raisebox{-\st@shadowoffsety}{
   \begin{picture}(\num@pw,\num@ph)(0,0)
        \put(\num@offsetx,0){\makebox(\num@tw,\num@th)[tl]{\color{\st@shadowcolor}\def\color##1{}\ignorespaces #1}}
        \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?

8
  • Here is the definition: \long macro:->\not@math@alphabet \bfseries \mathbf \fontseries \bfdefault \selectfont
    – Sigur
    Apr 26 '14 at 16:18
  • 2
    \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.
    – egreg
    Apr 26 '14 at 16:24
  • 1
    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"?
    – Jansen
    Apr 26 '14 at 16:35
  • 4
    @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
5

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{shadowtext}
\usepackage{stringstrings}
\long\def\beginshadowtext#1\endshadowtext{\shadowtexthelper#1 \relax\relax\kern0.666ex}
\long\def\shadowtexthelper#1 #2\relax{%
  \isnextbyte[q]{\par}{#1}%
  \if T\theresult\par\gobbleshadowtext#1\relax\relax\else%
    \shadowtext{#1}\ \kern-.666ex\fi%
  \ifx\relax#2\else\shadowtexthelper#2\relax\fi%
  }
\long\def\gobbleshadowtext#1#2\relax{%
  \isnextbyte[q]{\par}{#2}%
  \if T\theresult\par\gobbleshadowtext#2\relax\relax\else%
    \leavevmode\kern-0.666ex\shadowtext{#2}\ \kern-.666ex\fi%
}
\parskip 1em
\begin{document}
\shadowtext{This is a test}\ xyz

Start now!\beginshadowtext
This is a test this is a test this is a test. this is a test
this is a test this is a test. this is a test this is a test this is a test.
This is a test this is a test this is a test. this is a test
this is a test this is a test. this is a test this is a test this is a test.

this is a test this is a test this is a test. this is a test
this is a test. this is a test this is a test this is a test this is a test.
\par\par\par
The end.\endshadowtext
Back to normal.
\end{document}    

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.