0

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}
  • Try \noexpand\large? – Hood Chatham Nov 01 '17 at 03:10
  • 1
    you should never use \xdef on latex input, that's why latex has \protected@xdef – David Carlisle Nov 01 '17 at 07:57
  • 1
    how hard can it be to make a MWE? here is one: \documentclass{article}\begin{document}\edef\zz{\large}\end{document} – David Carlisle Nov 01 '17 at 07:59
  • I think I've already warned you about \xdef. – egreg Nov 01 '17 at 10:06
  • https://tex.stackexchange.com/questions/397121/solutions-will-not-compile#comment987967_397121 – David Carlisle Nov 01 '17 at 13:22
  • @egreg It has been quite hard for me to understand some of the warnings because I don't really know what the word "expand" means and haven't found a definitions or explanations that strike me as anything other than incomprehensible jargon. I'm still pretty confused by all the different ways to define and redefine things in LaTeX; I'm baffled as to why more than one way (an equals sign in Python, for example) is necessary. – WeCanLearnAnything Nov 01 '17 at 16:20
  • @DavidCarlisle, I tried \protected@xdef, but it doesn't compile. It says I can't use the character @. I also have no idea what protected actually means. – WeCanLearnAnything Nov 01 '17 at 16:22
  • you need to use \makeatletter to use commands with @ in their name – David Carlisle Nov 01 '17 at 16:32
  • @DavidCarlisle "how hard can it be to make a MWE? here is one:..." Actually, it can be quite hard for people who haven't mastered LaTeX. I'm trying to create a MWE that isolates the problem of font sizes within TikZ within \xdef and 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
  • it's hardly true that you can define everything in python with just an = function definitions, arrays .... each construct needs a specific definition form, as in most languages – David Carlisle Nov 01 '17 at 16:34
  • you should not be using xdef, as stated in comments to your previous question. tikz is not relevant to the error. – David Carlisle Nov 01 '17 at 16:36
  • When the definition is question is changed to a simple \def it compiles. What is wrong with that result, for example? – Steven B. Segletes Nov 01 '17 at 16:59
  • @StevenB.Segletes I used \xdef because I've used it before. I'm not really sure what it does. In response to your suggestion, I changed \xdef to \def in the link and it compiles and the exercises appear but the solutions do not. – WeCanLearnAnything Nov 01 '17 at 17:16
  • @WeCanLearnAnything There are so many things that break with \xdef that's quite hard to suggest a workaround. – egreg Nov 01 '17 at 17:29
  • @ egreg , So what should I use instead of \xdef to make my solution page? I've tried everything from these comments: \noexpand\large, \make@letter and \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

0 Answers0