Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.
\pgfkeys{/pgf/fpu} 

\pgfmathsetlengthmacro\x{5^2}
\show\x -> 25.0pt % OK, thanks.

\pgfmathparse{5cm^2}
  1. What is the meaning of ] in the following?

    \show\pgfmathresult % ->1Y2.0238983e4].
    
    \pgfkeys{/pgf/fpu/output format=sci}
    

    gives the expected format, but what is the cryptic ]?

  2. Why does this fail? Is unit not allowed in {<expr>}? The manual says \pgfmathsetlengthmacro "defines <macro> as the value of <expression> in points."

    \pgfmathsetlengthmacro\y{5cm^2} % ! Illegal unit.
    \pgfmathsetlengthmacro\y{5^2cm} % ! Illegal unit.
    \show\y
    

EDIT

Here is a minimal example:

\documentclass{article}
\usepackage{pgfplots}

\begin{document}
\pgfkeys{/pgf/fpu}
\pgfkeys{/pgf/fpu/output format=sci}
\pgfmathparse{5cm^2}
%\show\pgfmathresult % -> 2.0238983e4.

% Both of these give error:
\pgfmathsetlengthmacro\x{5mm^2}
\pgfmathsetlengthmacro\x{5^2}

\pgfkeys{/pgf/fpu=false}

\end{document}

Error msg:

! Illegal unit of measure (pt inserted).
<to be read again>
                   e
l.10 \pgfmathsetlengthmacro\x{5mm^2}
share|improve this question
    
Wouldn't a MWE help? You know which packages you're loading, we don't. I get an error from the first \pgfmathsetlengthmacro call. –  egreg Oct 1 '12 at 14:53
2  
This is related to the internal number represantation of the fpu library and I think ] is doing something similar to \relax. You have to use \pgfmathprintnumber to convert it to the human-readable form. –  percusse Oct 1 '12 at 14:56
    
I get ! Dimension too large. for both of the examples in part 2, probably because 5 cm comes out 'too big' in pt. –  Joseph Wright Oct 1 '12 at 15:09
add comment

1 Answer

up vote 7 down vote accepted

The 1Y2.0238983e4] is the internal representation of the number. With fpu you have to explicitly specify the output format or use \pgfmathfloattofixed. The default format is float (with Y and ]), \pgfmathsetlengthmacro is not changed by the fpu library, thus the length is not a valid TeX length with format float. Examples:

\documentclass{article}
\usepackage{pgf}
\usepgflibrary{fpu}

\begingroup
  \pgfkeys{/pgf/fpu,/pgf/fpu/output format=fixed}
  \pgfmathsetlengthmacro\x{5^2}
  \typeout{\x}
\endgroup

\begingroup
  \pgfkeys{/pgf/fpu}
  \pgfmathparse{5^2}
  \pgfmathfloattofixed{\pgfmathresult}
  \edef\x{\pgfmathresult pt}
  \typeout{\x}
\endgroup

\begingroup
  \pgfkeys{/pgf/fpu,/pgf/fpu/output format=fixed}
  \pgfmathparse{5cm^2}
  \typeout{\pgfmathresult}
\endgroup

\begin{document}
\end{document}

Result:

25.0pt
25.000000000pt
20238.983000000000

More details in 36 Floating Point Unit Library.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.