[Tex/LaTex] Define numeric variable in terms of another variable

automationvariable

So, I have a variable called number which I define like so:

\def\number{0.25}

I'd like to automatically define a number which will give me 1-number (in this case, which would give me 0.75). I tried doing this:

\def\othernumber{1-\number}

However, this didn't seem to work. It seems like the engine doesn't realize that I want to subtract \number from 1. Could anyone help me fix this syntax? Thanks 🙂

Best Answer

You can use pgf package for this. Instead TeX primitive \def one need use \pgfmathsetmacro

\documentclass{article}
\usepackage{pgf}

\begin{document}
\pgfmathsetmacro{\first}{0.25}
\pgfmathsetmacro{\second}{1-\first}

The value of \verb|\first| is \first

The value of \verb|\second| is \second
\end{document}

enter image description here

Related Question