Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am trying to create a file which includes common packages and macros I use. It is something like this.

commonDefinitions.tex

 \interdisplaylinepenalty=2500
 \usepackage{algorithmic}

 \usepackage{cite} 
 \usepackage{appendix}
 ... other packages and macros

But some packages clash with each other in combinations. For example when I try to use

 \documentclass[journal]{IEEEtran}
 \usepackage{appendix}

It gives error since IEEEtran already created command appendix.

I would like to get some solution to this problem something like below.

if document class is not IEEEtran 
   \usepackage{appendix}
end if
share|improve this question

2 Answers 2

up vote 6 down vote accepted

A way is

\makeatletter
\@ifclassloaded{IEEEtran}{}{\usepackage{appendix}}
\makeatother

But I believe that documents written for submission should not have any reference to conflicting packages (and so tricks like this one). How would you use the commands provided by appendix if the document class is IEEEtran?

share|improve this answer
    
I do not plan to use appendix commands in this conference submission , but I use that commands in my thesis. –  Atilla Ozgur Feb 29 '12 at 10:51

I was advised once to test on functionality rather than on class name. The problem is that both appendix.sty and IEEEtran.cls defines \appendices. So only load the appendix package if there isn't already a command \appendices defined. Here is a working example:

\documentclass{IEEEtran}
\title{Test of conditional use of the appendix package}
\usepackage{lipsum} % just for dummy text
\ifcsname appendices\endcsname
  % do nothing
\else
  \usepackage{appendix}
\fi

\begin{document}
\maketitle

\section{Foo}

\lipsum

\section{Bar}

\lipsum

\appendix

\section{Appendix}

\lipsum

\end{document}

\ifcsame is available on all e-TeX builds and is documented (along with other ways to check if a command is defined) here.

share|improve this answer
    
This will do nothing for all classes that define \appendix, including article, report, book, memoir. –  egreg Feb 29 '12 at 22:23
    
@Matthew: Please something is wrong with your use of \ifcsname! –  Ahmed Musa Mar 1 '12 at 2:22
    
@egreg: I thought that's what the OP wanted. He said the problem was the existence of the command \appendix. After creating a MWE I see that's not the problem: it's the existence of the command \appendices. I've updated my answer so that appendix.sty is loaded in article.cls, etc. –  Matthew Leingang Mar 10 '12 at 12:32
    
@AhmedMusa: Yes, I was missing \endcsname. Thanks for noticing. –  Matthew Leingang Mar 10 '12 at 12:32

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.