numerica 包是解决电路方程的非常方便的工具,但我找不到使用 mA、kV 等工程倍数来获取数值结果的方法。siunitx 包有一个非常好的解决方案,如下所示,但我无法在管道中获取这两个包,因为宏扩展最初不是一个简单的文本结果。
\documentclass{article}
\usepackage{amssymb} %maths
\usepackage{amsmath} %maths
\usepackage{physics} % before numerica!!!
\usepackage{numerica} % computation of math expressions
\def\eval{\nmcEvaluate} % to simplify numerica avoiding conflict with physics
\usepackage{siunitx}
% --- siunitx settings -----
\sisetup {
exponent-to-prefix = true, % convert exponents into belonging prefixes
round-mode = places,
round-precision = 2,
scientific-notation = engineering,% try to use next engineering unit instead of '.'
per-mode = symbol,
per-symbol = /
}% --------------------------
\begin{document}
Numerica is used to solve the Ohm's Law $I_B = VCC/R1$, given $R1= \SI{10}{\kilo\ohm}$ and $VCC= \SI{5}{\volt}$ as follows: \eval[vv=, eq=\approx]{$I_B$}[I_B = VCC/R1, R1=10^4, VCC=5.0][2x] A.
However, the result uses scientific notation instead of engineering multiples notation that is nicely provided by siunitx as follows: $ V_B \approx \num{5e-4}$A, or even better in a compact form \SI{5e-4}{\ampere}.
I tried a naive approach to mix the two packages siunitx and numerica but it doesn't work.
% \SI{\eval[vv=, eq=\approx]{$I_B$}[I_B = VCC/R1, R1=10^4, VCC=5.0][2x]}{\ampere}
\end{document} '''
答案1
目前,我能想到的唯一实现所需结果的方法是使用numerica
命令\reuse
,该命令将计算结果保存到宏中(然后可以在当前文档的其他地方使用,也可以保存到文件中;请参阅手册第 6.4 节numerica
)。我选择ohmslaw
以下宏的名称:
\documentclass{article}
\usepackage{amssymb} %maths
\usepackage{amsmath} %maths
\usepackage{physics} % before numerica!!!
\usepackage{numerica} % computation of math expressions
\def\eval{\nmcEvaluate} % to simplify numerica avoiding conflict with physics
\usepackage{siunitx}
% --- siunitx settings -----
\sisetup {
exponent-to-prefix = true, % convert exponents into belonging prefixes
round-mode = places,
round-precision = 2,
scientific-notation = engineering,% try to use next engineering unit instead of '.'
per-mode = symbol,
per-symbol = /
}% --------------------------
\begin{document}
\eval[vv=, eq=\approx]{$I_B$}[I_B = VCC/R1, R1=10^4, VCC=5.0][5] A.
\reuse[renew]{ohmslaw}
\SI{\ohmslaw}{\ampere}.
\end{document} '''
Note that I saved the calculated result in ordinary decimal notation rather than scientific notation (the 5 rather than your 2x in the trailing number format option of ```\eval```).