
Minha pergunta é semelhante aMatemática em negrito: escolha automática entre \mathbf e \boldsymbol para símbolos latinos e gregos?, mas um pouco diferente. Meu exemplo mínimo não compilável é o seguinte:
\documentclass{book}
\usepackage{amssymb}
\newcommand{\tensor}[1]{if latin alphabet \mathbb{#1} else \mathbf{#1}}
\begin{document}
$\tensor{A}$ $\tensor{\Lambda}$
\end{document}
O que é sugerido é alcançável? A partir do exemplo abaixo, entendo que não há uma troca eficiente neste momento entre os alfabetos matemáticos latino e grego se usarmos pdflatex. Também entendo que uma solução seria mudar para lualatex, onde os alfabetos latino e grego são tratados de forma diferente.
Responder1
Não tenho as mtpro2
fontes, então usarei uma opção diferente de fontes.
A ideia é que as letras latinas sejam chamadas por si mesmas (ou seja, caracteres), enquanto as letras gregas sejam chamadas por sequências de controle. Então
\documentclass{article}
\usepackage{bm}
\newcommand\tensor[1]{%
\ifcat\noexpand#1\relax % check if the argument is a control sequence
\bm{#1}% probably Greek
\else
\textsf{#1}% single character
\fi
}
\begin{document}
$\tensor{X}\tensor{\Lambda}$
\end{document}
Limitação.Apenas um token deve ser fornecido como argumento para \tensor
. Qualquer uma \tensor{AB}
ou \tensor{A\Lambda}
qualquer variação de token múltiplo falharia.
Uma macro multitoken baseada na mesma ideia:
\documentclass{article}
\usepackage{xparse}
\usepackage{bm}
\ExplSyntaxOn
\NewDocumentCommand\tensor{m}
{
\pluton_tensor:n { #1 }
}
\cs_new_protected:Npn \pluton_tensor:n #1
{
\tl_map_inline:nn { #1 }
{
\token_if_cs:NTF ##1 { \bm { ##1 } } { \textsf { ##1 } }
}
}
\ExplSyntaxOff
\begin{document}
$\tensor{X}\tensor{\Lambda}$
$\tensor{X\Lambda}$
\end{document}
É claro que isso ainda falhará se uma entrada arbitrária for usada.
Uma versão talvez mais robusta, com substituto para tokens desconhecidos.
\documentclass{article}
\usepackage{xparse}
\usepackage{bm}
\ExplSyntaxOn
\NewDocumentCommand\tensor{m}
{
\pluton_tensor:n { #1 }
}
\cs_new_protected:Npn \pluton_tensor:n #1
{
\tl_map_inline:nn { #1 }
{
\pluton_tensor_inner:n { ##1 }
}
}
\cs_new_protected:Npn \pluton_tensor_inner:n #1
{
\tl_if_in:VnTF \g_pluton_latin_tl { #1 }
{
\textsf { #1 } % a Latin letter
}
{
\tl_if_in:VnTF \g_pluton_greek_tl { #1 }
{
\bm { #1 } % a Greek letter
}
{
#1 % fall back
}
}
}
\tl_new:N \g_pluton_latin_tl
\tl_new:N \g_pluton_greek_tl
\tl_gset:Nn \g_pluton_latin_tl
{
ABCDEFGHIJKLMNOPQRSTUVWXYZ
abcdefghijklmnopqrstuvwxyz
}
\tl_gset:Nn \g_pluton_greek_tl
{
\Gamma\Delta\Theta\Lambda\Pi\Sigma\Upsilon\Phi\Chi\Psi\Omega
}
\ExplSyntaxOff
\begin{document}
$\tensor{X}\tensor{\Lambda}$
$\tensor{X\Lambda}$
\end{document}
Responder2
Se você quiser algo mais flexível, talvez isso possa ser útil no futuro:
\documentclass{book}
\usepackage{expl3,xparse}
\ExplSyntaxOn
\keys_define:nn { pluton / tensor } {
latin .tl_set:N = \pluton_tensor_latin_tl,
greek .tl_set:N = \pluton_tensor_greek_tl,
latin-alphabet .tl_set:N = \pluton_tensor_latin_alphabet_tl,
greek-alphabet .tl_set:N = \pluton_tensor_greek_alphabet_tl,
}
\cs_new:Nn \pluton_tensor:n {
\tl_if_in:NnTF \pluton_tensor_latin_alphabet_tl { #1 } {
\pluton_tensor_latin_tl { #1 }
} {
\tl_if_in:NnT \pluton_tensor_greek_alphabet_tl { #1 } {
\pluton_tensor_greek_tl { #1 }
}
}
}
\NewDocumentCommand \tensor { O{} m } {
\group_begin:
\keys_set:nn { pluton / tensor } {
latin-alphabet = abcdefhijklmnopqrstuvwxyz
ABCDEFHIJKLMNOPQRSTUVWXYZ,
greek-alphabet = \alpha\beta\delta\epsilon
\phi\gamma\eta\iota\theta
\kappa\lambda\mu\nu\pi\chi
\rho\sigma\tau\omega\xi\psi\xi
\Alpha\Beta\Delta\Epsilon % capitals; some of
\Phi\Gamma\Eta\Iota\Theta % these *definitely*
\Kappa\Lambda\Mu\Nu\Pi\Chi % aren't defined, but
\Rho\Sigma\Tau\Omega\Xi\Psi\Xi, % emacs helps :)
latin = \mathbf,
greek = \mathrm,
#1
}
\pluton_tensor:n { #2 }
\group_end:
}
\ExplSyntaxOff
\begin{document}
$\tensor{A}$ $\tensor{\Lambda}$
\end{document}