使用 \AtBeginDocument 获取前言中的词汇表

使用 \AtBeginDocument 获取前言中的词汇表

我正在使用glossaries带有类的包来处理命令内部的一些前端格式\AtBeginDocument{}

我无法将词汇表正确放入前言中。相反,它们只出现在内容之后\AtBeginDocument{},因此被推入主文档。

这是我的 MWE(thesis-umich-glo类包含在这篇文章的末尾 - 我尽可能地精简了它)

\documentclass[thesis,12pt]{thesis-umich-glo}
\usepackage[style=long3col,acronym]{glossaries}
\usepackage{acronym}

% I want two glossaries: I'll use 'sym' to separate them
\newglossary[tlg]{sym}{tld}{tdn}{Symbols}
\makeglossaries

\begin{document} 
% Print the glossaries
\glstoctrue
\printglossary[type=sym,title={List of Symbols}]
\printglossary[type=acronym,title={List of Abbreviations}]

% Glossary definitions
\newglossaryentry{alpha}{type=sym, name=$\alpha$, description={Just a symbol}}
\newglossaryentry{beta}{type=sym, name=$\beta$, description={Another symbol}}
\newacronym{cd}{CD}{compact disk}
\newacronym{FE}{FE}{finite element} 

\chapter{First chap}
\section{First section}
Here I use the symbols in the document: \gls{alpha}, and \gls{beta}.

Now some acronyms: First use of \gls{cd}\ subsequent \gls{cd} with first \gls{FE}.
\end{document}

尝试在主文档之前获取词汇表

有人能帮我把这些词汇表条目推到前言中吗?我知道一种方法是完全忘记这个类(词汇表包默认将内容放在前言中),但不幸的是,我从 MWE 中剔除了许多小的格式化内容,我需要使用这些内容。

% thesis-umich-glo.cls
\ProvidesClass{thesis-umich-glo}[2011/04/09 Thesis template]

%% ---- OPTIONS PROCESSING ---------------------------------------------
% I've removed other options - only thesis left in this example
\newif\if@umich@thesis
% Set the default value of some of the options to true.
\@umich@thesistrue

% Declare options for the overall layout.
\DeclareOption{thesis}{\@umich@thesistrue}

% This passes any other options on to the 'report' class.
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{report}%
 \typeout{Unknown option: passing ``\CurrentOption"
  option on to the standard LaTeX report class.}}
% This command tells LaTeX to simply process the class options.
\ProcessOptions

% Call the report class with 12pt fonts and one-sided formatting.
 \LoadClass[letterpaper,12pt,oneside]{report}

%% ---- PACKAGE LOADING ------------------------------------------------
% This class uses the geometry.sty package to set the margins.
 % Use the standard margins for the thesis version.
 \RequirePackage[margin=1in,left=1.5in, %
  headheight=0.5\baselineskip]{geometry}
% This changes the font.
\RequirePackage{times}
% This package is used to set line spacing.
\RequirePackage{setspace}
% This package allows conditional testing of variables.
\RequirePackage{ifthen}
% This package is used to generate alternate environments.
\RequirePackage{float}
% This is the package for special headers and footers.
\RequirePackage{fancyhdr}

%% ---- PAGE STYLES ----------------------------------------------------
% Same idea as \ttlpg above but with page numbers
\newcommand*{\frntpg}{ %
 % Set one-column switch temporarily to false.
 \@restonecolfalse %
 % Check the number of columns.
 \if@twocolumn %
  \@restonecoltrue\onecolumn %
 \else %
  \newpage %
 \fi
 % Regular headers and footers
 \thispagestyle{plain}
}

%% ---- TABLE OF CONTENTS ----------------------------------------------
% This sets the formatting for chapter entries in the table of contents.
\renewcommand*\l@chapter[2]{ %
 % First add some vertical space.
 \vskip 1ex plus 1pt minus 1pt
 % Format the spacing and use dots between title and number.
 \@dottedtocline{1}{0em}{1.0em} %
 % This sets the formatting for the chapter name and page number.
 {\textbf{#1}}{\textbf{#2}} %
 % Add some space below, too.
 \vskip 1ex}

% These lines set the spacing for other table of contents entries.
\renewcommand*{\l@section}{\@dottedtocline{2}{2.5em}{2em}}
\renewcommand*{\l@subsection}{\@dottedtocline{3}{5.0em}{2.8em}}
\renewcommand*{\l@subsubsection}{\@dottedtocline{4}{7.5em}{3.5em}}

% Number of section layers to show in table of contents
\setcounter{tocdepth}{3}
% Number of subsection layers to allow in document
\setcounter{secnumdepth}{3}

% This sets the formatting of the table of contents.
\renewcommand*{\tableofcontents}{%
 % Move to new page.
 \newpage %
 % Add a pdf anchor.
 \phantomsection %
 % Add a bookmark manually for the table of contents.
 \pdfbookmark[0]{Table of Contents}{\thepage} %
 % Use front page styling.
 \frntpg %
 % Larger upper margin for first page of table
 \if@umich@thesis %
  \begin{minipage}{0.8\textwidth} \vspace{1in} \end{minipage} \\ %
 \fi %
 % Add the title
 \centerline{\large\bf TABLE OF CONTENTS} %
 % Add some space after the title.
 \vspace{2ex} %
 % Start the automatic table of contents features.
 \begin{singlespace} %
  \@starttoc{toc}\if@restonecol\twocolumn\fi %
 \end{singlespace} %
}

%% ---- LIST OF FIGURES ------------------------------------------------
% This sets the formatting for the various entry types.
\renewcommand*{\l@figure}{\@dottedtocline{1}{0em}{2.5em}}

% This sets the formatting of the list of figures page.
\renewcommand*{\listoffigures}{%
 % Move to new page.
 \newpage %
 % Add this page to the table of contents.
 \phantomsection\addcontentsline{toc}{chapter}{List of Figures} %
 % Use front page styling.
 \frntpg %
 % Larger upper margin for first page of table (thesis only)
 \if@umich@thesis %
  \begin{minipage}{0.8\textwidth} \vspace{1in} \end{minipage} \\ %
 \fi %
 % Add the title
 \centerline{\large\bf LIST OF FIGURES} %
 % Add some space after the title.
 \vspace{1ex} %
 % Start the automatic table of contents features.
 \begin{singlespace} %
 \leftline{\bf Figure}  %
 \vspace{-0.5ex} %
  \@starttoc{lof}\if@restonecol\twocolumn\fi %
 \end{singlespace} %
}


%% ---- LIST OF TABLES -------------------------------------------------
% This sets the format for the table entries.
\renewcommand*{\l@table}{\@dottedtocline{1}{0em}{2.5em}}

% This sets the formatting of the list of tables page.
\renewcommand*{\listoftables}{%
 % Move to new page.
 \newpage %
 % Add this page to the table of contents.
 \phantomsection\addcontentsline{toc}{chapter}{List of Tables} %
 % Use front page styling.
 \frntpg %
 % Larger upper margin for first page of table (thesis only)
 \if@umich@thesis %
  \begin{minipage}{0.8\textwidth} \vspace{1in} \end{minipage} \\ %
 \fi %
 % Add the title
 \centerline{\large\bf LIST OF TABLES} %
 % Add some space after the title.
 \vspace{1ex} %
 % Start the automatic table of contents features.
 \begin{singlespace} %
 \leftline{\bf Table}  %
 \vspace{-0.5ex} %
  \@starttoc{lot}\if@restonecol\twocolumn\fi %
 \end{singlespace} %
}

%% ---- LINKS ----------------------------------------------------------
% This loads a package that allows extra colors for links.
\RequirePackage[usenames,dvipsnames]{xcolor}
% Custom color for references.
\definecolor{DarkGreen}{rgb}{0,0.6,0}
% This will make labels and references hyperlinks.
\RequirePackage{hyperref}

%% ---- INITIALIZATION -------------------------------------------------
% Commands to be placed after \begin{document}
\AtBeginDocument{ %
 % Insert a title page.
 \titlepage %
 % Page numbers at the bottom
 \pagestyle{plain} %
 % Use lower-case roman numerals.
 \renewcommand{\thepage}{\roman{page}} %
 % Initialize page numbers.
 \setcounter{page}{1} %
 % Insert the table of contents.
 \tableofcontents %
 % Insert the list of figures & tables.
\listoffigures %
 % Insert the list of tables.
\listoftables %
 % Move to next page.
 \newpage %
 % Restart page numbers for the chapters.
 \setcounter{page}{1} %
 % Page numbers at the bottom
 \pagestyle{plain} %
 % Use Arabic numerals.
 \renewcommand{\thepage}{\arabic{page}} %
 % Add the word 'Chapter' to the table of contents.
 \addtocontents{toc}{\vspace{1.3ex}\noindent %
 {\bf Chapter}\vspace{1.3ex}} %
 % Use the correct formatting.
  \onehalfspacing %
}

相关内容