3

Following the Latex wiki page I tried \newcommand and \DeclareRobustCommand:

\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}

\newcommand{\marginProportion}{0.76}   
\usepackage[scale=\marginProportion{}]{geometry} 

\begin{document}


\end{document}

Both of which cause a myriad of compilation errors.

3
  • 3
    scale=\marginProportion should work, but not scale=\marginProportion{}. \DeclareRobustCommand does not work since it's not expandable
    – user31729
    Mar 17, 2015 at 7:53
  • 1
    The key-value syntax does not expand the key value \marginProportion, just copies content and in the case of \marginProporption{} it adds content to the value which shouldn't be there (the {} pair)
    – user31729
    Mar 17, 2015 at 7:57
  • 1
    It has to be added, from my point of view, that the {} issue is actually not limited to a 'numerical' variable
    – user31729
    Mar 17, 2015 at 13:07

1 Answer 1

4

Key-value approaches (often) do not expand the key values.

In this case scale=\marginProportion{} will just be copied, as can be shown from the verbatim output of \typeout of the dummykey definition. The second call with trailing {} will just have those {} as key value, conflicting with the expected input for the scale key from geometry package.

\documentclass[a4paper,10pt]{article} 
\usepackage[utf8]{inputenc}

\usepackage{xkeyval}

\makeatletter
\define@key{fam}{dummykey}{%
  \def\FamKVMacroDummy{#1}
  \typeout{#1}
}%

\makeatother


\newcommand{\somecmd}[1]{%
  \setkeys{fam}{#1}
Printing the key value:  \FamKVMacroDummy
}

\newcommand{\marginProportion}{0.76}
\usepackage[scale=\marginProportion]{geometry}

\begin{document}

\somecmd{dummykey=\marginProportion}

\somecmd{dummykey=\marginProportion{}}

\end{document}


./numvar.aux)
*geometry* driver: auto-detecting
*geometry* detected driver: pdftex
0.76
0.76{}
[1{/usr/local/texlive/2014/texmf-var/fonts/map/pdftex/updmap/pdftex.map}]
(./numvar.aux) )</usr/local/texlive/2014/texmf-dist/fonts/type1/public/amsfonts
/cm/cmr10.pfb>
Output written on numvar.pdf (1 page, 13994 bytes).
Transcript written on numvar.log.

\DeclareRobustCommand will not expand to 0.76 so this is useless here, as well as \newrobustcmd from etoolbox.

1
  • 1
    Such a great answer! Also, thank you for showing me that "debugging" technique! Mar 17, 2015 at 9:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .