Text FormattingDefinition of non-trivial numerical Values (again)

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

Definition of non-trivial numerical Values (again)

Post by svend_tveskaeg »

Hi all.

The following MWE is inspired by Clemens' answer in this thread.

Well, here is the test code:

Code: Select all

\documentclass{article}

\usepackage{auto-pst-pdf,pstricks-add}
\usepackage[locale=DE,round-mode=places,round-precision=1]{siunitx}
\usepackage{expl3}

\ExplSyntaxOn
\cs_new_eq:NN \calculate \fp_eval:n
\ExplSyntaxOff

\begin{document}

\begin{figure}
\def\factor{1.2 }
\def\Cx{0 }
\def\Cy{0 }
\def\Bx{\Cx 11.5 \factor mul add }
\def\By{\Cy }
\def\Ax{\Cx 11.63521739130435 \factor mul add }
\def\Ay{\Cy 5.798423601039239 \factor mul add }
\def\Dx{\Cx 0.705044815592284 \factor mul add }
\def\Dy{\Cy 9.373521846563673 \factor mul add }
\def\CD{\calculate{((\Cx-\Dx)^2+(\Cy-\Dy)^2)^(1/2)}}
 \centering
  \begin{pspicture}(14,11.25)
  \psset{unit=0.8cm,nrot=:U}
   \pnode(!\Ax \Ay){A}
   \pnode(!\Bx \By){B}
   \pnode(!\Cx \Cy){C}
   \pnode(!\Dx \Dy){D}
   \pspolygon(A)(B)(C)(D)
   \uput{3pt}[60](A){$A$}
   \uput{3pt}[315](B){$B$}
   \uput{3pt}[225](C){$C$}
   \uput{3pt}[135](D){$D$}
   \pcline{-}(C)(A)
   \naput{\SI{13.0}{\cm}}
   \pcline{-}(C)(D)
   \naput{\SI{\CD}{\cm}}
   \pcline{-}(D)(A)
   \naput{\SI{11.5}{\cm}}
   \pcline{-}(C)(B)
   \naput{\SI{11.5}{\cm}}
   \pcline{-}(B)(A)
   \naput{\SI{5.8}{\cm}}
  \end{pspicture}
\end{figure}

\end{document}
Why in the number in \SI at the node \naput between the nodes C and D printed as 0? I cannot understand why my definition of \CD is wrong.

Thank you in advance!
``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Re: Definition of non-trivial numerical Values (again)

Post by cgnieder »

You're mixing two ways of calculating. I would either use l3fp or the postscript way.

Regards
site moderator & package author
User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

Definition of non-trivial numerical Values (again)

Post by svend_tveskaeg »

cgnieder wrote:You're mixing two ways of calculating.
Good point! I will remember this.

But... then why is the following not working?

Code: Select all

\documentclass{article}

\usepackage{auto-pst-pdf,pstricks-add}
\usepackage[locale=DE,round-mode=places,round-precision=1]{siunitx}
\usepackage{expl3}

\ExplSyntaxOn
\cs_new_eq:NN \calculate \fp_eval:n
\ExplSyntaxOff

\begin{document}

\begin{figure}
\def\factor{1.2 }
\def\Cx{0 }
\def\Cy{0 }
\def\Bx{\calculate{\Cx+11.5*\factor}}
\def\By{\Cy }
\def\Ax{\calculate{\Cx+11.63521739130435*\factor}}
\def\Ay{\calculate{\Cy+5.798423601039239*\factor}}
\def\Dx{\calculate{\Cx+0.705044815592284*\factor}}
\def\Dy{\calculate{\Cy+9.373521846563673*\factor}}
\def\CD{\calculate{((\Cx-\Dx)^2+(\Cy-\Dy)^2)^(1/2)}}
 \centering
  \begin{pspicture}(14,11.25)
  \psset{unit=0.8cm,nrot=:U}
   \pnode(!\Ax \Ay){A}
   \pnode(!\Bx \By){B}
   \pnode(!\Cx \Cy){C}
   \pnode(!\Dx \Dy){D}
   \pspolygon(A)(B)(C)(D)
   \uput{3pt}[60](A){$A$}
   \uput{3pt}[315](B){$B$}
   \uput{3pt}[225](C){$C$}
   \uput{3pt}[135](D){$D$}
   \pcline{-}(C)(A)
   \naput{\SI{13.0}{\cm}}
   \pcline{-}(C)(D)
   \naput{\SI{\CD}{\cm}}
   \pcline{-}(D)(A)
   \naput{\SI{11.5}{\cm}}
   \pcline{-}(C)(B)
   \naput{\SI{11.5}{\cm}}
   \pcline{-}(B)(A)
   \naput{\SI{5.8}{\cm}}
  \end{pspicture}
\end{figure}

\end{document}
Now, nothing is printed at all. :(

I am now sticking to one type of notation (I think).
``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Definition of non-trivial numerical Values (again)

Post by cgnieder »

I don't really know... are you sure about the scaling? It seems to print everything at nearly the same place. The calculations are working:

Code: Select all

\documentclass{article}
\usepackage{expl3}

\ExplSyntaxOn
\cs_new_eq:NN \calculate \fp_eval:n
\ExplSyntaxOff

\begin{document}


\ttfamily\noindent
\def\factor{1.2 }%
\def\Cx{0 }%
\def\Cy{0 }%
\def\Bx{\calculate{\Cx+11.5*\factor}}Bx: \Bx \\
\def\By{\Cy}By: \By \\
\def\Ax{\calculate{\Cx+11.63521739130435*\factor}}Ax: \Ax \\
\def\Ay{\calculate{\Cy+5.798423601039239*\factor}}Ay: \Ay \\
\def\Dx{\calculate{\Cx+0.705044815592284*\factor}}Dx: \Dx \\
\def\Dy{\calculate{\Cy+9.373521846563673*\factor}}Dy: \Dy \\
\def\CD{\calculate{((\Cx-\Dx)^2+(\Cy-\Dy)^2)^(1/2)}}CD: \CD

\end{document}
site moderator & package author
User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

Definition of non-trivial numerical Values (again)

Post by svend_tveskaeg »

The scaling is for something else; not related to this. ;)

When I compile the following MWE, the values are (of course) printed, but the PS figure is not.

Code: Select all

\documentclass{article}

\usepackage{auto-pst-pdf,pstricks-add}
\usepackage[locale=DE,round-mode=places,round-precision=1]{siunitx}
\usepackage{expl3}

\ExplSyntaxOn
\cs_new_eq:NN \calculate \fp_eval:n
\ExplSyntaxOff

\begin{document}

\ttfamily\noindent
\def\factor{1.2 }%
\def\Cx{0 }%
\def\Cy{0 }%
\def\Bx{\calculate{\Cx+11.5*\factor}}Bx: \Bx \\
\def\By{\Cy}By: \By \\
\def\Ax{\calculate{\Cx+11.63521739130435*\factor}}Ax: \Ax \\
\def\Ay{\calculate{\Cy+5.798423601039239*\factor}}Ay: \Ay \\
\def\Dx{\calculate{\Cx+0.705044815592284*\factor}}Dx: \Dx \\
\def\Dy{\calculate{\Cy+9.373521846563673*\factor}}Dy: \Dy \\
\def\AB{\calculate{((\Ax-\Bx)^2+(\Ay-\By)^2)^(1/2)}}AB: \AB \\
\def\AD{\calculate{((\Ax-\Dx)^2+(\Ay-\Dy)^2)^(1/2)}}AD: \AD \\
\def\CA{\calculate{((\Cx-\Ax)^2+(\Cy-\Ay)^2)^(1/2)}}CA: \CA \\
\def\CB{\calculate{((\Cx-\Bx)^2+(\Cy-\By)^2)^(1/2)}}CB: \CB \\
\def\CD{\calculate{((\Cx-\Dx)^2+(\Cy-\Dy)^2)^(1/2)}}CD: \CD

\begin{figure}
 \centering
  \begin{pspicture}(14,11.25)
  \psset{unit=0.8cm,nrot=:U}
   \pnode(!\Ax \Ay){A}
   \pnode(!\Bx \By){B}
   \pnode(!\Cx \Cy){C}
   \pnode(!\Dx \Dy){D}
   \pspolygon(A)(B)(C)(D)
   \uput{3pt}[60](A){$A$}
   \uput{3pt}[315](B){$B$}
   \uput{3pt}[225](C){$C$}
   \uput{3pt}[135](D){$D$}
   \pcline{-}(C)(A)
   \naput{\SI{\CA}{\cm}}
   \pcline{-}(C)(D)
   \naput{\SI{\CD}{\cm}}
   \pcline{-}(A)(D)
   \naput{\SI{\AD}{\cm}}
   \pcline{-}(C)(B)
   \naput{\SI{\CB}{\cm}}
   \pcline{-}(B)(A)
   \naput{\SI{\AB}{\cm}}
  \end{pspicture}
\end{figure}

\end{document}
I have attached the log file.

Is the figure printed when you compile?
Attachments
test.log
Log file.
(28.9 KiB) Downloaded 421 times
``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)
CrazyHorse
Posts: 351
Joined: Sat Aug 02, 2008 8:47 am

Definition of non-trivial numerical Values (again)

Post by CrazyHorse »

svend_tveskaeg wrote:The scaling is for something else; not related to this. ;)

When I compile the following MWE, the values are (of course) printed, but the PS figure is not.

Is the figure printed when you compile?
the spaces are missing:

Code: Select all

\def\factor{1.2 }%
\def\Cx{0 }%
\def\Cy{0 }%
\def\Bx{\calculate{\Cx+11.5*\factor} }Bx: \Bx \\
\def\By{\Cy }By: \By \\
\def\Ax{\calculate{\Cx+11.63521739130435*\factor} }Ax: \Ax \\
\def\Ay{\calculate{\Cy+5.798423601039239*\factor} }Ay: \Ay \\
\def\Dx{\calculate{\Cx+0.705044815592284*\factor} }Dx: \Dx \\
\def\Dy{\calculate{\Cy+9.373521846563673*\factor} }Dy: \Dy \\
\def\AB{\calculate{((\Ax-\Bx)^2+(\Ay-\By)^2)^(1/2)} }AB: \AB \\
\def\AD{\calculate{((\Ax-\Dx)^2+(\Ay-\Dy)^2)^(1/2)} }AD: \AD \\
\def\CA{\calculate{((\Cx-\Ax)^2+(\Cy-\Ay)^2)^(1/2)} }CA: \CA \\
\def\CB{\calculate{((\Cx-\Bx)^2+(\Cy-\By)^2)^(1/2)} }CB: \CB \\
\def\CD{\calculate{((\Cx-\Dx)^2+(\Cy-\Dy)^2)^(1/2)} }CD: \CD
User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

Re: Definition of non-trivial numerical Values (again)

Post by svend_tveskaeg »

You are kidding me. How blind can one be. :oops:

Thank you to both of you for helping me!
``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)
Post Reply