A quick way to make 26 macros (one for each letter)

Instead of creating a macro for each letter, as in

\def\bA{\mathbf{A}}
...
\def\bZ{\mathbf{Z}}

Is there a way to iterate over a character class (e.g. uppercase letters) and generate macros for each? I would also like to do the same for Greek letters (using bminstead mathbf).

+5
source share
4 answers
\def\mydefb#1{\expandafter\def\csname b#1\endcsname{\mathbf{#1}}}
\def\mydefallb#1{\ifx#1\mydefallb\else\mydefb#1\expandafter\mydefallb\fi}
\mydefallb ABCDEFGHIJKLMNOPQRSTUVWXYZ\mydefallb

New for greek

\def\mydefgreek#1{\expandafter\def\csname b#1\endcsname{\text{\boldmath$\mathbf{\csname #1\endcsname}$}}}
\def\mydefallgreek#1{\ifx\mydefallgreek#1\else\mydefgreek{#1}%
   \lowercase{\mydefgreek{#1}}\expandafter\mydefallgreek\fi}
\mydefallgreek {beta}{Gamma}{Delta}{epsilon}{etaex}{Theta}{Iota}{Lambda}{kappa}{mu}{nu}{Xi}{Pi}{rho}\mydefallgreek


$\bGamma\bDelta \bTheta \bLambda \bXi \bPi $

$\bbeta \bgamma\bdelta \bepsilon \betaex \btheta \biota \blambda \bkappa \bmu \bnu \bxi \bpi \brho$
+6
source

Turning around Andrew's answer, here is a solution without \expandafter:

\makeatletter
\@tempcnta=\@ne
\def\@nameedef#1{\expandafter\edef\csname #1\endcsname}
\loop\ifnum\@tempcnta<27
  \@nameedef{b\@Alph\@tempcnta}{\noexpand\mathbb{\@Alph\@tempcnta}}
  \advance\@tempcnta\@ne
\repeat

This will determine \bA, \bBetc., to expand to \mathbb{A}, \mathbb{B}etc.

+6
source

\newcommand\bm[1]{\ensuremath{${\boldmath$#1$}}$}

text, math. :

\[\bm{F(x)}=\int\bm\delta(x)\ dx]
\where \mb F is blah blah blah and \bm \delta is halb halb halb...

:
F (x)= 'inegral delta​​strong > (x)' dx
F - -- "- halb halb halb...

(roman), \boldmath . ( ). (${\boldmath) , \boldmath #1

\bb \bg. , LaTeX makros.

, , .

+4

:

\newcommand{\b}[1]{\mathbf{#1}}

as Crowley says, and similar for all other alphabets. However, if you really want to do this with LaTeX code, it seems to work here:

\documentclass{article}
\usepackage{amssymb}
\newcounter{char}
\setcounter{char}{1}

\loop\ifnum\value{char}<27
\edef\c{\Alph{char}}
\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\def\expandafter\expandafter\expandafter\csname\expandafter\expandafter\expandafter b\expandafter\c\expandafter\endcsname\expandafter{\expandafter\mathbb\expandafter{\c}}
\addtocounter{char}{1}
\repeat

\begin{document}

\(\bZ\)
\end{document}

I lost track of how much "expands after that!" To get lowercase letters, replace Alph with a letter.

+3
source

All Articles