2

I have created a \newcommand with some arguments that allow me to call an other command.

Command syntax:

\newcommand{\nodeperso}[1]{\node[\noexpand\type#1](){\noexpand\nom#1};}

I have declared a style:

Boite/.style={rounded rectangle,font=\ttfamily} 

After that I declare two other new commands like this:

\newcommand{\typeAAB}{Boite}
\newcommand{\nomAAB}{coucou}

I want to call the \nodeperso command with AAB as argument (\nodeperso{AAB}). \nomAB is correctly expanded but not \typeAB.

Maybe the use of pgfkeys can provide better results but I am not familiar with the syntax.

MWE:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes}

\newcommand{\nodeperso}[1]{\node[\noexpand\type#1](){\noexpand\nom#1};}
\newcommand{\typeAAB}{Boite}
\newcommand{\nomAAB}{coucou}

\begin{document}
\begin{tikzpicture}[Boite/.style={rounded rectangle,font=\ttfamily}]

\node[Boite]{coucou};  %% OK
\node[\typeAAB]{\nomAAB};  %% OK

\nodeperso{AAB}  %% NOK

\end{tikzpicture}
\end{document}
2
  • Please help us help you and add a minimal working example (MWE) that illustrates your problem. Reproducing the problem and finding out what the issue is will be much easier when we see compilable code, starting with \documentclass{...} and ending with \end{document}.
    – user31729
    Jun 19, 2015 at 15:03
  • I have updated my question
    – Guuk
    Jun 19, 2015 at 15:09

1 Answer 1

4

I think it should rather be a \csname type#1\endcsname instead of \noexpand\type#1.

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes}

\newcommand{\nodeperso}[1]{\node[\csname type#1\endcsname](){\csname nom#1\endcsname};}
\newcommand{\typeAAB}{Boite}
\newcommand{\nomAAB}{coucou}

\begin{document}
\begin{tikzpicture}[Boite/.style={rounded rectangle,font=\ttfamily}]

\node[Boite]{coucou};  %% OK
\node[\typeAAB]{\nomAAB};  %% OK

\nodeperso{AAB}  %% NOK

\end{tikzpicture}
\end{document}

enter image description here

8
  • Thank you. Do you have any idea of where I can find any complete information about \csname, \endcsname, \expandafter and \noexpand command?
    – Guuk
    Jun 19, 2015 at 15:15
  • 1
    Wait, shouldn't your code give "coucou" as well as the node text?
    – Alenanno
    Jun 19, 2015 at 15:16
  • 1
    @Alenanno: Yes, I've forgotten to remove the second \noexpand -- will update
    – user31729
    Jun 19, 2015 at 15:17
  • @Guuk: I am sure there are many questions on those elementary TeX commands, as well as in TeX by Topic for example. But I can add some short explanation
    – user31729
    Jun 19, 2015 at 15:20
  • I already use it many times but I don't really understand the purpose of these commands. They seem to be not well explain or I don't find the right explanation. I don't want to take your time. I will look more precisely for an description. Thank you.
    – Guuk
    Jun 19, 2015 at 15:24

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.