如何定义全局变量并在任何地方使用它的值?

如何定义全局变量并在任何地方使用它的值?

这是构建自定义样式包的可行/合适的方法吗?目标是可以有一段易于理解的样板代码,用于构建新文档。

迄今为止的样板代码:

\RequirePackage[l2tabu,orthodox]{nag} % Complains about deprecated packages
\documentclass[12pt,numbers=noenddot]{scrartcl} % Appropriate KOMAScript class

% Required preamble part for any document using the `oilnet' style
\makeatletter
  \include{oilworks/packages} % Defines OWdefaultlanguage
  \OWdefaultlanguage{german}
  \include{oilworks/oilworks}
  \include{oilworks/variables}
  \include{oilworks/titlepage}
  \OWuniversity{Universität Leipzig}
  \OWfaculty{Fakultät für Geschichte, Kunst- und Orientwissenschaften}
  \OWinstitute{Orientalisches Institut}
  \OWtypeofwork{Irgendwasarbeit}
  \title{Blah Blah \dmg{ʾImrūʾu l-Qays b. Ḥuǧr al-Kindī} Wein-, Weib- und Gesangsdichtung Blah Blah}
  \OWassessor{Dr. Montag Dienstag Freitag}
  \author{Peter Student}
  \OWmatriculationnumber{1234567}
  \OWemailaddress{[email protected]}
  \OWstreetandhousenumber{Sonnenstraße 123}
  \OWpostcodeandcity{12345 Wintergarten}
\makeatother

\begin{document}  
  \OWmaketitle
  \blinddocument
\end{document}

packages.tex

% Needs to be set *here* for dependency reasons
\def\OWdefaultlanguage#1{\def\@OWdefaultlanguage{#1}}

% Universal Fixes
\usepackage{fixltx2e} % Corrects LaTeX2e bugs and quirks
\usepackage{ifxetex} % Checks if XeTeX/XeLaTeX is the compiler-of-choice
% Unicode, i18n, etc.
\usepackage{polyglossia}
% Layout and Format
% \usepackage{csquotes} % Fixes inline and display quotations - doesn't work atm, reason unknown
\usepackage[absolute]{textpos} % For "\textblock"s, which can be freely  positioned on the page
% Math
\usepackage{amsmath} % Swiss-knife math package
% Graphics
\usepackage{graphicx} % Allows inserting of graphics and images
% Tables and Figures
\usepackage{booktabs} % For drawing nice tables with proper line weights
\usepackage{flafter} % To ensure that figures float only after they are defined/referenced
\usepackage{tabu} % Provides better control for tables and column widths
\usepackage{longtable} % Allows tables to span across pages - integrates with tabu
\usepackage{multicol} % Allows spanning columns in tables
% Referencing
\usepackage[longnamesfirst]{natbib} % Reimplements \cite to work with author-year and numerical citations
% Fonts and Typography
\usepackage{ellipsis} % Fixes space uneveness around ellipses
\usepackage{url} % Allows encapsulated URLs to break across lines
\usepackage[colorlinks,hypertexnames=false,plainpages=false]{hyperref} % Converts \url references to valid hyperlinks in PDF documents
\usepackage{fontspec} % Allows usage of system opentype/truetype fonts
% Things to use during development
\usepackage{blindtext}

oilworks.tex

\setdefaultlanguage{\@OWdefaultlanguage}

\newcommand{\latin}[1]{{\emph{#1}}} % For easier handling of how latin phrases are formatted
\newcommand{\dmg}[1]{{\emph{#1}}} % The same for DMG transliteration

variables.tex

\def\OWuniversity#1{\def\@OWuniversity{#1}}
\def\OWfaculty#1{\def\@OWfaculty{#1}}
\def\OWinstitute#1{\def\@OWinstitute{#1}}
% (etc...)

titlepage.tex

\newcommand*{\OWmaketitle}{
  \begin{titlepage}
    \begin{center}
      \pagestyle{empty}
      \selectlanguage{german} % Must be German according to UL style guide.
      \begingroup
        {\LARGE \@OWuniversity} \\
        {\normalsize \@OWfaculty} \\
        {\Large \@OWinstitute} \\
      \endgroup
      \vspace*{0.5cm}
      \includegraphics[height=150pt,width=150pt]{oilworks/uofl_official_seal}\\
      \vspace*{0.35cm}
      \begingroup
        {\LARGE \@OWtypeofwork} \\
      \endgroup
      \vspace*{1.25cm}
      \begingroup
        \if\relax\detokenize{\@subtitle}\relax
          {\LARGE \@title} \\
          \vspace{0.2cm}
          {\normalsize \textit{\@subtitle}} \\
        \else
          {\normalsize {\@title}} \\
        \fi
      \endgroup
      % (etc...)
      \selectlanguage{\@OWdefaultlanguage} % Back to whatever the document is written in.
    \end{center}
  \end{titlepage}
  \clearpage
}

相关内容