编辑:我认为 overleaf 中有一个错误,因为代码现在打印表格。表格缺少页码列。表格的第一列包含条目的名称,而不是 \newsymbol 可选参数。此外,条目的顺序似乎没有反映 \gls 调用的顺序。
我正在尝试创建一个格式化为表格的词汇表,其中包含:符号、描述、CGS 单位、基本 CGS 单位、尺寸和文档中所有符号的出现页面。
我正在使用带有首字母缩略词的词汇表包,因为我将在主文档中有一个单独的词汇表和首字母缩略词部分。
这有点超出我的 LaTeX 知识范围,我曾尝试使用 GPT 3.5 来创建它。我得到的最接近的代码是以下代码:
\documentclass{article}
\usepackage[acronym]{glossaries}
\usepackage{amsmath} % for math symbols
\usepackage{longtable}
% Define a new glossary type for symbols
\newglossary[slg]{symbol}{sym}{sbl}{List of Symbols}
% Custom glossary entry style
\newglossarystyle{symbolsstyle}{
\renewenvironment{theglossary}%
{\begin{longtable}{llllll}}{\end{longtable}}%
\renewcommand*{\glossaryheader}{\hline Symbol & Description & CGS Units & Base CGS Units & Dimensions & Page \\ \hline}%
\renewcommand*{\glsgroupheading}[1]{}%
\renewcommand*{\glossentry}[2]{%
\glsentryitem{##1}\glstarget{##1}{\glossentrysymbol{##1}} &
\glossentrydesc{##1} &
\glsentryuseri{##1} &
\glsentryuserii{##1} &
\glsentryuseriii{##1} &
\glsentryuseriv{##1} \\ % Use \glsentryuseriv for page numbers
}%
\renewcommand*{\glsgroupskip}{}%
}
% Custom glossary entry command
\newcommand{\newsymbol}[7][]{%
\newglossaryentry{#2}{
type=symbol,
name={#1},
symbol={#2},
description={#3},
user1={#4}, % CGS Units
user2={#5}, % Base CGS Units
user3={#6}, % Dimensions
user4={}, % This will store page numbers
user5={\thepage} % Store the current page number
}%
\label{symbol:#2}%
}
% Sample symbols
\newsymbol[$\vec{F}$]{vecF}{Force}{dyn}{g cm s$^{-2}$}{[M][L][T]$^{-2}$}{}
\newsymbol[$m$]{m}{Mass}{g}{g}{[M]}{}
\newsymbol[$\vec{a}$]{veca}{Acceleration}{cm s$^{-2}$}{cm s$^{-2}$}{[L][T]$^{-2}$}{}
\makeglossaries % Use \makeglossaries instead of \glsaddall
\begin{document}
\section*{Table of Symbols}
\printglossary[type=symbol,style=symbolsstyle,title=List of Symbols]
\newpage
\section{Introduction}
This is a sample document with symbols: \gls{vecF}, \gls{m}, and \gls{veca}.
\end{document}
答案1
如果希望可选参数是符号,\newsymbol
则应使用symbol={#1}
而不是symbol={#2}
:
\documentclass{article}
\usepackage[acronym]{glossaries}
\usepackage{amsmath} % for math symbols
\usepackage{longtable}
% Define a new glossary type for symbols
\newglossary[slg]{symbol}{sym}{sbl}{List of Symbols}
% Custom glossary entry style
\newglossarystyle{symbolsstyle}{
\renewenvironment{theglossary}%
{\begin{longtable}{llllll}}{\end{longtable}}%
\renewcommand*{\glossaryheader}{\hline Symbol & Description & CGS Units & Base CGS Units & Dimensions & Page \\ \hline}%
\renewcommand*{\glsgroupheading}[1]{}%
\renewcommand*{\glossentry}[2]{%
\glsentryitem{##1}\glstarget{##1}{\glossentrysymbol{##1}} &
\glossentrydesc{##1} &
\glsentryuseri{##1} &
\glsentryuserii{##1} &
\glsentryuseriii{##1} &
\glsentryuseriv{##1} \\ % Use \glsentryuseriv for page numbers
}%
\renewcommand*{\glsgroupskip}{}%
}
% Custom glossary entry command
\NewDocumentCommand{\newsymbol}{O{#2}mmmmm}{%
\newglossaryentry{#2}{
type=symbol,
name={#2},
symbol={#1},
description={#3},
user1={#4}, % CGS Units
user2={#5}, % Base CGS Units
user3={#6}, % Dimensions
user4={}, % This will store page numbers
user5={\thepage} % Store the current page number
}%
\label{symbol:#2}%
}
% Sample symbols
\newsymbol[$\vec{F}$]{vecF}{Force}{dyn}{g cm s$^{-2}$}{[M][L][T]$^{-2}$}{}
\newsymbol[$m$]{m}{Mass}{g}{g}{[M]}{}
\newsymbol[$\vec{a}$]{veca}{Acceleration}{cm s$^{-2}$}{cm s$^{-2}$}{[L][T]$^{-2}$}{}
\makeglossaries % Use \makeglossaries instead of \glsaddall
\begin{document}
\section*{Table of Symbols}% Note: Does this make sense???
\printglossary[type=symbol,style=symbolsstyle,title=List of Symbols]
\newpage
\section{Introduction}
This is a sample document with symbols: \gls{vecF}, \gls{m}, and \gls{veca}.
\end{document}
但是,这不会显示页码。目前我不知道您期望的是哪个页码。
顺便说一句:在我看来,使用符号名称的可选参数更有意义,如果符号本身不能用于引用,则需要:
\documentclass{article}
\usepackage[acronym]{glossaries}
\usepackage{amsmath} % for math symbols
\usepackage{longtable}
\usepackage{mwe}
% Define a new glossary type for symbols
\newglossary[slg]{symbol}{sym}{sbl}{List of Symbols}
% Custom glossary entry style
\newglossarystyle{symbolsstyle}{
\renewenvironment{theglossary}%
{\begin{longtable}{llllll}}{\end{longtable}}%
\renewcommand*{\glossaryheader}{\hline Symbol & Description & CGS Units & Base CGS Units & Dimensions & Page \\ \hline}%
\renewcommand*{\glsgroupheading}[1]{}%
\renewcommand*{\glossentry}[2]{%
\glsentryitem{##1}\glstarget{##1}{\glossentrysymbol{##1}} &
\glossentrydesc{##1} &
\glsentryuseri{##1} &
\glsentryuserii{##1} &
\glsentryuseriii{##1} &
##2 \\ % Note: location list
}%
\renewcommand*{\glsgroupskip}{}%
}
% Custom glossary entry command
\NewDocumentCommand{\newsymbol}{O{#2}mmmmm}{%
\newglossaryentry{#1}{
type=symbol,
name={#2},
symbol={#2},
description={#3},
user1={#4}, % CGS Units
user2={#5}, % Base CGS Units
user3={#6}, % Dimensions
user4={}, % This will store page numbers
user5={\thepage} % Store the current page number
}%
\label{symbol:#1}% Note: Does this make sense???
}
% Sample symbols
\newsymbol[vecF]{$\vec{F}$}{Force}{dyn}{g cm s$^{-2}$}{[M][L][T]$^{-2}$}{}
\newsymbol[m]{$m$}{Mass}{g}{g}{[M]}{}
\newsymbol[veca]{$\vec{a}$}{Acceleration}{cm s$^{-2}$}{cm s$^{-2}$}{[L][T]$^{-2}$}{}
\newsymbol{me}{The
Author}{\includegraphics[width=1em]{example-image-a}}{nonsense}{demo}{}
\makenoidxglossaries % see the glossaries manual for more information
\begin{document}
\printnoidxglossary[sort=use,type=symbol,style=symbolsstyle,title=List of Symbols]
\newpage
\section{Introduction}
This is a sample document from \gls{me} with symbols: \gls{vecF}, \gls{m}, and \gls{veca}.
\end{document}
这不需要makeglossaries
或makeindex
生成:
顺便说一句:GPT 的 LaTeX 代码至少与互联网上用于训练机器的大量 LaTeX 代码一样有缺陷。因此,我建议不要使用它,而是阅读手册glossaries
。在那里你还会发现条目是如何排序的,以及如何制作未分类的词汇表。
答案2
我认为这个问题已经解决了!代码仍然很乱(感谢 GPT),但现在似乎可以正常工作了。非常感谢 @cabohah 。我需要的所有前言和后文现在都已自动化。从长远来看,这将节省我几天的工作时间。
最终的 LaTeX 代码是:
\documentclass{article}
\usepackage[acronym]{glossaries}
\usepackage{amsmath} % for math symbols
\usepackage{longtable}
\usepackage{mwe}
% Define a new glossary type for symbols
\newglossary[slg]{symbol}{sym}{sbl}{List of Symbols}
% Custom glossary entry style
\newglossarystyle{symbolsstyle}{
\renewenvironment{theglossary}%
{\begin{longtable}{llllll}}{\end{longtable}}%
\renewcommand*{\glossaryheader}{\hline Symbol & Description & CGS Units & Base CGS Units & Dimensions & Page \\ \hline}%
\renewcommand*{\glsgroupheading}[1]{}%
\renewcommand*{\glossentry}[2]{%
\glsentryitem{##1}\glstarget{##1}{\glossentrysymbol{##1}} &
\glossentrydesc{##1} &
\glsentryuseri{##1} &
\glsentryuserii{##1} &
\glsentryuseriii{##1} &
##2 \\ % Note: location list
}%
\renewcommand*{\glsgroupskip}{}%
}
% Custom glossary entry command
\NewDocumentCommand{\newsymbol}{O{#2}mmmmm}{%
\newglossaryentry{#1}{
type=symbol,
name={#2},
symbol={#2},
description={#3},
user1={#4}, % CGS Units
user2={#5}, % Base CGS Units
user3={#6}, % Dimensions
user4={}, % This will store page numbers
user5={\thepage} % Store the current page number
}%
\label{symbol:#1}% Note: Does this make sense???
}
% Sample symbols
\newsymbol[vecF]{$\vec{F}$}{Force}{dyn}{g cm s$^{-2}$}{[M][L][T]$^{-2}$}{}
\newsymbol[m]{$m$}{Mass}{g}{g}{[M]}{}
\newsymbol[veca]{$\vec{a}$}{Acceleration}{cm s$^{-2}$}{cm s$^{-2}$}{[L][T]$^{-2}$}{}
\newsymbol{me}{The
Author}{\includegraphics[width=1em]{example-image-a}}{nonsense}{demo}{}
\makenoidxglossaries % see the glossaries manual for more information
\begin{document}
\printnoidxglossary[sort=use,type=symbol,style=symbolsstyle,title=List of Symbols]
\newpage
\section{Introduction}
This is a sample document from with symbols: \gls{m}, and \gls{veca},\gls{me}, \gls{vecF},.
\end{document}