TransWikia.com

Use number as argument for command

TeX - LaTeX Asked by LightninBolt74 on July 5, 2021

I am unable to use a number as a parameter for a command that I have defined.

The command takes 5 numerical inputs and returns a single number.

documentclass{standalone}

usepackage{tikz}

newcommand{rotateX}[5]{pgfmathparse{cos({#5})*({#1}-{#3})-sin({#5})({#2}-{#4})+{#3}}pgfmathresult}

begin{document}
    rotateX{-0.5}{3.5}{-2}{1}{40}
end{document}

However, once the engine reaches the rotateX command it gives the error Illegal unit of measure (pt inserted)

Do I need to do something extra in order for LaTeX to recognise that the arguments are numbers?

Edit:
Note that the following works on its own, the issue is with the variables that get passed to the command.

pgfmathparse{cos(40)*(-0.5--2)-sin(40)(3.5-1)+-2}pgfmathresult

Edit 2: (Using David Carlisle’s suggestion)

documentclass{standalone}

usepackage{tikz}

newcommand{rotateX}[5]{pgfmathparse{cos(#5)*(#1-#3)-sin(#5)(#2-#4)+#3}pgfmathresult}

begin{document}
    rotateX{-0.5}{3.5}{-2}{1}{40}
end{document}

gives the following:
Output of code

2 Answers

You just need to remove the spurious brace groups

enter image description here

documentclass{article}

usepackage{tikz}

newcommand{rotateX}[5]{pgfmathparse{cos(#5)*(#1-#3)-sin(#5)(#2-#4)+#3}pgfmathresult}

begin{document}
pgfmathparse{cos(40)*(-0.5--2)-sin(40)(3.5-1)+-2}pgfmathresult

rotateX{-0.5}{3.5}{-2}{1}{40}
end{document}

This is unrelated to the macro definition, pgfmathparse{cos({40})... would give the same error.

Correct answer by David Carlisle on July 5, 2021

The problem was not related to the question

The issue was a missed * between brackets xD!

Working solution: (thanks David for partial help!)

documentclass{standalone}

usepackage{tikz}

newcommand{rotateX}[5]{pgfmathparse{cos(#5)*(#1-#3)-sin(#5)*(#2-#4)+#3}pgfmathresult}
                                                              ^
begin{document}                                              |
    rotateX{-0.5}{3.5}{-2}{1}{40}
end{document}

Answered by LightninBolt74 on July 5, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP