Text Formattingsiunitx | Calculated Value in physical Quantities

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

siunitx | Calculated Value in physical Quantities

Post by svend_tveskaeg »

Hi all.

Consider the following MWE:

Code: Select all

\documentclass{article}

\usepackage{siunitx}
\usepackage{auto-pst-pdf,pstricks-add}

\begin{document}

\begin{figure}
\def\minimum{0 }
\def\maximum{10 }
\def\difference{\maximum \minimum sub }
 \centering
  \begin{pspicture}(\maximum,\maximum)
   \pnode(!\minimum \minimum){A}
   \pnode(!\minimum \maximum){B}
   \pnode(!\maximum \maximum){C}
   \pnode(!\maximum \minimum){D}
   \pspolygon(A)(B)(C)(D)
   \psarc(!\maximum \minimum){!\difference}{90}{180}
   \psarc(!\minimum \maximum){!\difference}{270}{360}
  \psset{offset=12pt,nrot=:U}
   \pcline{|-|}(B)(C)
   \ncput*{\SI{\maximum}{\centi\meter}}
   \pcline{|-|}(C)(D)
   \ncput*{\SI{\maximum}{\centi\meter}}
  \end{pspicture}
\end{figure}

\end{document}
I would like to replace

Code: Select all

\pcline{|-|}(B)(C)
\ncput*{\SI{\maximum}{\centi\meter}}
\pcline{|-|}(C)(D)
\ncput*{\SI{\maximum}{\centi\meter}}
with something like

Code: Select all

\pcline{|-|}(B)(C)
\ncput*{\SI{\difference}{\centi\meter}}
\pcline{|-|}(C)(D)
\ncput*{\SI{\difference}{\centi\meter}}
but I am not allowed to do this.

If it is possible, how do I do this?

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.

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

siunitx | Calculated Value in physical Quantities

Post by localghost »

You can't use postscript notation in the siunitx commands. The package does not understand this. You will need something else (untested).

Code: Select all

\SI{\numexpr\maximum-\minimum}{\cm}

Thorsten
User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

Re: siunitx | Calculated Value in physical Quantities

Post by svend_tveskaeg »

I see!

When I apply your suggested code it compiles just fine but nothing is printed.
``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

siunitx | Calculated Value in physical Quantities

Post by cgnieder »

svend_tveskaeg wrote:When I apply your suggested code it compiles just fine but nothing is printed.
Really? I get

Code: Select all

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! siunitx error: "invalid-number"
! 
! Invalid numerical input '\numexpr 10 -0 '.
! 
! See the siunitx documentation for further information.
! 
! For immediate help type H <return>.
!...............................................
But this works:

Code: Select all

\SI{\the\numexpr\maximum-\minimum}{\centi\meter}
or

Code: Select all

\def\difference{\the\numexpr\maximum-\minimum\relax}
and then

Code: Select all

\SI{\difference}{\centi\meter}
Regards
site moderator & package author
User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

siunitx | Calculated Value in physical Quantities

Post by svend_tveskaeg »

cgnieder wrote:Really?
Yes. See the log file.
cgnieder wrote:But this works:

Code: Select all

\SI{\the\numexpr\maximum-\minimum}{\centi\meter}
or

Code: Select all

\def\difference{\the\numexpr\maximum-\minimum\relax}
and then

Code: Select all

\SI{\difference}{\centi\meter}
Nice.

Thank you, Clemens.
Attachments
test2.log
Log file.
(28.7 KiB) Downloaded 294 times
``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)
Post Reply