I want to redefine the ampersand-charakter to expand to a macro, I defined. Basically it is/should be something like

&={\hspace*{30pt}Ampersand has been redefined\hfill}

The final use is


\newcommand{encap}[1]{ { % make definitions of \ns local / limit scope
\DeclareDocumentCommand{\ns}{s O{0 pt}}{%
    \divide\tempi by 2%
    \ifx##1\BooleanTrue \hskip 0pt plus 1fill minus 1fill \hspace*{\tempi}-\hspace*{\tempi}%
        \hskip 0pt plus 1fill minus 1fill%
        \hskip 0pt plus 2fill minus 2fill \hspace*{##2}%


}} % encap

\encap{this\ns equals& this}
\ns % out of scope
& % should be restored

BTW.: The \ns command works exactly as intended

  • 1
    Why don't you make a complete example? And did you really thought throught the consequences if you make & is active and it no longer can be used in a tabular? May 27 '16 at 15:01
  • @UlrikeFischer I thought this through (at least I think). Inside of \encap there can't be used the tabular-environment, but this is absolutely okay. May 27 '16 at 15:11
  • So you want that & does \ns only inside the argument to \encap?
    – egreg
    May 27 '16 at 15:16
  • 1
    You could use expl3 and do a \tl_replace_all:Nnn \l_tmpa_tl { & } { \ns }.
    – Manuel
    May 27 '16 at 15:27
  • 1
    @MaestroGlanz It won't break.
    – Manuel
    May 27 '16 at 15:38

It's not clear what is the intended usage of \ns; however, here's an implementation.

I fixed the most obvious weaknesses in your code.




% define active & to be normal &
% make & active


\NewDocumentCommand{\ns}{s O{0 pt}}{%
     \hspace{0pt plus 1fill minus 1fill}%
     \hspace{0pt plus 1fill minus 1fill}%
     \hspace{0pt plus 2fill minus 2fill}\hspace*{#2}%


\makebox[\textwidth]{\encap{this \ns equals & this}}

\makebox[\textwidth]{\encap{this \ns* equals &* this}}

\makebox[\textwidth]{\encap{this \ns*[10pt] equals &*[10pt] this}}

 text & text \\
 a & b


enter image description here

  • That's ecactly what it should do. May 27 '16 at 15:36

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.