1

Edit: I think there was a bug in overleaf as the code now prints the table. The table is missing the page number column. The first column of the table contains the name of the entries and not the \newsymbol optional argument. Also, the order of entries doesn't seem to reflect the order of \gls calls.

I am trying to create a glossary formatted as a table that contains the: symbol, description, CGS units, Base CGS units, Dimensions, and page of appearance of all symbols in my document.

I am using the glossaries package with acronym because I will have a separate glossary and acronym section in the main document.

This is a bit beyond my LaTeX knowledge and I have tried using GPT 3.5 to create it for me. The closest I have gotten is the following code:

\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}

This is the ideal output: Ideal Output

This is my current output: Current Output

4
  • 1
    Note that overleaf just runs your code. Your code does not generate page numbers at my end either.
    – daleif
    Commented Nov 9, 2023 at 15:44
  • Unrelated but yuo ought to use the siunitx package to format units.
    – daleif
    Commented Nov 9, 2023 at 15:45
  • I have fixed the page numbers. For some reason, page numbers where stored in user5. But \glsentryuseriv was printed in the table (seems AI is still a bit wonky haha). I have set page numbers to user4 and they now work. I still want to have the symbol from the optional argument of \newsymbol in the first column. And for the order of the symbols to be in the order of \gls calls (so from first appearance in text). When this is working it will go in to my main document. So I will do all my nice formatting in there.
    – BrayA
    Commented Nov 9, 2023 at 15:55
  • Also a new problem, new entries don't seem to work.
    – BrayA
    Commented Nov 9, 2023 at 16:08

2 Answers 2

1

If you want the optional argument to be the symbol, \newsymbol should use symbol={#1} instead of 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}

However, this will not show the page number. And currently I don't know, which page number you expect.

BTW: IMHO it would make more sense to use the optional argument for the symbol name, needed if the symbol itself cannot be used for a reference:

\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}

This would not need makeglossaries or makeindex to generate:

enter image description here

BTW: GPT's LaTeX code is at least as faulty as the mass of LaTeX code available from internet, that has been used to train the machine. So instead of using it, I would recommend to read the glossaries manual. There you will also find, how the entries are sorted and how you can make an unsorted glossary.

7
  • I have managed to get everything working except having the entries appear in order of appearance (either the \gls or \newsymbols calls). I have set both name and symbol to = #1 and label to = #2. This lets the symbols themselves appear in the table. Entries have to be defined where they are in text, otherwise the page numbers will not function. The only thing that I need to get working now is to get the table to list entries in order of apperenace.
    – BrayA
    Commented Nov 9, 2023 at 16:49
  • I just need to sort the table by the order of appearance now. I could use \usepackage[acronym,automake,sort = use]{glossaries}. But this would force my glossary and acronyms to do the same (they should be alphabetical).
    – BrayA
    Commented Nov 9, 2023 at 17:00
  • @BrayA You can use \makenoidxglossaries instead of \makeglossaries and \printnoidxglossary[sort=use,type=symbol,style=symbolsstyle,title=List of Symbols]. I've not testes sort=standard for a second glossary, because there isn't any in you example.
    – cabohah
    Commented Nov 9, 2023 at 17:17
  • That causes my latex to crash because the entries are defined in the text. I tried to use your second example instead, but it causes the \gls calls to print the name and not the symbol. I'll see if I can fix that to use \makenoidxglossaries.
    – BrayA
    Commented Nov 9, 2023 at 17:26
  • The error was only in the latex I had at the time, where glossary entries were defined in text. Using your second example they work fine. Honestly, thank you for helping me with it. I know some of it probably doesn't make sense because I just used GPT promps and this is a bit over my head. The only think I have left to fix now is that the \gls calls will print the name (such as vecF) rather than the math symbol.
    – BrayA
    Commented Nov 9, 2023 at 17:37
0

I think this has been solved! The code is still mess (Thanks GPT) but it appears to work fine now. Big thank you to @cabohah . All the front and back matter I need is now automated. This will save me literally days of work in the long run.

The final LaTeX code is:


\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}
2
  • Could you clarify what this answer adds to the one you accepted? I've only very quickly skimmed it, so this isn't a criticism of your code, but it would make it easier for people looking for solutions to know what differentiates yours.
    – cfr
    Commented Nov 9, 2023 at 20:11
  • There was a correction from name = {#1} to name ={#2} in \newsymbol in the other answer. But I think @cabohah edited their answer to correct it anyway, so i think the two codes are identical. My bad.
    – BrayA
    Commented Nov 10, 2023 at 10:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .