1

I have read a bunch of pages about "Macro parameters in horizontal mode" but have no idea what it means.

It is preventing me, though from compiling the following. I've read it over and fiddled with it a whole bunch, but it just seems similar to many other files I've made that work just fine.

What's going on?

\documentclass{article}

\usepackage{pgf}
\usepackage{pgffor}

\pgfmathsetseed{\number\pdfrandomseed}

\newcommand{\InitVariables}
{%
\pgfmathsetmacro{\A}{int(random(0,10))}
\pgfmathsetmacro{\B}{int(10-\A)}
\pgfmathsetmacro{\C}{int(\A+\B)}
\pgfmathsetmacro{\D}{int(random(0,9))}
\pgfmathsetmacro{\E}{int(9-\D)}
\pgfmathsetmacro{\F}{int(\D+\E)}
\pgfmathsetmacro{\r}{int(1,6)}
}

\newcommand{\Variables}
{%
\InitVariables

\A

\B

\C

\D

\E

\F
}

\begin{document}

\Variables

\end{document}
3

LaTeX predefines \r. Don't use one letter macro names unless you're sure that they aren't defined. Don't use a macro name as argument to \pgfmathsetmacro unless you know that it is free1

1 If you are using \pgfmathsetmacro inside a \foreach cycle, then there's little to worry about, as each cycle is performed in a group and values will be restored at the end of the group.

The error can be reproduced with

\documentclass{article}

\usepackage{pgf}

\begin{document}

\pgfmathsetmacro{\r}{int(1,6)}

\end{document}

The same happens whenever the argument to \pgfmathsetmacro is an already existing macro defined with \DeclareRobustCommand (or equivalent method).

|improve this answer|||||
  • Got it... I didn't know that creating arguments called \r was a problem outside of \foreach loops. Thanks! – WeCanLearnAnything Jan 12 '17 at 17:33

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.