# How can I pass an argument to a command defined and called in a .cls file using another command called in a .tex and defined in the previous .cls?

I am building a résumé on which I would like to list the languages I speak and my level in each one of them. To present the levels, I wish to use skill dots. I want to obtain a structure similar to the one shown in the image below

To do so, I defined a new command named \cvlanguages on a .cls file :



Later on the .cls code, in order to print the "Languages" section on the résumé, I use the following:

\ifthenelse{\equal{\cvlanguages}{}}{}{
\profilesection{LANGUAGES}
{\cvlanguages}
}


\profilesection is defined elsewhere and is not important here.

The \grade command is also on the .cls file and is given by:

\newcommand{\grade}[1]{
\begin{tikzpicture}
\clip (1em-.4em,-.35em) rectangle (5em +.5em ,1em);
\foreach \x in {1,2,...,5}{
\path[{fill=backColor}] (\x em,0) circle (.35em);
}
\begin{scope}
\clip (1em-.4em,-.35em) rectangle (#1 em +.5em ,1em);
\foreach \x in {1,2,...,5}{
\path[{fill=frontColor}] (\x em,0) circle (.35em);
}
\end{scope}
\end{tikzpicture}%
}


On the .tex file, I use the following line to call the \cvlanguages command:

\cvlanguages{Portuguese}{5}



I have considered an alternative solution using something like this instead:

\ifthenelse{\equal{\cvlanguages}{}}{}{
\profilesection{LANGUAGES}
{\fontsize{0.36cm}{0.432cm} \selectfont \cvlanguages{#1} \grade{\cvlanguages{#2}}}
}


but I have no idea how to make this work, as specifying which argument to print using "#" doesn't seem to work inside this \ifthenelse environment.

I am new to this level of LaTex and have spent a while trying to figure this out, with no success. I would appreciate any help on how to work around this problem.

• \ifthenelse doesn't care about #1, #2, etc. These, when used in the replacement text of a macro, are replaced by the corresponding arguments when said macro is expanded. IMHO, you should provide one file (code block) containing your code, as short as possible. Something self-contained. You can use the filecontents (or filecontents*) environment if you really need several files. Otherwise, it is just complicated and fuzzy for us to guess how each part is used and what fails in which way. Aug 7 '19 at 22:25
• It's hard to tell without a full example document, but only from your code snippets my best guess is that at some point \cvlanguages is defined to call itself when expanded, thus bringing the compiler into an infinite loop. Also, what's the purpose of the test \equal{\cvlanguages}{}}? Given either of your definitions for \cvlanguages, this command can never produce an empty token list. Aug 8 '19 at 0:04

Initially \cvlanguages is defined to consume two non delimited macro arguments and to redefine itself.
This redefining can happen exactly once.
When this redefining happens, then \cvlanguages is redefined not to consume any macro argument and to expand to something like the phrase "Portugese \grade{5}" and thus is not "redefinable" any more.

This means:

1. You can use \cvlanguages exactly once with two non delimited macro arguments for setting one language.
After that you can use \cvlanguages without macro arguments for listing that one language and the skill-dots.

2. If you did not use \cvlanguages exactly once with two non delimited macro arguments for setting one language, then \cvlanguages is still defined to consume two non delimited macro arguments. This circumstance may/will disturb the comparison of \cvlanguages's expansion to emptiness within the \ifthenelse-construct.

I suggest using the \@starttoc-mechanism:

In the example below the macro \cvlanguages is used for adding a language and a grade to the list of cvlanguages and the macro \listofcvlanguages is used for delivering the list of cvlanguages:

\documentclass{article}
\usepackage{tikz}

% As you didn't provide definitions for these, I invented something on my own:
\definecolor{frontColor}{named}{black}
\definecolor{backColor}{named}{lightgray}
\newcommand\profilesection[1]{%
\noindent\textsf{\textbf{#1}}\\\null\hrulefill\null\\%
}%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{tikzpicture}%
\clip (1em-.4em,-.35em) rectangle (5em +.5em ,1em);%
\foreach \x in {1,2,...,5}{%
\path[{fill=backColor}] (\x em,0) circle (.35em);%
}%
\begin{scope}%
\clip (1em-.4em,-.35em) rectangle (#1 em +.5em ,1em);%
\foreach \x in {1,2,...,5}{%
\path[{fill=frontColor}] (\x em,0) circle (.35em);%
}%
\end{scope}%
\end{tikzpicture}%
}%

\ifnum\cvlanguagecountmacro<1 \else
\ifnum\cvlanguagecountmacro<2 %
\profilesection{LANGUAGE}%
\else
\profilesection{LANGUAGES}%
\fi
\fi
}%
\newcommand\cvlanguagecountmacro{0}%
\xdef\cvlanguagecountmacro{%
\number\numexpr\cvlanguagecountmacro+1\relax
}%
}%
\newcommand\languageline[2]{%
}%
\makeatletter
\newcommand{\cvlanguages}[2]{%
\protected@write{\@mainaux}{}{%
}%
}%
\newcommand\listofcvlanguages{%
\@starttoc{cvl}%
}%
\makeatother

\begin{document}

Some text.

\listofcvlanguages

\cvlanguages{Portugese}{5}
\cvlanguages{English}{5}
\cvlanguages{WeirdSpeech}{2}
\cvlanguages{OddTongue}{1}

\end{document}