修改 expl3 命令以在参数中使用 \vspace

修改 expl3 命令以在参数中使用 \vspace

如何\wantedcontact修改此命令 ( ) 才能\vspace{ }在其参数中接受命令?其他命令在其参数中\placetextbox给出时可以正常工作\vspace

\documentclass{article}

\usepackage{xcolor}
\definecolor{wanted}{HTML}{3D2113}

\RequirePackage{eso-pic}

\newcommand{\placetextbox}[3]{% \placetextbox{<horizontal pos>}{<vertical pos>}{<stuff>}
        \AddToShipoutPictureFG*{%
        \put(\LenToUnit{#1\paperwidth},%
        \LenToUnit{#2\paperheight}){\parbox{\textwidth}{#3}}
  }%
}%

\ExplSyntaxOn

\NewDocumentCommand \wantedcontact { o +m }
 {
  \textbox_placement:ne { #1 } { #2 }
 }

\msg_new:nnnn { wantedcontact } { unsupported-argument }
    % When not using an accepted entry
  { Unsupported~ entry~ field~ `#1'~ }
  { Only~entries~'reward'~or~'noreward'~allowed. }

\tl_const:Nn  \c__page_placement_default_tl { reward }

\cs_new_protected:Npn \textbox_placement:nn #1#2
 {
  \tl_if_novalue:nTF {#1}
  { 
    \textbox_placement:Vn \c__page_placement_default_tl { #2 }
  }
  {
    \str_case_e:nnF { \str_foldcase:n { #1 } }
     {
      { reward   } { \placetextbox{0.036}{0.369}{\fontfamily{cmtt}\selectfont\color{wanted}#2} }
      { noreward } { \placetextbox{0.036}{0.103}{\fontfamily{cmtt}\selectfont\color{wanted}#2} }
     }
     { \msg_error:nnn { wantedcontact } { unsupported-argument } { #1 } }
  }
 }

\cs_generate_variant:Nn \textbox_placement:nn {ne,Vn}

\ExplSyntaxOff

\begin{document}

Hello.

\wantedcontact[ReWaRd]{
a\vspace{2cm}\\b
}

\placetextbox{0.036}{0.369}{a\vspace{2cm}\\b}

\end{document}

看看可能会有用:Expl3 语法命令不起作用

答案1

e就像\edef你不能使用任意的 latex 构造。你真的需要在这里完全扩展吗?为什么不使用基本形式nn?如果我用它替换,\textbox_placement:ne\textbox_placement:nn会运行而不会出错,并排版 hello a 和 b

相关内容