1

I'm trying to use pgffor to define a new command for \boldsymbol\mathsf like the following.

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

\newcommand\makemathsfbf[1]{
    \foreach\a\b\c in{#1}{
        \expandafter\gdef\csname\a\b\c\expandafter\endcsname\expandafter{%
            \expandafter\boldsymbol{\mathsf\expandafter{\a}}
        }
    }
}
\makemathsfbf{AAA,BBB,...,ZZZ} % {AAA,BBB, CCC, DDD, ..., ZZZ}

\begin{document}
$\AAA$ % = $\boldsymbol{\mathsf A}$
\end{document}

I want to use the above command, i.e., \AAA, to replace \boldsymbol{\mathsf A} and so on. However, I could not make it to work. How should I modify it?

9
  • First, it is not obvious what follows AAA. AAB? BBB? If I can't guess, how is the computer supposed to? As it stands, you should only be using \abc (or some other macro) instead of \a\b\c. Sep 13, 2021 at 13:43
  • @JohnKormylo You are right. I changed the list to make it more clear. Also, I tried \abc. Unfortunately, it didn't work out.
    – stackname
    Sep 13, 2021 at 13:53
  • what John meant is that apart from other considerations AAA,BBB,...,ZZZ is not a valid loop specification for pgf (or any other language I know) Sep 13, 2021 at 13:58
  • Also, you only need \expandafter for \gdef so that you don't redefine \csname instead of the expanded version. Sep 13, 2021 at 14:00
  • \boldsymbol\mathsf{A} would be the same as \boldsymbol{\mathsf}{A} You are missing the {} for \boldsymbol but you want to loop from A to Z not an undefined sequence from AAA to ZZZ, then construct the csname from three copies of the loop variable Sep 13, 2021 at 14:01

2 Answers 2

2

There is no way to define a loop AAA ... ZZZ you need A, ....Z but the pgf for loop isn't really helping here I would use

enter image description here

\documentclass{article}

\usepackage{bm,amsmath}

\makeatletter
\count@=1
\loop
\expanded{\noexpand\bmdefine\csname\@Alph\count@\@Alph\count@\@Alph\count@\endcsname
   {\noexpand\mathsf{\@Alph\count@}}}
\ifnum\count@<26
\advance\count@\@ne
\repeat


\begin{document}
$\mathsf{A}+\AAA$


$\mathsf{G}+\GGG$

\end{document}
1

This will run, but you will need to come up with a way to generate {AAA,BBB,...,ZZZ}. Maybe \Alph{\i}\Alph{\i}\Alph{\i}.

\documentclass{article}
\usepackage{amsmath}
\usepackage{pgffor}

\makeatletter
\newcommand\makemathsfbf[1]{
    \def\mylist{#1}
    \foreach \abc in \mylist {
        \expandafter\protected@xdef\csname\abc\endcsname{
            \boldsymbol{\mathsf{\abc}}
        }
    }
}
\makeatother

\makemathsfbf{AAA,BBB,ZZZ} % {AAA,BBB, CCC, DDD, ..., ZZZ}

\begin{document}
$\AAA$
\end{document}

You must log in to answer this question.

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