2

Is there any way to store real numbers (e.g. 4.5) as variable / macro / counter / whatever in standard LaTeX (no direct Lua code) and perform the 4 basic mathematical operations with them? I need to be able to store such numbers and perform repeated calculations on them, at different points in my code (not just once).

I've considered storing the numbers as lengths (say multiplied by 100pt) but I am stuck at recovering the underlying numbers (to actually use them to multiply other lengths...).

Bonus point if you minimize the number of external packages required. As for everything TeX, I am pretty sure someone will come up with a way to do this with tikz :)

lockstep
  • 250,273
Xavier
  • 13,947
  • There are various solutions depending on the detail of your requirements. Assuming e-TeX and 'simple' calculations, using dimensions and stripping off the pt is probably 'lowest' cost (no packages). On the other hand, clearer solutions involving either fp, pgfmath or the expandable l3fp are all also available. – Joseph Wright Feb 06 '13 at 08:58
  • You might want to look at for example Floating point calculations in LaTeX? – Joseph Wright Feb 06 '13 at 08:58
  • @JosephWright Thanks for the link! I searched a bit but hadn't seen that question. Please feel free to close mine as a duplicate. Ah, and there is some pgf / tikz answer :) – Xavier Feb 06 '13 at 09:28
  • I just discovered another option for simple calculations: use lenghts and the \real and \ratio macros of the calc package. – Xavier Feb 07 '13 at 19:31

0 Answers0