3

I need an alpha counter in a foreach loop :

\documentclass{article}
\usepackage{tikz}

\makeatletter

\newcommand{\TRAA}[1]{%
    % node/angle list
    \foreach \x/\y [count=\i from 1] in {#1} {%
        \expandafter\xdef\csname Pt@\Alph{\i}\endcsname{\x}
        \expandafter\xdef\csname Ang@\Alph{\i}\endcsname{\y}

    }
\draw (\Pt@A) -- (\Pt@B) ;
}

\makeatother

\begin{document}

essai

\begin{tikzpicture}
\coordinate (C) at (0,0) ;
\coordinate (B) at (109:7) ;

\TRAA{B/71,C/45}

\end{tikzpicture}
\end{document}
  • 2
    \Alph{} requires its argument to be a counter, so if you create one (\newcounter{temp}) in the preamble, then set it (\setcounter{temp}{\i}) and use it as \Alph{temp}, the code becomes working. – Sergei Golovan Jan 4 '18 at 11:05
  • Thank you. I expected an elegant alternative such as Christian Hupfer gave. – Tarass Jan 4 '18 at 11:30
3

The \Alph macro requires a counter (as stated by Sergei already), but internally it uses \@Alph, which does not need a counter but the literal number only.

So

\makeatletter\@Alph{5}\makeatother

would print E, since E is the 5th letter in the Latin alphabet.

Replacing \Alph by \@Alph works, the necessary \makeatletter...\makeatother pair is in O.P. code already.

\documentclass{article}
\usepackage{tikz}

\makeatletter

\newcommand{\TRAA}[1]{%
    % node/angle list
  \foreach \x/\y [count=\i from 1] in {#1} {%
      \expandafter\xdef\csname Pt@\@Alph{\i}\endcsname{\x}
      \expandafter\xdef\csname Ang@\@Alph{\i}\endcsname{\y}
    }
    \draw (\Pt@A) -- (\Pt@B) ;
  }

\makeatother

\begin{document}

essai

Omitting a counter \makeatletter\@Alph{5}\makeatother

\begin{tikzpicture}
\coordinate (C) at (0,0) ;
\coordinate (B) at (109:7) ;

\TRAA{B/71,C/45}

\end{tikzpicture}
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.