方程下的自动参数定义

方程下的自动参数定义

对于我的学士论文,我在文档中使用了很多方程式。我想使用符号列表,包括单位,并在方程式下添加参数描述。

我希望能够始终如一且高效地实现这一目标。我希望使用宏在我的文档中集中定义一次单位和符号描述。我将在整个文档的符号列表和参数定义中使用这些宏。如果我可以更自动地应用宏,那就更好了,可以防止错误并提高工作效率。

我知道如何手动创建所需输出的乳胶代码。但是我希望每当我添加方程式时,参数定义都可以自动添加。是否有软件可以帮助我实现这一点?

我使用 Lyx 作为编辑器。

我的计划是在我的文档中定义:

  1. 与包一起使用的单位的宏siunitx如下:

\DeclareSIUnit[]\kgpermthree{\kg\per\cubic\meter}
\DeclareSIUnit[]\mpers{\meter\per\second}
\DeclareSIUnit[]\patimess{\pascal\second}
\DeclareSIUnit[]\nodimension{-}
  1. 用于符号描述的宏如下:

\newcommand{\DRho}{density of the fluid} 
\newcommand{\Du}{velocity of the fluid with respect to the object. This is a second line} 
\newcommand{\DL}{characteristic linear dimension} 
\newcommand{\Dmu}{dynamic viscosity of the fluid}
% I chose D for 'definition'

基于以上两个,我计划创建新的宏:

  1. 用于方程参数定义的一组宏,即:

\newcommand{\ERho}{\parbox[t]{6cm}{\DRho}\hspace{2cm}[\si{\kgpermthree}]}
\newcommand{\Eu}{\parbox[t]{6cm}{\Du}\hspace{2cm}[\si{\mpers}]},
\newcommand{\EL}{\parbox[t]{6cm}{\DL}\hspace{2cm}[\si{\meter}]}
\newcommand{\Emu}{\parbox[t]{6cm}{\Dmu}\hspace{2cm}[\si{\patimess}]}
% I chose E for 'Equation definition'

我可以在数组中使用它来定义方程参数(其中 u = ... 等等),如下所示:

\begin{definitions}
\rho & \ERho \\
u & \Eu \\ 
L & \EL \\
\mu & \Emu
\end{definitions}

(另请参阅下面的完整代码(序言))

  1. 使用该包的符号列表的一组词汇表定义,glossaries即:

% Load external file named glsSymbolListDefinitions.tex with symbol list definitions
\loadglsentries{glsSymbolListDefinitions}

外部.tex 文件中的词汇表定义设置如下:

\newglossaryentry{Rho}{name={$\rho$},description={\DRho},unit={\si{\kgpermthree}},type=symbolslist}
\newglossaryentry{u}{name=$u$,description={\Du},unit={\si{\mpers}},type=symbolslist}
\newglossaryentry{L}{name=$L$,description={\DL},unit={\si{\meter}},type=symbolslist}
\newglossaryentry{mu}{name=$\mu$,description={\Dmu},unit={\si{\patimess}},type=symbolslist}

总结一下。我想集中定义单位和符号描述。根据这些定义创建一个符号列表。并自动生成方程下的参数描述。

我认为,创建一个 Excel 表可以帮助我,但这将非常耗时。有没有现成的解决方案?有可用的软件吗?

期望输出:

Latex 代码 MWE:

\documentclass{article}
\usepackage{amsmath}
\usepackage{glossaries}    
\usepackage{array}
\usepackage{textgreek} %for greek alphabet symbols
\usepackage{siunitx}

\glssetnoexpandfield{unit} %necessary for using siunitx macros in the glossary

%The height of each row is set to 1.3 relative to its default height.
\renewcommand{\arraystretch}{1.3}

% create new glossarylist named symbolslist
\newglossary[slg]{symbolslist}{syi}{syg}{List of symbols} 

% declare unit field for glossarylist of symbols
\glsaddkey{unit}{\glsentrytext{\glslabel}}{\glsentryunit}{\GLsentryunit}{\glsunit}{\Glsunit}{\GLSunit}

\makeglossaries                         

% Load external file named glsSymbolListDefinitions.tex with symbol list definitions
\loadglsentries{glsSymbolListDefinitions}

% define glossary style for the symbol list, based on the solution proposed on https://tex.stackexchange.com/questions/269565/glossaries-how-to-customize-list-of-symbols-with-additional-column-for-units
\newglossarystyle{symbunitlong}{%
\setglossarystyle{long3col}% base this style on the list style
\renewenvironment{theglossary}{% Change the table type --> 3 columns
  \begin{longtable}{ >{\raggedright}p{2cm}  >{\raggedright}p{8cm}  >{\raggedright}p{1,5cm} l }} %the third column with width=1,5 cm is for whitespace
  {\end{longtable}}

\renewcommand*{\glossaryheader}{%  Change the table header
    & \bfseries Description & & \bfseries Unit \\
  \endhead}
\renewcommand*{\glossentry}[2]{%  Change the displayed items
\glstarget{##1}{\glossentryname{##1}} %
& \glossentrydesc{##1}% Description
& %whitespace column
& \glsunit{##1}  \tabularnewline
}
}

\makeatletter

\sisetup{inter-unit-product=\ensuremath{{}\cdot{}}} 

%declaring shorthand unit macros, for use in Symbol list, equations parameters and everywhere else.
\DeclareSIUnit[]\kgpermthree{\kg\per\cubic\meter}
\DeclareSIUnit[]\mpers{\meter\per\second}
\DeclareSIUnit[]\patimess{\pascal\second}
\DeclareSIUnit[]\nodimension{-}

%as described on https://tex.stackexchange.com/questions/166580/writing-an-equation-with-the-units-positioned-off-right
\providecommand\add@text{}
\newcommand\equationunit[1]{%
  \gdef\add@text{#1\gdef\add@text{}}}% 
\renewcommand\tagform@[1]{%
  \maketag@@@{\llap{\add@text\quad}(\ignorespaces#1\unskip\@@italiccorr)}%
}

%as described on https://tex.stackexchange.com/questions/95838/how-to-write-a-perfect-equation-parameters-description
\newenvironment{definitions}[1][where:]
  {#1 \begin{tabular}[t]{>{$}l<{$} @{${}={}$} l}}
  {\end{tabular}\\[\belowdisplayskip]}


\begin{document}

    \glsaddall  

\makeatother

%macros for defining symbol descriptions, used in Symbol List and in parameter description, see below
\newcommand{\DRho}{density of the fluid}
\newcommand{\Du}{velocity of the fluid with respect to the object. This is a second line}
\newcommand{\DL}{characteristic linear dimension}
\newcommand{\Dmu}{dynamic viscosity of the fluid}

%macros for parameter descriptions under equation
\newcommand{\ERho}{\parbox[t]{6cm}{\DRho}\hspace{2cm}[\si{\kgpermthree}]}
\newcommand{\Eu}{\parbox[t]{6cm}{\Du}\hspace{2cm}[\si{\mpers}]},
\newcommand{\EL}{\parbox[t]{6cm}{\DL}\hspace{2cm}[\si{\meter}]}
\newcommand{\Emu}{\parbox[t]{6cm}{\Dmu}\hspace{2cm}[\si{\patimess}]}

\printglossary[type=symbolslist,style=symbunitlong,title=List of symbols]   % list of symbols

\printglossary[type=main]  % main glossary, if available, the symbol list seems to be only printed if the main glossary is added as well. It's outside of the scope of this example to check this. 

\section{An example of an equation}
An example of an equation, Reynold's number:

\begin{equation}
\text{Re}=\frac{\rho uL}{\mu}\equationunit{[\si{\nodimension}]}
\end{equation}

\begin{definitions}
\rho & \ERho \\
u & \Eu \\ 
L & \EL \\
\mu & \Emu
\end{definitions}
\end{document}

答案1

因为最近有一些空闲时间,所以我决定建立一个 Excel 文件,它可以帮助我以及其他人解决上述问题。

我为此创建了一个 github 项目: https://github.com/johanf85/Symbollist-maintain-Excel

我制作了一个 Excel 文件,您可以在其中输入:

  • 单位声明(使用siunitx包)
  • 符号和相关描述及单位
  • 文档中使用的公式。将每个符号放在 {} 括号中

一旦每个输入单元格都填满,就可以在“方程式”选项卡上的框中输入方程式编号。显示该方程式的代码和底层参数定义。

将宏复制到序言中,并将方程式和定义代码复制到文档中。

注意:一定要仔细检查结果。我尝试小心地制作 Excel 工作簿,但我还没有在实际工作中对其进行广泛测试。如果有些情况是我忽略的,并且在实践中不起作用,我很想知道。

请让我知道对此项目的任何意见。我很想听到可能的改进。

相关内容