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}
You just need to remove the spurious brace groups
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
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP