Bucle sobre letras griegas con pgffor

Bucle sobre letras griegas con pgffor

Actualmente estoy combinando las soluciones propuestas.aquípara la definición de bucle de comandos yaquípara la letra mayúscula que obliga a definir notaciones matemáticas en un bucle.

El objetivo es tener un atajo para todas las letras de los alfabetos latino y griego en negrita y mayúsculas/minúsculas.

Para el alfabeto latino, la solución actual funciona bien, pero para el griego no funcionará.

Entonces tengo dos preguntas aquí:

  • 1: ¿Es posible recorrer automáticamente las letras griegas con pgffor, al igual que con las letras latinas?
  • 2: ¿Existe alguna razón por la que mi solución actual no funcione con letras griegas?

Como es habitual, la respuesta puede ser muy corta o muy larga, así que gracias de antemano.

\documentclass{article}

% Command forcing 1st letter of argument to be capital one
\usepackage{xparse}
\ExplSyntaxOn
\NewExpandableDocumentCommand \firstcap { m } { \tl_mixed_case:n {#1} }
\ExplSyntaxOff

% Loop over latin alphabet (working)
\usepackage{pgffor}
\foreach \x in {a,...,z}{%
\expandafter\xdef\csname \firstcap{\x}mat\endcsname{\noexpand\ensuremath{\noexpand\mathbf{\firstcap{\x}}}}
}
\foreach \x in {a,...,z}{%
\expandafter\xdef\csname \firstcap{\x}vec\endcsname{\noexpand\ensuremath{\noexpand\mathbf{\x}}}
}
% Loop over greek alphabet (non working)
%\foreach \x in {alpha,zeta}{%
%\expandafter\xdef\csname \firstcap{\x}mat\endcsname{\noexpand\ensuremath{\noexpand\mathbf{\firstcap{\x}}}}
%}
%\foreach \x in {\alpha,...,\zeta}{%
%\expandafter\xdef\csname \firstcap{\x}vec\endcsname{\noexpand\ensuremath{\noexpand\mathbf{\x}}}
%}

\begin{document}
$\Amat \Bmat \Cmat \Avec \Bvec \Cvec$
%$\Alphamat \Betamat \Alphavec \Betavec$
\end{document}

Respuesta1

Tienes que definir la lista tú mismo, pero es un trabajo de una sola vez. Además, definir \Alphamatcomo \bm{\Alpha}no hará nada sensato, ya que \Alphano está definido.

Creo que es más sencillo de usar directamente expl3en lugar de incómodo \foreachcon \csnamey \noexpandsus amigos.

Como siempre, omití \ensurematheso que no sirve de nada aquí: \Amates un comando para un símbolo matemático.

No estoy seguro de cuál es la razón para tener un comando \Avecque imprime una “a” minúscula en negrita.

\documentclass{article}
\usepackage{amsmath,bm}

% Command forcing 1st letter of argument to be capital one
\usepackage{xparse}

\ExplSyntaxOn

\cs_new_protected:Nn \bamboo_define:nnnnN
 {
  \cs_new_protected:cpx { #1 #3 } { \exp_not:N #4{#5{#2}} }
 }

\int_step_inline:nnn { `A } { `Z }
 {
  \bamboo_define:nnnnN
   { \char_generate:nn { #1 } { 11 } } % character
   { \char_generate:nn { #1 } { 11 } } % character
   { mat }                             % suffix
   { \mathbf }                         % decoration
   \use:n                              % just the argument
 }
\int_step_inline:nnn { `a } { `z }
 {
  \bamboo_define:nnnnN
   { \char_generate:nn { #1 -32 } { 11 } } % character
   { \char_generate:nn { #1 } { 11 } }     % uppercase variant
   { vec }                                 % suffix
   { \mathbf }                             % decoration
   \use:n                                  % just the argument
 }
\clist_map_inline:nn
 {
  Gamma,Delta,Theta,Lambda,Xi,Pi,Sigma,Phi,Psi,Omega
 }
 {
  \bamboo_define:nnnnN
   { #1 }  % the Greek letter name with first uppercase
   { #1 }  % the Greek letter name with first uppercase
   { mat } % suffix
   { \bm } % decoration
   \use:c  % make a control sequence
 }
\clist_map_inline:nn
 {
  alpha,beta,gamma,delta,epsilon,zeta,eta,theta,iota,kappa,
  lambda,mu,nu,xi,pi,rho,sigma,tau,phi,chi,psi,omega
 }
 {
  \bamboo_define:nnnnN
   { \tl_mixed_case:n { #1 } } % the Greek letter name with first uppercase
   { #1 }                      % the Greek letter name
   { vec }                     % suffix
   { \bm }                     % decoration
   \use:c                      % make a control sequence
 }

\ExplSyntaxOff

\begin{document}
$\Amat \Bmat \Cmat \Avec \Bvec \Cvec$
$\Gammamat \Deltamat \Alphavec \Betavec$
\end{document}

ingrese la descripción de la imagen aquí

Considerándolo todo, creo que perdió más tiempo definiendo los bucles que definiendo todos los comandos manualmente. ;-)Pero, por supuesto, el interés académico tiene su papel.

Respuesta2

información relacionada