I need both \large and \huge fonts inside of TikZ diagrams for an exercise for kids to learn that, say, adding a negative is the same as subtracting a positive.
Unfortunately, the font size commands don't seem to survive the \xdef command in which they're placed.
I'm trying to create a MWE and having a horrible time doing it... Can anyone answer this question without an MWE? I'll keep working on the MWE until/unless someone can figure this out...
EDIT: This isn't really a minimum working example, but it has the bug...
I included \makeatletter and \protected@xdef as recommended in the comments.
https://www.sharelatex.com/project/59f9f7ad53d7fe35b052e16b
EDIT 2: I think I may have isolated the problem in my new thread.
OR
\documentclass{article}
\usepackage[margin=2cm]{geometry}
\usepackage{pgffor}
\pgfmathsetseed{\number\pdfrandomseed}
\usepackage{tikz}
%BLANK VARIABLE STUFF
\newcommand{\Operator}{}
\newcommand{\Sign}{}
\newcommand{\Simplified}{}
\newcommand{\InitVariables}
{%
\pgfmathrandominteger{\Type}{1}{4}
\ifcase\Type\relax
\or \renewcommand{\Operator}{+}
\renewcommand{\Sign}{+}
\renewcommand{\Simplified}{+}
\or \renewcommand{\Operator}{+}
\renewcommand{\Sign}{-}
\renewcommand{\Simplified}{-}
\or \renewcommand{\Operator}{-}
\renewcommand{\Sign}{+}
\renewcommand{\Simplified}{-}
\or \renewcommand{\Operator}{-}
\renewcommand{\Sign}{-}
\renewcommand{\Simplified}{+}
\fi
\pgfmathrandominteger{\Magnitude}{1}{20}
\pgfmathrandominteger{\MagnitudeWithZero}{0}{20}
\pgfmathsetmacro{\NegativeMagnitudeWithZero}{int(-1*\MagnitudeWithZero)}
\pgfmathrandominteger{\VariedSignAndBracketType}{1}{16}
}
\newcommand{\fewer}
{\draw[blue] (-2.2,-1) rectangle( -1.1,-1.6);}
\newcommand{\more}
{\draw[blue] (-2.2,-1) rectangle (-1.1,-0.5);}
\newcommand{\gains}
{\draw[blue] (-1,-1) rectangle (0.2,-0.5);}
\newcommand{\losses}
{\draw[blue] (-1,-1) rectangle (0.2,-1.6);}
\newcommand{\good}
{\draw[blue] (1.2,-1) rectangle (2.3,-0.5);}
\newcommand{\bad}
{\draw[blue] (1.2,-1) rectangle (2.3,-1.6);}
%MORE BLANK VARIABLE STUFF
\newcommand{\TwoSignsExercise}{}
\newcommand{\TwoSignsSolution}{}
\newcommand{\TwoSignsGenerator}
{%
\InitVariables
\renewcommand{\TwoSignsExercise}
{%
\begin{tikzpicture}
\node[anchor=center] at (-1.35,0) {\huge $\Operator$};
\node[anchor=center] at (0,0) {\huge $(\Sign)=$};
\draw[dashed, thick] (1.3,-0.4) rectangle (2.3,0.6);
\node[anchor=center] at (-1.6,-0.8) {\large more};
\node[anchor=center] at (-1.6,-1.3) {\large fewer};
\node[anchor=center] at (-0.4,-0.8) {\large gains};
\node[anchor=center] at (-0.4,-1.3) {\large losses};
\node[anchor=center] at (0.6,-1.05) {\large is};
\node[anchor=center] at (1.8,-0.8) {\large good};
\node[anchor=center] at (1.8,-1.3) {\large bad};
\end{tikzpicture}
}
%
\renewcommand{\TwoSignsSolution}
{%
\begin{tikzpicture}
\ifcase\Type\relax
\or \more \gains \good
\or \more \losses \bad
\or \fewer \gains \bad
\or \fewer \losses \good
\fi
\node[anchor=center] at (-1.35,0) {\huge $\Operator$};
\node[anchor=center] at (0,0) {\huge $(\Sign)=$};
\draw[dashed, thick] (1.3,-0.4) rectangle (2.3,0.6);
\node[anchor=center, blue] at (1.8,0) {\huge {$\Simplified$}};
\node[anchor=center] at (-1.6,-0.8) {\large more};
\node[anchor=center] at (-1.6,-1.3) {\large fewer};
\node[anchor=center] at (-0.4,-0.8) {\large gains};
\node[anchor=center] at (-0.4,-1.3) {\large losses};
\node[anchor=center] at (0.6,-1.05) {\large is};
\node[anchor=center] at (1.8,-0.8) {\large good};
\node[anchor=center] at (1.8,-1.3) {\large bad};
\end{tikzpicture}
}
}
\makeatletter
\newcommand{\ManyTwoSignsSolutions}{}
\newcommand{\ManyTwoSignsExercises}
{%
\foreach \x in {1,...,10}
{%
\TwoSignsGenerator \TwoSignsExercise \vskip 0.25cm
\protected@xdef\ManyTwoSignsSolutions{\ManyTwoSignsSolutions \TwoSignsSolution}
}
}
\setlength{\parindent}{0em}
\begin{document}
\section*{Exercises}
\ManyTwoSignsExercises
\section*{Solutions}
\ManyTwoSignsSolutions
\end{document}
\noexpand\large? – Hood Chatham Nov 01 '17 at 03:10\xdefon latex input, that's why latex has\protected@xdef– David Carlisle Nov 01 '17 at 07:57\documentclass{article}\begin{document}\edef\zz{\large}\end{document}– David Carlisle Nov 01 '17 at 07:59\xdef. – egreg Nov 01 '17 at 10:06\protected@xdef, but it doesn't compile. It says I can't use the character@. I also have no idea whatprotectedactually means. – WeCanLearnAnything Nov 01 '17 at 16:22\makeatletterto use commands with@in their name – David Carlisle Nov 01 '17 at 16:32TikZwithin\xdefand it seems that there are new problems in my MWE attempts... so I haven't posted it yet. – WeCanLearnAnything Nov 01 '17 at 16:33=function definitions, arrays .... each construct needs a specific definition form, as in most languages – David Carlisle Nov 01 '17 at 16:34\defit compiles. What is wrong with that result, for example? – Steven B. Segletes Nov 01 '17 at 16:59\xdefbecause I've used it before. I'm not really sure what it does. In response to your suggestion, I changed\xdefto\defin the link and it compiles and the exercises appear but the solutions do not. – WeCanLearnAnything Nov 01 '17 at 17:16\xdefthat's quite hard to suggest a workaround. – egreg Nov 01 '17 at 17:29\xdefto make my solution page? I've tried everything from these comments:\noexpand\large,\make@letterand\protected@xdef,\def, etc. and nothing has worked. Am I better off just learn a completely different computer language if I want solutions pages? LaTeX seems to give me problems about 80% of the time and I've found no simple explanation as to why. – WeCanLearnAnything Nov 01 '17 at 22:36