Considering this definition of a latex macro:
\newcommand\createCMDMANUV[4]{%
\expandafter\@ifdefinable\csname #3#2\endcsname{%
\expandafter\xdef\csname #3#2\endcsname##1{%
\noexpand\vcenteredhbox{%
\noexpand\includegraphics[width=##1,trim=0 0 1 -1]{BD_CATIA/#4/#1.png}}%
}%
}%
}
I try to deal with empty (not optional) parameter. So I tried this definition but it is not working:
\newcommand\createCMDMANUV[4]{%
\expandafter\@ifdefinable\csname #3#2\endcsname{%
\expandafter\xdef\csname #3#2\endcsname##1{%
\noexpand\vcenteredhbox{%
\ifdefempty{##1}{\def\widthCATIA{3cm}}{\def\widthCATIA{##1}}%
\includegraphics[width=\widthCATIA,trim=0 0 1 -1]{BD_CATIA/#4/#1.png}}%
}%
}%
}
I think it is due to the fact that \widthCATIA
is not well defined but what is the right syntax...
I call the command \createCMDMANUV{\tA}{\tB}{\tC}{\tD}
where \tA
to \tD
contains string.
For example if \tC
contains AVV
and \tB
contains test
the macro build the command \AVVtest
.
MWE (base on the same idea):
\documentclass{standalone}
\RequirePackage{xstring}
\RequirePackage{etoolbox}
\makeatletter
\newcommand\createCMDMANUV[2]{%
\expandafter\@ifdefinable\csname #1#2\endcsname{%
\expandafter\xdef\csname #1#2\endcsname##1{%
\noexpand\textbf{##1}%
}%
}%
}
\makeatother
\begin{document}
\def\tA {AA}
\def\tB {BB}
\createCMDMANUV{\tA}{\tB}
\AABB{coucou}
\end{document}
MNWE (Minimal Not Working Example :-) ):
\documentclass{standalone}
\RequirePackage{xstring}
\RequirePackage{etoolbox}
\makeatletter
\newcommand\createCMDMANUV[2]{%
\expandafter\@ifdefinable\csname #1#2\endcsname{%
\expandafter\xdef\csname #1#2\endcsname##1{%
\ifcsempty{##1}{ \expandafter\xdef\csname ttMANU\endcsname{Ahah}}{ \expandafter\xdef\csname ttMANU\endcsname{ohoh}}%
\noexpand\textbf{\csname ttMANU\endcsname}%
}%
}%
}
\makeatother
\begin{document}
\def\tA {AA}
\def\tB {BB}
\createCMDMANUV{\tA}{\tB}
\AABB{}
\AABB{aa}
\end{document}
\ifcsempty
seems not doing well the empty test.
SOLUTION of my MNWE:
\documentclass{standalone}
\RequirePackage{xstring}
\RequirePackage{etoolbox}
\makeatletter
\newcommand\createCMDMANUV[2]{%
\ifdefempty{##1}{\def\ttMANU{ahah}}{\def\ttMANU{ohoh}}%
\expandafter\@ifdefinable\csname #1#2\endcsname{%
\expandafter\xdef\csname #1#2\endcsname##1{%
\noexpand\ifblank{##1}{\def\noexpand\ttMANU{ahah}}{\def\noexpand\ttMANU{##1}}%%
\noexpand\textbf{\noexpand\ttMANU}%
}%
}%
}
\makeatother
\begin{document}
\def\tA {AA}
\def\tB {BB}
\createCMDMANUV{\tA}{\tB}
\AABB{}
\AABB{aa}
\end{document}
\def\widthCATIA{...}
is only in the local group if\ifdefempty
... Please provide a complete example, not just fragments. And I think, you should rather use\ifcsempty
, not\ifdefempty
, but it's unclear to me\widthCATIA
, in my point of view\widthCATIA
when I call the final macro.width
value it still sees a macro but not its expansion.