从给定的宏创建开关

从给定的宏创建开关

我想创建与命令 相当的\bfseries命令,其定义如下:\textbf\shadowtext

\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%
}

我第一次天真的尝试是让该参数成为可选的,但这当然没有成功:)。

那么,我怎样才能\shadowtext变成这样的开关\bfseries

答案1

我不确定如果内容不是文本会发生什么,但我确保它可以与嵌入的\pars 一起使用。然而,考虑到标准宏形式\shadowtext{}不能换行,这提供了显着的改进。

使用\beginshadowtext\endshadowtext喜欢环境分隔符。

注意:\kerns 是必需的,因为底层\shadowtext宏有点奇怪。您会从输出的第一行注意到,宏形式与段落缩进不一致。同样在同一行文本上,必须在宏形式调用的末尾手动添加一个空格,但情况不应该如此。所以\kern我的环境中使用 s 是为了弥补这些不足。

\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}    

在此处输入图片描述

相关内容