1

Edited: David Carlisle kindly provided the answer in a comment, which is the definition after \makeatletter.

I'm trying to use embellishments in \NewDocumentCommand to define a macro to kern subscripts on \Gamma (as a test case to a more general problem), but don't know how to handle primes. Since they don't take an argument, I tried the two commented versions below but in both cases in the last example the _ is no longer treated as an embellishment. Is there a way to fix this?

\documentclass{article}

\NewDocumentCommand{\kernedGamma}{e{^_}}{\Gamma\IfValueT{#1}{^{#1}}\IfValueT{#2}{_{\mkern-3mu #2}}}
%\NewDocumentCommand{\kernedGamma}{e{^_'}}{\Gamma\IfValueT{#1}{^{#1}}\IfValueT{#2}{_{\mkern-3mu #2}}\IfValueT{#3}{^{\prime}#3}}
%\NewDocumentCommand{\kernedGamma}{e{^_}t'}{\Gamma\IfValueT{#1}{^{#1}}\IfValueT{#2}{_{\mkern-3mu #2}}\IfBooleanT{#3}{^{\prime}}}

\makeatletter
\RenewDocumentCommand{\kernedGamma}{e{^_}t'e{_}}{\Gamma\IfValueT{#1}{^{#1}}
\IfValueT{#2}{_{\mkern-3mu #2}}\IfBooleanT{#3}{^{\prime}}
\IfValueT{#4}{\IfValueT{#2}{\@latex@error{embellishment used twice}}_{\mkern-3mu #4}}}
\makeatother

\begin{document}

$\Gamma_1$ $\kernedGamma_1$ 

$\Gamma^2_2$ $\kernedGamma^2_2$ 

$\Gamma_1'$ $\kernedGamma_1'$ 

$\Gamma'_1$ $\kernedGamma'_1$ 

\end{document}
4
  • e{^_}t'e{_} would allow you to pick up a _ (you woud need to flag error if #2 and #4 both used Commented Mar 17, 2023 at 10:10
  • That works perfectly, thank you! In this instance the double subscript error catches a duplicated embellishment, but I take your point that one should be cautious. I'll add the solution to the question, if that's appropriate. Commented Mar 17, 2023 at 10:31
  • sure you add a tested answer better than me just reposting the comment as an answer Commented Mar 17, 2023 at 10:33
  • 3
    No sorry do not post the answer in the question that messes up the site format (and after a while the system will delete it as unanswered) leave the question as a question, and post (and self-accept) an answer. Commented Mar 17, 2023 at 11:15

1 Answer 1

3

Use e{^_}t'e{^_}

\documentclass{article}

\NewDocumentCommand{\kernedGamma}{e{^_}t'e{^_}}{%
  \kernedGammaAux{#1}{#2}{#3}{#4}{#5}%
}

\ExplSyntaxOn

\NewDocumentCommand{\kernedGammaAux}{mmmmm}
 {
  \bourke_kernedGamma:nnnnn { #1 } { #2 } { #3 } { #4 } { #5 }
 }

\cs_new_protected:Nn \bourke_kernedGamma:nnnnn
 {%#1 = first sup, #2 = first sub, #3 = prime, #4 = second sup, #5 = second sub
  \Gamma
  \bool_if:nTF { #3 }
   {% there's a prime
    \sp{ \tl_if_novalue:nF { #1 } { #1 } \prime \tl_if_novalue:nF { #4 } { #4 } }
   }
   {%
    \exp_args:Ne \tl_if_empty:nF { \__bourke_double:nn { #1 } { #4 } }
     {
      \sp{ \__bourke_double:nn { #1 } { #4 } }
     }
   }
  \sb{ \mkern -3mu ~ \__bourke_double:nn { #2 } { #5 } }
 }

\cs_new:Nn \__bourke_double:nn
 {
  \tl_if_novalue:nF { #1 } { \exp_not:n { #1 } } 
  \tl_if_novalue:nF { #2 } { \exp_not:n { #2 } } 
 }

\ExplSyntaxOff

\begin{document}

$\kernedGamma$ $\Gamma$

$\kernedGamma'$ $\Gamma'$ $\Gamma^{\prime}$

$\kernedGamma'^{2}_{i}$ $\Gamma'^{2}_{i}$

$\kernedGamma_{i}^{2}'$ $\Gamma^{2\prime}_{i}$

$\kernedGamma_{i}'^{2}$ $\Gamma'^{2}_{i}$

$\kernedGamma_{i}^{2}$ $\Gamma^{2}_{i}$

\end{document}

(Picture will be added later, when Imgur allows it)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .