扫描文档中的所有 siunits

扫描文档中的所有 siunits

当给出宏时\tableofcontents,它会获取所有章节、部分、节...并生成整个文档的目录。甚至和\listoftables\listoffigures能做到这一点。现在,我的文档中有一组siunits与 tcolorbox 修改一起使用的\begin{siunit}...\end{siunit},我如何定义一个命令来扫描所有这些siunit环境并生成所有使用的 siunits 的页面。

以下是源代码:

\documentclass[12pt, a4paper]{book}
\usepackage{setspace}
\usepackage[many]{tcolorbox}
\usepackage[detect-all]{siunitx}
\DeclareSIUnit\gauss{G}
\usepackage[pagestyles]{titlesec}
\usepackage{amsmath}
%\usepackage{empheq}
%%--------tcolorbox setting for the SI Units display---------%%
\newtcolorbox{siunit}{enhanced,
  colframe=red!60!black,colback=yellow!50!white,arc=4pt,boxrule=1pt,
  drop fuzzy shadow,before=\begin{center},after=\end{center},hbox}
%\tcbset{highlight math style={enhanced,
%  colframe=red!60!black,colback=yellow!50!white,arc=4pt,boxrule=1pt,
%  drop fuzzy shadow}}
\newtcbox{\picturebox}[1][]{nobeforeafter,math upper,tcbox raise base,
  enhanced,watermark graphics=example-grid-100x100bp.jpg,% from package mwe
  colback=white,frame hidden,boxrule=0pt,arc=10pt,
  watermark stretch=1.00,watermark opacity=0.4,#1}
%%--------Chapter and Section headings display------------%%
\makeatletter
\renewcommand{\thechapter}{\Roman{chapter}}
\titleformat{\chapter}[display]
{\bfseries\Large\filleft} %\centering doesn't work only \filleft
{\filleft\MakeUppercase{\chaptertitlename} \Huge\thechapter}
{4ex}
{\titlerule
\vspace{2ex}%
\filright}
[\vspace{2ex}
\titlerule]

\renewcommand{\thesection}{\Roman{section}}
\titleformat{\section}
{\LARGE\bfseries}
{}{1em}{}
\titlespacing{\section}
{-2.15pc}{3.5ex plus .1ex minus .2ex}{1.5ex minus .1ex}

\makeatletter

\newpagestyle{mystyle}{
\headrule \sethead[\thepage][][\chaptertitlename\ \thechapter. \chaptertitle]
{\sectiontitle}{}{\thepage}}

\begin{document}
\pagestyle{mystyle}
\frontmatter
\begin{titlepage}

\end{titlepage}
\mainmatter
\include{magnetic}
\end{document} 

磁性.tex:

\chapter{Magnetic Materials}
\section{Introduction}
Magnetic materials have had various applications in ancient and modern society. A magnetic compass made of lodestone (magnetite) was used for navigation since the north pole of a compass point toward the south pole of Earth's magnetic field. In the modern era, magnetism and magnetic materials find applications in various fields.

\section{Origin of Magnetic properties of\\ materials}
Magnetic properties of materials have their origin in :
\begin{enumerate}
\item Permanent magnetic moments of their atoms and$/$or
\item Induced magnetic moments due to the change of motion of the electric charges of the atoms in an external magnetic field.
\end{enumerate}
The magnetic moments of atomic nuclei are generally neglected as they are very small.

\paragraph{Permanent magnetic moment of atoms}is due to the orbital and spin motions of unpaired electrons (i.e., electrons in the incompletely filled valence shell). Electrons in completely filled valence shells have no magnetic moment.(Eg. He, Ne, Ar etc). Some of the important terms in the study of magnetic materials is given below.

\paragraph{Magnetic fields}are generated by movement of electric charges. \textit{\bfseries Magnetic field} is the region of space where moving charges, current carrying elements or other magnetic objects will experience a force.

\paragraph{Magnetic moment}of a magnet is a quantity that determines the force the magnet can exert on electric currents and the torque that a magnetic field will exert on it. A loop of electric current generates a \textit{magnetic dipole field}. \textit{Magnitude} of the magnetic dipole moment is the product of the current and the area of the loop. Magnetic dipole is often represented schematically as an arrow. The head of the arrow is the North pole.\par
\begin{siunit}
SI unit :  Ampere. square metre (\si{\ampere\square\meter})
\end{siunit}

\paragraph{Magnetic Field lines} run from the North pole to the South pole.
\paragraph{Magnetic Flux}The group of magnetic field lines emitted outward from the north pole of a magnet is called \textit{magnetic flux}.\par
\begin{siunit}
SI~unit :  Weber (\si{\weber})
\end{siunit}
One weber is equal to $1$ x $10^8$ magnetic field lines. Direction of flux at any point in space indicates the direction of force that would be experienced by a North pole placed at that point.

\paragraph{Intensity of Magnetization M}A Material with a net (nonzero) magnetic moment is magnetized. \textit{Intensity of Magnetization M} is the magnetic moment per unit volume within the material.\par
\begin{siunit}
SI unit :  Ampere per metre (\si{\ampere\per\meter})
\end{siunit}
M depends on the following:
\begin{enumerate}
\item Number density of magnetic dipole moments within material.
\item Magnitude of the magnetic dipole moments.
\item The arrangement of the magnetic dipoles within the material and so on.
\end{enumerate}

\paragraph{Magnetization M}in materials mainly arises from spins of unpaired electrons within the material and to a lesser extent from their orbital motion.

\section{Magnetic field}
A \textbf{magnetic field} is a field of force produced by moving electric charges, by electric fields varying with time and by the \textbf{intrinsic} magnetic field of elementary particles due to their spin. Magnetic field is a vector field and is most commonly defined in terms of the Lorentz force that it exerts on moving electric charges. The magnetic field can be visualized as magnetic field lines.\par
There are two separate but closely related fields to which the name 'magnetic field' can refer:
A magnetic \textbf{B} field called \textit{magnetic induction} or \textit{magnetic flux density} \par
%{\centering \tcbox{SI unit :  tesla, T}} %%tcolorbox not properly aligned when using \centering -- thought will complete in a single line
\begin{siunit}
SI unit :  tesla, \si{\tesla}
\end{siunit}
and  a magnetic \textbf{H} field called \textit{magetic field strength} or \textit{magnetizing field}\par
%{\centering \tcbox{SI unit :  Ampere per metre $A.m^{-1}$}}
\begin{siunit}
SI unit :  Ampere per metre (\si{\ampere\per\meter})
\end{siunit}
Magnetic field strength \textbf{H} is measured in $A/m$, and magnetic flux density \textbf{B}, measured in $Nm/A$, also called tesla (T).

\paragraph{Magnetic flux density or magnetic induction B}\textit{Magnetic Flux density} \textbf{B} is the amount of magnetism induced in a body and it is a function of the \textit{magnetizing force} \textbf{H}.
The \textit{magnetic induction}, \textbf{B} is defined as the amount of magnetic flux through a unit area taken perpendicular to the direction of the magnetic flux.
\begin{siunit}
\begin{minipage}{0.75\linewidth}
SI unit  : Weber per metre square (\si{\weber\per\square\meter}) or tesla (\si{\tesla})
\par
CGS unit  : gauss ($\SI{1}{\tesla} = \SI{10000}{\gauss}$)
\end{minipage}
\end{siunit}

\paragraph{Manetic field strength, H}Magnetic field strength \textbf{H} is the amount of magnetizing force. Magnetic field strength is a vector quantity whose magnitude is the strength of a magnetic field at a point in the direction of the magnetic field at that point.
\begin{siunit}
SI~unit  : Ampere~per~metre (\si{\ampere\per\meter})
\end{siunit}

\section{Relation between B and H}
\textit{In free space or outside of a material (i.e., in vacuum) the \textbf{B} and \textbf{H} fields are indistinguishable (they only differ by a multiplicative constant).}
\begin{gather*}
B = \mu_{0}.H \quad \text{(in vaccum)} \\
\mu_{0}   \rightarrow \text{magnetic permeability of free space (vacuum)}
\end{gather*}
where $\mu_{0} = 4\pi~\text{x}~10^7 N.A^{-2}~(H.m^{-1})$ \par
Inside magnetic material,  $B = \mu.H = \mu_{0}.H + \mu_{0}.M $ where $\mu$ is the \\ \textit{magnetic permeability of medium}. 

答案1

我引入了一个包装命令,用于将数量及其单位的名称写入listofsiunits-toc 文件。

而不是\begin{siunit}...\end{siunit}使用\SiunitBox{Magnetic Flux}{Weber}。第一个参数是可选的,用于处理颜色框的设置。在示例中,我的更改在输出中有一个绿色框架。

\documentclass[12pt, a4paper]{book}
\usepackage{setspace}
\usepackage{etoolbox}
\usepackage[many]{tcolorbox}
\usepackage[detect-all]{siunitx}
\DeclareSIUnit\gauss{G}
\usepackage[pagestyles]{titlesec}
\usepackage{amsmath}
%\usepackage{empheq}
%%--------tcolorbox setting for the SI Units display---------%%


% Wrapper for siunitbox%
\newenvironment{siunit}[2][]{%
\begin{siunitbox}[#1]{#2}
SI~unit : #2%
\end{siunitbox}}{% Other start code
}{% Other end code
}%

\newrobustcmd{\SiunitBox}[3][]{%
  \begin{siunitbox}[#1]{#2: #3}
    SI~unit : #3%
  \end{siunitbox}
}

\newcounter{siunitboxcounter}

\newtcolorbox[use counter={siunitboxcounter},number within=section,list inside={siunitbox}]{siunitbox}[2][]{enhanced,%
  colframe=red!60!black,colback=yellow!50!white,arc=4pt,boxrule=1pt,
  drop fuzzy shadow,before=\begin{center},after=\end{center},hbox,list entry={\protect\textbf{#2}},#1}
%\tcbset{highlight math style={enhanced,
%  colframe=red!60!black,colback=yellow!50!white,arc=4pt,boxrule=1pt,
%  drop fuzzy shadow}}
\newtcbox{\picturebox}[1][]{nobeforeafter,math upper,tcbox raise base,
  enhanced,watermark graphics=example-grid-100x100bp.jpg,% from package mwe
  colback=white,frame hidden,boxrule=0pt,arc=10pt,
  watermark stretch=1.00,watermark opacity=0.4,#1}
%%--------Chapter and Section headings display------------%%
\makeatletter
\renewcommand{\thechapter}{\Roman{chapter}}
\titleformat{\chapter}[display]
{\bfseries\Large\filleft} %\centering doesn't work only \filleft
{\filleft\MakeUppercase{\chaptertitlename} \Huge\thechapter}
{4ex}
{\titlerule
\vspace{2ex}%
\filright}
[\vspace{2ex}
\titlerule]

\renewcommand{\thesection}{\Roman{section}}
\titleformat{\section}
{\LARGE\bfseries}
{}{1em}{}
\titlespacing{\section}
{-2.15pc}{3.5ex plus .1ex minus .2ex}{1.5ex minus .1ex}

\makeatletter

\newpagestyle{mystyle}{
\headrule \sethead[\thepage][][\chaptertitlename\ \thechapter. \chaptertitle]
{\sectiontitle}{}{\thepage}}



\begin{document}
\pagestyle{mystyle}
\frontmatter
\begin{titlepage}

\end{titlepage}



\tcblistof{siunitbox}{List of SI units}
\mainmatter
\include{magnetic}
\end{document} 

磁性.tex

\chapter{Magnetic Materials}
\section{Introduction}
Magnetic materials have had various applications in ancient and modern society. A magnetic compass made of lodestone (magnetite) was used for navigation since the north pole of a compass point toward the south pole of Earth's magnetic field. In the modern era, magnetism and magnetic materials find applications in various fields.

\section{Origin of Magnetic properties of\\ materials}
Magnetic properties of materials have their origin in :
\begin{enumerate}
\item Permanent magnetic moments of their atoms and$/$or
\item Induced magnetic moments due to the change of motion of the electric charges of the atoms in an external magnetic field.
\end{enumerate}
The magnetic moments of atomic nuclei are generally neglected as they are very small.

\paragraph{Permanent magnetic moment of atoms}is due to the orbital and spin motions of unpaired electrons (i.e., electrons in the incompletely filled valence shell). Electrons in completely filled valence shells have no magnetic moment.(Eg. He, Ne, Ar etc). Some of the important terms in the study of magnetic materials is given below.

\paragraph{Magnetic fields}are generated by movement of electric charges. \textit{\bfseries Magnetic field} is the region of space where moving charges, current carrying elements or other magnetic objects will experience a force.

\paragraph{Magnetic moment}of a magnet is a quantity that determines the force the magnet can exert on electric currents and the torque that a magnetic field will exert on it. A loop of electric current generates a \textit{magnetic dipole field}. \textit{Magnitude} of the magnetic dipole moment is the product of the current and the area of the loop. Magnetic dipole is often represented schematically as an arrow. The head of the arrow is the North pole.\par
%\SiunitBox{SI unit :  Ampere. square metre (\si{\ampere\square\meter})}

\begin{siunit}{Ampere. square metre (\si{\ampere\square\meter})}
%SI~unit :  Ampere. square metre (\si{\ampere\square\meter})
\end{siunit}

\SiunitBox[colframe=green]{Magnetic Moment}{Ampere. square metre (\si{\ampere\square\meter})}


\paragraph{Magnetic Field lines} run from the North pole to the South pole.
\paragraph{Magnetic Flux}The group of magnetic field lines emitted outward from the north pole of a magnet is called \textit{magnetic flux}.\par
\begin{siunit}{Weber (\si{\weber})}
\end{siunit}

\SiunitBox[colframe=green]{Magnetic Flux}{Weber (\si{\weber})}

One weber is equal to $1$ x $10^8$ magnetic field lines. Direction of flux at any point in space indicates the direction of force that would be experienced by a North pole placed at that point.

\paragraph{Intensity of Magnetization M}A Material with a net (nonzero) magnetic moment is magnetized. \textit{Intensity of Magnetization M} is the magnetic moment per unit volume within the material.\par
\begin{siunit}{Ampere per metre(\si{\ampere\per\meter})}
\end{siunit}
M depends on the following:
\begin{enumerate}
\item Number density of magnetic dipole moments within material.
\item Magnitude of the magnetic dipole moments.
\item The arrangement of the magnetic dipoles within the material and so on.
\end{enumerate}

\paragraph{Magnetization M}in materials mainly arises from spins of unpaired electrons within the material and to a lesser extent from their orbital motion.

\section{Magnetic field}
A \textbf{magnetic field} is a field of force produced by moving electric charges, by electric fields varying with time and by the \textbf{intrinsic} magnetic field of elementary particles due to their spin. Magnetic field is a vector field and is most commonly defined in terms of the Lorentz force that it exerts on moving electric charges. The magnetic field can be visualized as magnetic field lines.\par
There are two separate but closely related fields to which the name 'magnetic field' can refer:
A magnetic \textbf{B} field called \textit{magnetic induction} or \textit{magnetic flux density} \par
%{\centering \tcbox{SI unit :  tesla, T}} %%tcolorbox not properly aligned when using \centering -- thought will complete in a single line
\begin{siunit}{tesla, \si{\tesla}}
\end{siunit}%
and  a magnetic \textbf{H} field called \textit{magetic field strength} or \textit{magnetizing field}\par
%{\centering \tcbox{SI unit :  Ampere per metre $A.m^{-1}$}}
\begin{siunit}{SI unit :  Ampere per metre (\si{\ampere\per\meter})}
\end{siunit}
Magnetic field strength \textbf{H} is measured in $A/m$, and magnetic flux density \textbf{B}, measured in $Nm/A$, also called tesla (T).

\paragraph{Magnetic flux density or magnetic induction B}\textit{Magnetic Flux density} \textbf{B} is the amount of magnetism induced in a body and it is a function of the \textit{magnetizing force} \textbf{H}.
The \textit{magnetic induction}, \textbf{B} is defined as the amount of magnetic flux through a unit area taken perpendicular to the direction of the magnetic flux.
%\begin{siunit}
%\begin{minipage}{0.75\linewidth}
%SI unit  : Weber per metre square (\si{\weber\per\square\meter}) or tesla (\si{\tesla})
%\par
%CGS unit  : gauss ($\SI{1}{\tesla} = \SI{10000}{\gauss}$)
%\end{minipage}
%\end{siunit}

\paragraph{Manetic field strength, H}Magnetic field strength \textbf{H} is the amount of magnetizing force. Magnetic field strength is a vector quantity whose magnitude is the strength of a magnetic field at a point in the direction of the magnetic field at that point.
\begin{siunit}{Ampere~per~metre (\si{\ampere\per\meter})}
\end{siunit}

\section{Relation between B and H}
\textit{In free space or outside of a material (i.e., in vacuum) the \textbf{B} and \textbf{H} fields are indistinguishable (they only differ by a multiplicative constant).}
\begin{gather*}
B = \mu_{0}.H \quad \text{(in vaccum)} \\
\mu_{0}   \rightarrow \text{magnetic permeability of free space (vacuum)}
\end{gather*}
where $\mu_{0} = 4\pi~\text{x}~10^7 N.A^{-2}~(H.m^{-1})$ \par
Inside magnetic material,  $B = \mu.H = \mu_{0}.H + \mu_{0}.M $ where $\mu$ is the \\ \textit{magnetic permeability of medium}.

在此处输入图片描述

笔记

不要\begin{siunitbox}...直接使用,它没有将数量设置到列表文件中。

相关内容