From e6bb4f9ae2d3785b331388703b8793e0409d30af Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Sun, 15 Sep 2019 17:01:48 -0400 Subject: [PATCH] Put \ifx guards on most other package includes, too. We shouldn't be trying to load "amsopn" ten times, for example. But testing whether or not a package is loaded is tricky. First, I tried the \@ifpackageloaded macro: that causes problems with some of my existing documents, and the "spacefactor" error that results is apparently a FAQ. But I don't know what to do about it. The other way to test if a package is loaded is by checking for some (unique?) macro that it defines. That's what I've guessed at here. It works in most cases, like when we want \operatorname from "amsopn." But, some packages also didn't have something obvious to check for, so coverage isn't 100%. --- mjo-algebra.tex | 5 +++-- mjo-algorithm.tex | 1 + mjo-arrow.tex | 6 +++++- mjo-calculus.tex | 3 +++ mjo-common.tex | 10 ++++++---- mjo-cone.tex | 4 +++- mjo-convex.tex | 5 +++-- mjo-font.tex | 5 +++-- mjo-linear_algebra.tex | 16 ++++++++++------ mjo-listing.tex | 9 +++++++-- mjo-misc.tex | 4 +++- mjo-theorem-star.tex | 4 +++- mjo-theorem.tex | 5 +++-- mjo-topology.tex | 5 +++-- 14 files changed, 56 insertions(+), 26 deletions(-) diff --git a/mjo-algebra.tex b/mjo-algebra.tex index 8852345..0b8dc93 100644 --- a/mjo-algebra.tex +++ b/mjo-algebra.tex @@ -5,8 +5,9 @@ \def\havemjoalgebra{1} -% Needed for \operatorname. -\usepackage{amsopn} +\ifx\operatorname\undefined + \usepackage{amsopn} +\fi % The fraction field of its argument, an integral domain. The name % "Frac" was chosen here instead of "Quot" because the latter diff --git a/mjo-algorithm.tex b/mjo-algorithm.tex index cef0e89..55d4831 100644 --- a/mjo-algorithm.tex +++ b/mjo-algorithm.tex @@ -16,6 +16,7 @@ % This just gives us the floating ``algorithm'' environment. \usepackage{algorithm} +% Use "//" for comments instead of the default. \algrenewcommand{\algorithmiccomment}[1]{/\!/ {#1}} diff --git a/mjo-arrow.tex b/mjo-arrow.tex index 4dd5f88..60530cb 100644 --- a/mjo-arrow.tex +++ b/mjo-arrow.tex @@ -5,7 +5,11 @@ \def\havemjoarrow{1} -\input{mjo-common} +\input{mjo-common} % for \of, at least. + +\ifx\operatorname\undefined + \usepackage{amsopn} +\fi % The identity operator/arrow on its argument. \newcommand*{\identity}[1]{ \operatorname{id}_{{#1}} } diff --git a/mjo-calculus.tex b/mjo-calculus.tex index fbc9bfe..6021163 100644 --- a/mjo-calculus.tex +++ b/mjo-calculus.tex @@ -1,3 +1,6 @@ +% +% Standard calculus operations. +% \ifx\havemjocalculus\undefined \def\havemjocalculus{1} diff --git a/mjo-common.tex b/mjo-common.tex index 6aac4ca..aa7427f 100644 --- a/mjo-common.tex +++ b/mjo-common.tex @@ -5,11 +5,13 @@ \def\havemjocommon{1} -% Needed for \mathbb. -\usepackage{amsfonts} +\ifx\mathbb\undefined + \usepackage{amsfonts} +\fi -% Needed for \bigtimes. -\usepackage{mathtools} +\ifx\bigtimes\undefined + \usepackage{mathtools} +\fi % Place the argument in matching left/right parentheses. \newcommand*{\of}[1]{ \left({#1}\right) } diff --git a/mjo-cone.tex b/mjo-cone.tex index 35edc8e..703ecf4 100644 --- a/mjo-cone.tex +++ b/mjo-cone.tex @@ -8,7 +8,9 @@ \def\havemjocone{1} -\usepackage{amssymb} % \succcurlyeq and friends +\ifx\succcurlyeq\undefined + \usepackage{amssymb} % \succcurlyeq, \preccurlyeq +\fi \input{mjo-common} diff --git a/mjo-convex.tex b/mjo-convex.tex index dfc2822..5a930fc 100644 --- a/mjo-convex.tex +++ b/mjo-convex.tex @@ -5,8 +5,9 @@ \def\havemjoconvex{1} -% Needed for \operatorname. -\usepackage{amsopn} +\ifx\operatorname\undefined + \usepackage{amsopn} +\fi \input{mjo-common} diff --git a/mjo-font.tex b/mjo-font.tex index c6675f3..2a00a29 100644 --- a/mjo-font.tex +++ b/mjo-font.tex @@ -13,7 +13,8 @@ \usepackage[utf8]{inputenc} % Grab the AMS fonts, too, for things like \mathbb. -\usepackage{amsfonts} - +\ifx\mathbb\undefined + \usepackage{amsfonts} +\fi \fi diff --git a/mjo-linear_algebra.tex b/mjo-linear_algebra.tex index d423a43..e2ae9fa 100644 --- a/mjo-linear_algebra.tex +++ b/mjo-linear_algebra.tex @@ -5,14 +5,18 @@ \def\havemjolinearalgebra{1} -% Needed for \lvert, \rVert, etc. and \operatorname. -\usepackage{amsmath} +\ifx\lvert\undefined + \usepackage{amsmath} % \lvert, \rVert, etc. and \operatorname. +\fi -% Wasysym contains the \ocircle that we use in \directsumperp. -\usepackage{wasysym} +\ifx\ocircle\undefined + \usepackage{wasysym} +\fi -% Part of the adjustbox package; needed to clip the \perp sign. -\usepackage{trimclip} +\ifx\clipbox\undefined + % Part of the adjustbox package; needed to clip the \perp sign. + \usepackage{trimclip} +\fi \input{mjo-common} diff --git a/mjo-listing.tex b/mjo-listing.tex index f898aba..cf3fc58 100644 --- a/mjo-listing.tex +++ b/mjo-listing.tex @@ -14,8 +14,13 @@ \def\havemjolisting{1} -\usepackage{listings} -\usepackage{tcolorbox} +\ifx\lstset\undefined + \usepackage{listings} +\fi + +\ifx\tcbuselibrary\undefined + \usepackage{tcolorbox} +\fi % Tell tcolorbox to use ``listings'' within the boxes. \tcbuselibrary{listings} diff --git a/mjo-misc.tex b/mjo-misc.tex index f73fe14..2442145 100644 --- a/mjo-misc.tex +++ b/mjo-misc.tex @@ -5,7 +5,9 @@ \def\havemjomisc{1} -\usepackage{amsmath} +\ifx\operatorname\undefined + \usepackage{amsopn} +\fi % The cardinality of a set. The |X| notation conflicts with the % absolute value, and the meaning of card(X) is clear at once, so we diff --git a/mjo-theorem-star.tex b/mjo-theorem-star.tex index 7a3ceba..b8ed63c 100644 --- a/mjo-theorem-star.tex +++ b/mjo-theorem-star.tex @@ -5,7 +5,9 @@ \def\havemjotheoremstar{1} -\usepackage{amsthm} +\ifx\theoremstyle\undefined + \usepackage{amsthm} +\fi \theoremstyle{plain} \newtheorem*{corollary*}{Corollary} diff --git a/mjo-theorem.tex b/mjo-theorem.tex index dc67f45..ea0ca33 100644 --- a/mjo-theorem.tex +++ b/mjo-theorem.tex @@ -5,8 +5,9 @@ \ifx\havemjotheorem\undefined \def\havemjotheorem{1} - -\usepackage{amsthm} +\ifx\theoremstyle\undefined + \usepackage{amsthm} +\fi \theoremstyle{plain} \newtheorem{corollary}{Corollary} diff --git a/mjo-topology.tex b/mjo-topology.tex index c7f5037..760d44d 100644 --- a/mjo-topology.tex +++ b/mjo-topology.tex @@ -5,8 +5,9 @@ \def\havemjotopology{1} -% Needed for \operatorname. -\usepackage{amsopn} +\ifx\operatorname\undefined + \usepackage{amsopn} +\fi \input{mjo-common} -- 2.44.2