SHARE
TWEET

Untitled

a guest Mar 15th, 2018 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. \documentclass{article}
  2.  
  3. \usepackage{xfp,etoolbox}
  4.  
  5. \newcommand{\newreg}[1]{\csdef{reg-#1}{}}
  6. \newcommand{\setreg}[2]{\csedef{reg-#1}{\fpeval{#2}}}
  7. \newcommand{\addreg}[2]{\csedef{reg-#1}{\fpeval{\csuse{reg-#1} + #2}}}
  8. \newcommand{\valuereg}[1]{\csuse{reg-#1}}
  9.  
  10. \begin{document}
  11.  
  12. \newreg{myx}
  13. \setreg{myx}{0.0}
  14. \addreg{myx}{0.5}
  15. \addreg{myx}{-0.25}
  16. \valuereg{myx} % this expands to 0.25 (0 + 0.5 - 0.25)
  17.  
  18. \newreg{abc}
  19. \setreg{abc}{-2 + 3.1}
  20. \addreg{abc}{5.1 - 1}
  21. \valuereg{abc} % this expands to 5.2 (-2 + 3.1 + 5.1 - 1)
  22.  
  23. \setreg{def}{1 + 2 + 3 + 4} % 10
  24. \addreg{def}{\valuereg{def} + 10} % Add 20 (10+10) = 30
  25. \valuereg{def} % 30
  26.  
  27. \end{document}
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top