Real operations in LaTex

Viewed 63

This is a piece of my code.

\newcommand{\number}{2}
\number + 2

Is there any way that a '4' is written instead a '2+2'? (LaTex does the real operation).

Thanks

1 Answers

There are many possibilities to do calculations in latex. Just one option is pgfmath:

\documentclass{article}

\usepackage{tikz}

\begin{document}
    
\newcommand{\mynumber}{2}
\pgfmathparse{\mynumber+2}

\pgfmathresult

    
\end{document}
Related