I am not able to compile the following document with pdflatex.
\documentclass{article}
\usepackage{graphicx}
\NewDocumentCommand{\logoscale}{}{0.3}
%\newcommand{\logoscale}{0.3} <---- works with this
\NewDocumentCommand{\mylogo}{}%
{\includegraphics[scale=\logoscale]{example-image-a}}
\begin{document}
\mylogo
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy
eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam
voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet
clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit
amet.
\end{document}
On compiling, I get the following error:
./x.tex:21: pdfTeX error (\pdfsetmatrix): Unrecognized format..
<argument> ...shipout:D \box_use:N \l_shipout_box
\__shipout_drop_firstpage_...
l.21 \end{document}
The same document compiles if I use newcommand. I need some help in understanding where the problem is.
\NewExpandableDocumentCommand{\logoscale}{}{0.3}\New...macros.\defmyself because it is the simplest solution. However, it is not without problems, the biggest one is that you can easily overwrite an earlier defined macro unintentionally because (La)TeX doesn't warn about redefinitions with\def.\includegraphics. However, the expansion problem and its solution are actually the same.graphicxuses\edefinternally when processingscale. And there\logoscaleis not expanded, because\NewDocumentCommanddefines it protected. And in another context,graphicxuses the argument ofscaleas a prefix factor to a length. This also needs an expandable macro. So expansion is the problem.